|
|
@@ -0,0 +1,47 @@
|
|
|
+package com.etotem.cfc.unit;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.*;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * TDD 契约:后台用户管理支持按真实姓名(realName)模糊查询。
|
|
|
+ *
|
|
|
+ * <p>AdminController./api/admin/users 现有 nickname/phone 模糊查询,缺 realName;
|
|
|
+ * 本测试守护后端追加 realName like 条件 + 前端搜索表单追加 realName 字段。</p>
|
|
|
+ */
|
|
|
+class AdminUserRealNameSearchTest {
|
|
|
+
|
|
|
+ private String read(String rel) throws Exception {
|
|
|
+ Path p = Paths.get(rel);
|
|
|
+ if (!Files.exists(p)) p = Paths.get("../cfc-backend/" + rel);
|
|
|
+ return new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void backend_users_list_supports_real_name_like() throws Exception {
|
|
|
+ String src = read("src/main/java/com/etotem/cfc/controller/admin/AdminController.java");
|
|
|
+ // getUsers 方法段:应有 realName like 条件
|
|
|
+ int idx = src.indexOf("public Result<Page<User>> getUsers(");
|
|
|
+ assertTrue(idx >= 0, "getUsers 方法应存在");
|
|
|
+ String body = src.substring(idx, Math.min(src.length(), idx + 2500));
|
|
|
+ assertTrue(body.contains("getRealName") && body.contains("like"),
|
|
|
+ "getUsers 应含 User::getRealName 的 like 模糊查询条件");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void frontend_search_form_has_real_name_field() throws Exception {
|
|
|
+ // 前端源码路径相对 cfc-backend 模块测试运行目录,需回退到仓库根
|
|
|
+ Path p = Paths.get("../cfc-web/src/views/Users.vue");
|
|
|
+ if (!Files.exists(p)) p = Paths.get("../../cfc-web/src/views/Users.vue");
|
|
|
+ String vue = new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
|
|
|
+ assertTrue(vue.contains("searchForm.realName"), "搜索表单应含 realName 字段绑定");
|
|
|
+ assertTrue(vue.contains("真实姓名"), "搜索表单应有「真实姓名」标签");
|
|
|
+ assertTrue(vue.contains("请输入真实姓名"), "搜索输入框 placeholder 应为「请输入真实姓名」");
|
|
|
+ // 不能误用展示用 editForm.realName
|
|
|
+ assertTrue(vue.indexOf("searchForm.realName") < vue.indexOf("editForm.realName")
|
|
|
+ || vue.contains("v-model=\"searchForm.realName\""),
|
|
|
+ "搜索区应绑定 searchForm.realName(而非仅编辑弹窗的 editForm.realName)");
|
|
|
+ }
|
|
|
+}
|