fix: restore safe top actions and home group chat entry
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(sdk = 34)
|
||||
public class BossWindowInsetsTest {
|
||||
@Test
|
||||
public void applyStatusBarInset_addsInsetOnTopOfInitialPadding() {
|
||||
View view = new View(RuntimeEnvironment.getApplication());
|
||||
view.setPadding(12, 16, 18, 20);
|
||||
|
||||
BossWindowInsets.applyStatusBarInset(view);
|
||||
|
||||
WindowInsetsCompat insets = new WindowInsetsCompat.Builder()
|
||||
.setInsets(WindowInsetsCompat.Type.statusBars(), Insets.of(0, 30, 0, 0))
|
||||
.build();
|
||||
|
||||
WindowInsetsCompat applied = androidx.core.view.ViewCompat.dispatchApplyWindowInsets(view, insets);
|
||||
|
||||
assertEquals(12, view.getPaddingLeft());
|
||||
assertEquals(46, view.getPaddingTop());
|
||||
assertEquals(18, view.getPaddingRight());
|
||||
assertEquals(20, view.getPaddingBottom());
|
||||
assertEquals(insets, applied);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,30 @@ public class GroupCreateActivityTest {
|
||||
assertEquals("thread-1", filtered.get(0).optString("projectId", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectSelectableConversationItems_keepsAllThreadsWhenSourceConversationIsMissing() {
|
||||
JSONObject threadConversation = new StubJSONObject()
|
||||
.withString("projectId", "thread-1")
|
||||
.withString("projectTitle", "线程一")
|
||||
.withBoolean("isGroup", false);
|
||||
JSONObject secondThreadConversation = new StubJSONObject()
|
||||
.withString("projectId", "thread-2")
|
||||
.withString("projectTitle", "线程二")
|
||||
.withBoolean("isGroup", false);
|
||||
JSONObject groupConversation = new StubJSONObject()
|
||||
.withString("projectId", "group-1")
|
||||
.withString("projectTitle", "已有群聊")
|
||||
.withBoolean("isGroup", true);
|
||||
JSONObject conversationsPayload = new StubJSONObject()
|
||||
.withObjectArray("conversations", threadConversation, secondThreadConversation, groupConversation);
|
||||
|
||||
java.util.List<JSONObject> filtered = GroupCreateActivity.collectSelectableConversationItems(conversationsPayload, null);
|
||||
|
||||
assertEquals(2, filtered.size());
|
||||
assertEquals("thread-1", filtered.get(0).optString("projectId", ""));
|
||||
assertEquals("thread-2", filtered.get(1).optString("projectId", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reconcileSelectedProjectIds_keepsManualDeselectionWhenCandidatesStayTheSame() {
|
||||
Set<String> previousCandidateIds = linkedSet("thread-1", "thread-2", "thread-3");
|
||||
@@ -57,10 +81,16 @@ public class GroupCreateActivityTest {
|
||||
public void canCreateGroupChat_blocksWhileRefreshingOrCreating() {
|
||||
Set<String> selectedProjectIds = linkedSet("thread-1");
|
||||
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(true, false, selectedProjectIds));
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(false, true, selectedProjectIds));
|
||||
assertTrue(GroupCreateActivity.canCreateGroupChat(false, false, selectedProjectIds));
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(false, false, linkedSet()));
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(true, false, selectedProjectIds, true));
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(false, true, selectedProjectIds, true));
|
||||
assertTrue(GroupCreateActivity.canCreateGroupChat(false, false, selectedProjectIds, true));
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(false, false, linkedSet(), true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canCreateGroupChat_requiresTwoSelectionsWhenCreatedFromConversationList() {
|
||||
assertFalse(GroupCreateActivity.canCreateGroupChat(false, false, linkedSet("thread-1"), false));
|
||||
assertTrue(GroupCreateActivity.canCreateGroupChat(false, false, linkedSet("thread-1", "thread-2"), false));
|
||||
}
|
||||
|
||||
private static Set<String> linkedSet(String... values) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class WechatSurfaceMapperTopActionTest {
|
||||
@Test
|
||||
public void rootTopAction_usesPlusForConversations() {
|
||||
WechatSurfaceMapper.RootTopAction action = WechatSurfaceMapper.rootTopAction("conversations", false);
|
||||
|
||||
assertEquals("+", action.label);
|
||||
assertTrue(action.primaryStyle);
|
||||
assertEquals("create_group_chat", action.actionKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootTopAction_keepsAddDeviceOnDevicesTab() {
|
||||
WechatSurfaceMapper.RootTopAction action = WechatSurfaceMapper.rootTopAction("devices", false);
|
||||
|
||||
assertEquals("+添加", action.label);
|
||||
assertTrue(action.primaryStyle);
|
||||
assertEquals("add_device", action.actionKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootTopAction_keepsRefreshOnMeTab() {
|
||||
WechatSurfaceMapper.RootTopAction action = WechatSurfaceMapper.rootTopAction("me", true);
|
||||
|
||||
assertEquals("同步中", action.label);
|
||||
assertFalse(action.primaryStyle);
|
||||
assertEquals("refresh", action.actionKey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user