feat: polish pinned conversations and context ring
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -80,15 +82,49 @@ public class BossUiConversationRowTest {
|
||||
"M",
|
||||
"W",
|
||||
new WechatSurfaceMapper.GroupAvatarMember[0],
|
||||
false,
|
||||
"上下文紧张 34%",
|
||||
"urgent"
|
||||
"urgent",
|
||||
66,
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
LinearLayout rowView = BossUi.buildConversationRow(context, row, null);
|
||||
LinearLayout trailingColumn = (LinearLayout) rowView.getChildAt(2);
|
||||
|
||||
assertTrue(viewTreeContainsText(trailingColumn, "上下文紧张 34%"));
|
||||
assertEquals("空闲会话不应再渲染活动点", 2, trailingColumn.getChildCount());
|
||||
assertFalse("右下角应改成环形上下文状态,而不是文字", viewTreeContainsText(trailingColumn, "上下文紧张 34%"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildConversationRow_usesSubtlePinnedBackgroundWithoutPinnedBadge() {
|
||||
Context context = RuntimeEnvironment.getApplication();
|
||||
WechatSurfaceMapper.ConversationRow row = new WechatSurfaceMapper.ConversationRow(
|
||||
"主 Agent",
|
||||
"主控线程",
|
||||
"正在观察多个任务",
|
||||
"09:26",
|
||||
0,
|
||||
"置顶",
|
||||
0,
|
||||
false,
|
||||
"M",
|
||||
"A",
|
||||
new WechatSurfaceMapper.GroupAvatarMember[0],
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
-1,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
LinearLayout rowView = BossUi.buildConversationRow(context, row, null);
|
||||
|
||||
assertTrue("置顶会话背景应略深于普通白底", rowView.getBackground() instanceof ColorDrawable);
|
||||
assertEquals(0xFFF7F7F7, ((ColorDrawable) rowView.getBackground()).getColor());
|
||||
assertFalse("置顶会话不应再显示右侧“置顶”文字", viewTreeContainsText(rowView, "置顶"));
|
||||
}
|
||||
|
||||
private static boolean viewTreeContainsText(View root, String expectedText) {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(sdk = 34)
|
||||
public class MainActivityPinnedConversationsTest {
|
||||
@Test
|
||||
public void renderConversationsRoot_groupsPinnedConversationsAndTogglesCollapse() throws Exception {
|
||||
MainActivity activity = Robolectric.buildActivity(MainActivity.class).setup().get();
|
||||
ReflectionHelpers.setField(activity, "conversationsData", new JSONArray()
|
||||
.put(new JSONObject()
|
||||
.put("projectId", "p1")
|
||||
.put("projectTitle", "主 Agent")
|
||||
.put("threadTitle", "主 Agent")
|
||||
.put("folderLabel", "主控线程")
|
||||
.put("topPinnedLabel", "置顶")
|
||||
.put("lastMessagePreview", "正在观察")
|
||||
.put("latestReplyLabel", "09:40"))
|
||||
.put(new JSONObject()
|
||||
.put("projectId", "p2")
|
||||
.put("projectTitle", "Boss 移动控制台")
|
||||
.put("threadTitle", "Boss 移动控制台")
|
||||
.put("folderLabel", "归档确认")
|
||||
.put("lastMessagePreview", "线程链路正常")
|
||||
.put("latestReplyLabel", "09:41")));
|
||||
|
||||
ReflectionHelpers.callInstanceMethod(activity, "showContent");
|
||||
ReflectionHelpers.callInstanceMethod(activity, "renderConversationsRoot");
|
||||
|
||||
LinearLayout content = activity.findViewById(R.id.screen_content);
|
||||
assertTrue(viewTreeContainsText(content, "置顶会话"));
|
||||
assertTrue(viewTreeContainsText(content, "收起"));
|
||||
assertTrue(viewTreeContainsText(content, "主 Agent"));
|
||||
assertTrue(viewTreeContainsText(content, "Boss 移动控制台"));
|
||||
|
||||
View pinnedHeader = content.getChildAt(1);
|
||||
pinnedHeader.performClick();
|
||||
|
||||
assertEquals(true, ReflectionHelpers.getField(activity, "pinnedConversationsCollapsed"));
|
||||
assertTrue(viewTreeContainsText(content, "展开"));
|
||||
assertTrue("收起后普通会话仍应保留", viewTreeContainsText(content, "Boss 移动控制台"));
|
||||
}
|
||||
|
||||
private static boolean viewTreeContainsText(View root, String expectedText) {
|
||||
if (root instanceof TextView) {
|
||||
CharSequence text = ((TextView) root).getText();
|
||||
if (expectedText.contentEquals(text)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!(root instanceof LinearLayout)) {
|
||||
return false;
|
||||
}
|
||||
LinearLayout group = (LinearLayout) root;
|
||||
for (int index = 0; index < group.getChildCount(); index += 1) {
|
||||
if (viewTreeContainsText(group.getChildAt(index), expectedText)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ public class WechatSurfaceMapperConversationStatusTest {
|
||||
assertEquals(0, row.activityIconCount);
|
||||
assertEquals("上下文紧张 34%", row.contextStatusLabel);
|
||||
assertEquals("urgent", row.contextStatusLevel);
|
||||
assertEquals(66, row.contextUsagePercent);
|
||||
assertEquals(true, row.contextIndicatorVisible);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,6 +46,8 @@ public class WechatSurfaceMapperConversationStatusTest {
|
||||
|
||||
assertEquals("必须收尾", row.contextStatusLabel);
|
||||
assertEquals("critical", row.contextStatusLevel);
|
||||
assertEquals(100, row.contextUsagePercent);
|
||||
assertEquals(true, row.contextMustFinish);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,6 +64,7 @@ public class WechatSurfaceMapperConversationStatusTest {
|
||||
|
||||
assertNull(row.contextStatusLabel);
|
||||
assertNull(row.contextStatusLevel);
|
||||
assertEquals(-1, row.contextUsagePercent);
|
||||
}
|
||||
|
||||
private static final class StubJSONObject extends JSONObject {
|
||||
|
||||
Reference in New Issue
Block a user