android: preserve device detail summary context
This commit is contained in:
@@ -53,6 +53,23 @@ public class WechatSurfaceMapperTest {
|
||||
assertEquals("异常 · 17600003315", row.subtitle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deviceDetailSummary_keepsEssentialContextAlongsideNoteEndpointAndProjects() throws Exception {
|
||||
JSONObject item = new StubJSONObject()
|
||||
.withString("name", "Mac Studio")
|
||||
.withString("status", "online")
|
||||
.withString("account", "17600003315")
|
||||
.withString("note", "书房主机")
|
||||
.withString("endpoint", "https://boss.hyzq.net/device/mac-studio")
|
||||
.withArray("projects", "master-agent", "android-app");
|
||||
|
||||
WechatSurfaceMapper.DeviceDetailSummary summary = WechatSurfaceMapper.toDeviceDetailSummary(item);
|
||||
|
||||
assertEquals("Mac Studio", summary.title);
|
||||
assertEquals("在线 · 17600003315", summary.subtitle);
|
||||
assertEquals("书房主机 · https://boss.hyzq.net/device/mac-studio · 项目 master-agent, android-app", summary.meta);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootMeMenuTitles_matchApprovedSimpleMenu() throws Exception {
|
||||
assertArrayEquals(
|
||||
@@ -116,6 +133,11 @@ public class WechatSurfaceMapperTest {
|
||||
return this;
|
||||
}
|
||||
|
||||
StubJSONObject withArray(String key, String... entries) {
|
||||
values.put(key, new StubJSONArray(entries));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String optString(String key, String defaultValue) {
|
||||
Object value = values.get(key);
|
||||
@@ -133,5 +155,33 @@ public class WechatSurfaceMapperTest {
|
||||
Object value = values.get(key);
|
||||
return value instanceof Boolean ? (Boolean) value : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.json.JSONArray optJSONArray(String key) {
|
||||
Object value = values.get(key);
|
||||
return value instanceof org.json.JSONArray ? (org.json.JSONArray) value : null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class StubJSONArray extends org.json.JSONArray {
|
||||
private final String[] entries;
|
||||
|
||||
StubJSONArray(String... entries) {
|
||||
this.entries = entries == null ? new String[0] : entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return entries.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String optString(int index) {
|
||||
if (index < 0 || index >= entries.length) {
|
||||
return "";
|
||||
}
|
||||
String value = entries[index];
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user