120 lines
5.0 KiB
Java
120 lines
5.0 KiB
Java
package com.hyzq.boss;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import android.content.Intent;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
|
|
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 ProjectVersionsActivityUiTest {
|
|
@Test
|
|
public void renderVersionsUsesReadonlyWechatStyleCards() throws Exception {
|
|
TestProjectVersionsActivity activity = Robolectric
|
|
.buildActivity(TestProjectVersionsActivity.class, new Intent()
|
|
.putExtra(ProjectVersionsActivity.EXTRA_PROJECT_ID, "project-1")
|
|
.putExtra(ProjectVersionsActivity.EXTRA_PROJECT_NAME, "北区试产线回归需要只展示一行避免堆叠"))
|
|
.setup()
|
|
.get();
|
|
|
|
ReflectionHelpers.callInstanceMethod(
|
|
activity,
|
|
"renderVersions",
|
|
ReflectionHelpers.ClassParameter.from(JSONObject.class, buildProject())
|
|
);
|
|
|
|
activity.configureScreen("版本记录", "北区试产线回归需要只展示一行避免堆叠");
|
|
LinearLayout content = activity.findViewById(R.id.screen_content);
|
|
TextView title = activity.findViewById(R.id.screen_title);
|
|
TextView subtitle = activity.findViewById(R.id.screen_subtitle);
|
|
assertEquals("版本记录", String.valueOf(title.getText()));
|
|
assertTrue(viewTreeContainsText(content, "仅主 Agent 可发布迭代记录"));
|
|
assertTrue(viewTreeContainsText(content, "v1.2.8 已发布"));
|
|
assertTrue(viewTreeContainsSubstring(content, "• 优化 OTA 实时提示"));
|
|
assertTrue(viewTreeContainsText(content, "主 Agent 复核记录"));
|
|
assertTrue(hasHorizontalContentPadding(content, BossUi.dp(activity, 12)));
|
|
assertTrue(subtitle.getMaxLines() <= 1);
|
|
assertTrue(String.valueOf(subtitle.getEllipsize()).contains("END"));
|
|
assertFalse(viewTreeContainsText(content, "版本记录只读"));
|
|
assertFalse(((SwipeRefreshLayout) activity.findViewById(R.id.screen_refresh_layout)).isRefreshing());
|
|
}
|
|
|
|
private static JSONObject buildProject() throws Exception {
|
|
JSONArray versions = new JSONArray()
|
|
.put(new JSONObject()
|
|
.put("version", "v1.2.8 已发布")
|
|
.put("summary", "• 优化 OTA 实时提示\n• 修复主 Agent 版本汇总延迟\n• 补齐北区试产线回归记录")
|
|
.put("createdAt", "09:40"))
|
|
.put(new JSONObject()
|
|
.put("version", "v1.2.7 已归档")
|
|
.put("summary", "• 接入设备页状态色\n• 新增账号二维码入口\n• 优化会话页排序")
|
|
.put("createdAt", "昨日"));
|
|
return new JSONObject().put("versions", versions);
|
|
}
|
|
|
|
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 ViewGroup)) {
|
|
return false;
|
|
}
|
|
ViewGroup group = (ViewGroup) root;
|
|
for (int index = 0; index < group.getChildCount(); index += 1) {
|
|
if (viewTreeContainsText(group.getChildAt(index), expectedText)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean viewTreeContainsSubstring(View root, String expectedText) {
|
|
if (root instanceof TextView) {
|
|
CharSequence text = ((TextView) root).getText();
|
|
if (text != null && text.toString().contains(expectedText)) {
|
|
return true;
|
|
}
|
|
}
|
|
if (!(root instanceof ViewGroup)) {
|
|
return false;
|
|
}
|
|
ViewGroup group = (ViewGroup) root;
|
|
for (int index = 0; index < group.getChildCount(); index += 1) {
|
|
if (viewTreeContainsSubstring(group.getChildAt(index), expectedText)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean hasHorizontalContentPadding(LinearLayout content, int minPaddingPx) {
|
|
return content.getPaddingLeft() >= minPaddingPx && content.getPaddingRight() >= minPaddingPx;
|
|
}
|
|
|
|
public static class TestProjectVersionsActivity extends ProjectVersionsActivity {
|
|
@Override
|
|
protected void reload() {
|
|
// Tests drive renderVersions manually.
|
|
}
|
|
}
|
|
}
|