fix: show conversation context status
This commit is contained in:
@@ -64,4 +64,49 @@ public class BossUiConversationRowTest {
|
||||
assertTrue("预览需要保留可见宽度: " + metrics, previewView.getMeasuredWidth() > 0);
|
||||
assertTrue("右侧信息列不应吞掉中间内容: " + metrics, trailingColumn.getMeasuredWidth() < rowView.getMeasuredWidth() / 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildConversationRow_showsContextStatusWithoutIdleActivityDots() {
|
||||
Context context = RuntimeEnvironment.getApplication();
|
||||
WechatSurfaceMapper.ConversationRow row = new WechatSurfaceMapper.ConversationRow(
|
||||
"北区试产线回归",
|
||||
"归档确认",
|
||||
"线程链路已稳定",
|
||||
"09:26",
|
||||
0,
|
||||
"",
|
||||
0,
|
||||
false,
|
||||
"M",
|
||||
"W",
|
||||
new WechatSurfaceMapper.GroupAvatarMember[0],
|
||||
"上下文紧张 34%",
|
||||
"urgent"
|
||||
);
|
||||
|
||||
LinearLayout rowView = BossUi.buildConversationRow(context, row, null);
|
||||
LinearLayout trailingColumn = (LinearLayout) rowView.getChildAt(2);
|
||||
|
||||
assertTrue(viewTreeContainsText(trailingColumn, "上下文紧张 34%"));
|
||||
assertEquals("空闲会话不应再渲染活动点", 2, trailingColumn.getChildCount());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WechatSurfaceMapperConversationStatusTest {
|
||||
@Test
|
||||
public void toConversationRow_mapsContextStatusAndIdleActivity() {
|
||||
JSONObject item = new StubJSONObject()
|
||||
.withString("threadTitle", "北区试产线回归")
|
||||
.withString("folderLabel", "归档确认")
|
||||
.withString("lastMessagePreview", "线程链路已稳定")
|
||||
.withString("latestReplyLabel", "09:26")
|
||||
.withInt("activityIconCount", 0)
|
||||
.withBoolean("mustFinishBeforeCompaction", false)
|
||||
.withObject("contextBudgetIndicator", new StubJSONObject()
|
||||
.withBoolean("visible", true)
|
||||
.withInt("percent", 34)
|
||||
.withString("level", "urgent"));
|
||||
|
||||
WechatSurfaceMapper.ConversationRow row = WechatSurfaceMapper.toConversationRow(item);
|
||||
|
||||
assertEquals(0, row.activityIconCount);
|
||||
assertEquals("上下文紧张 34%", row.contextStatusLabel);
|
||||
assertEquals("urgent", row.contextStatusLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toConversationRow_prefersMustFinishContextStatus() {
|
||||
JSONObject item = new StubJSONObject()
|
||||
.withString("threadTitle", "北区试产线回归")
|
||||
.withInt("activityIconCount", 0)
|
||||
.withBoolean("mustFinishBeforeCompaction", true)
|
||||
.withObject("contextBudgetIndicator", new StubJSONObject()
|
||||
.withBoolean("visible", true)
|
||||
.withInt("percent", 18)
|
||||
.withString("level", "critical"));
|
||||
|
||||
WechatSurfaceMapper.ConversationRow row = WechatSurfaceMapper.toConversationRow(item);
|
||||
|
||||
assertEquals("必须收尾", row.contextStatusLabel);
|
||||
assertEquals("critical", row.contextStatusLevel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toConversationRow_hidesContextStatusWhenNotVisible() {
|
||||
JSONObject item = new StubJSONObject()
|
||||
.withString("threadTitle", "北区试产线回归")
|
||||
.withInt("activityIconCount", 0)
|
||||
.withObject("contextBudgetIndicator", new StubJSONObject()
|
||||
.withBoolean("visible", false)
|
||||
.withInt("percent", 71)
|
||||
.withString("level", "safe"));
|
||||
|
||||
WechatSurfaceMapper.ConversationRow row = WechatSurfaceMapper.toConversationRow(item);
|
||||
|
||||
assertNull(row.contextStatusLabel);
|
||||
assertNull(row.contextStatusLevel);
|
||||
}
|
||||
|
||||
private static final class StubJSONObject extends JSONObject {
|
||||
private final java.util.Map<String, Object> values = new java.util.HashMap<>();
|
||||
|
||||
StubJSONObject withString(String key, String value) {
|
||||
values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
StubJSONObject withInt(String key, int value) {
|
||||
values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
StubJSONObject withBoolean(String key, boolean value) {
|
||||
values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
StubJSONObject withObject(String key, JSONObject value) {
|
||||
values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String optString(String key, String defaultValue) {
|
||||
Object value = values.get(key);
|
||||
return value instanceof String ? (String) value : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int optInt(String key, int defaultValue) {
|
||||
Object value = values.get(key);
|
||||
return value instanceof Integer ? (Integer) value : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean optBoolean(String key, boolean defaultValue) {
|
||||
Object value = values.get(key);
|
||||
return value instanceof Boolean ? (Boolean) value : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject optJSONObject(String key) {
|
||||
Object value = values.get(key);
|
||||
return value instanceof JSONObject ? (JSONObject) value : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray optJSONArray(String key) {
|
||||
Object value = values.get(key);
|
||||
return value instanceof JSONArray ? (JSONArray) value : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user