v13-f1 Task 1.2: junit-jupiter 5.12.2 依赖 + InputFieldBuilderTest (4/4 PASS)
This commit is contained in:
1 parent
09efa5f7f8
commit
aae916a033
2 files changed
+111
No files matched your search
@@ -75,6 +75,13 @@
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.4.0</version>
|
||||
</dependency>
|
||||
<!-- JUnit 5: v13 form builder 单元测试 (Task 1.2) -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.12.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package ssw.dacli.form.builder.field;
|
||||
|
||||
import ssw.dacli.form.builder.FieldBuildContext;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.nio.file.*;
|
||||
|
||||
/**
|
||||
* v13 Task 1.2 + 1.3 — InputFieldBuilder 单元测试 (4 用例).
|
||||
*
|
||||
* <p>校验关键结构 (jnpfKey/tag/label/field/__config__/__vModel__) 与 baseline 真实 formData 对齐.
|
||||
* 0 误差打磨细节: dumpToFile 把生成结果写到 scripts/InputFieldBuilder-output.json, 用 diff-input.py 对比 baseline.
|
||||
*/
|
||||
public class InputFieldBuilderTest {
|
||||
|
||||
private static final ObjectMapper M = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void testInputField_basic() throws Exception {
|
||||
FieldBuildContext ctx = new FieldBuildContext();
|
||||
ctx.field = "f_name";
|
||||
ctx.label = "姓名";
|
||||
ctx.required = false;
|
||||
|
||||
String json = new InputFieldBuilder().buildFormField(ctx);
|
||||
var parsed = M.readTree(json);
|
||||
|
||||
// 顶层关键键
|
||||
assertNotNull(parsed.get("__config__"));
|
||||
assertNotNull(parsed.get("__vModel__"));
|
||||
assertEquals("f_name", parsed.get("__vModel__").asText());
|
||||
|
||||
// __config__ 关键键
|
||||
var cfg = parsed.get("__config__");
|
||||
assertEquals("input", cfg.get("jnpfKey").asText());
|
||||
assertEquals("JnpfInput", cfg.get("tag").asText());
|
||||
assertEquals("姓名", cfg.get("label").asText());
|
||||
assertEquals("colFormItem", cfg.get("layout").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputField_required() throws Exception {
|
||||
FieldBuildContext ctx = new FieldBuildContext();
|
||||
ctx.field = "f_phone";
|
||||
ctx.label = "电话";
|
||||
ctx.required = true;
|
||||
|
||||
String json = new InputFieldBuilder().buildFormField(ctx);
|
||||
var parsed = M.readTree(json);
|
||||
assertTrue(parsed.get("__config__").get("required").asBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputField_baselineKeyStructure() throws Exception {
|
||||
// 跟 baseline input 控件 formData 关键结构对齐检查
|
||||
// (不要求 100% 0 误差 - 留给 Task 1.3, 这里验证骨架)
|
||||
FieldBuildContext ctx = new FieldBuildContext();
|
||||
ctx.field = "f_name";
|
||||
ctx.label = "姓名";
|
||||
|
||||
String json = new InputFieldBuilder().buildFormField(ctx);
|
||||
var parsed = M.readTree(json);
|
||||
var cfg = parsed.get("__config__");
|
||||
|
||||
// baseline 必有结构
|
||||
assertNotNull(cfg.get("visibility"));
|
||||
assertNotNull(cfg.get("formId"));
|
||||
assertNotNull(cfg.get("jnpfKey"));
|
||||
assertNotNull(cfg.get("noShow"));
|
||||
assertNotNull(cfg.get("required"));
|
||||
assertNotNull(cfg.get("span"));
|
||||
assertNotNull(cfg.get("tag"));
|
||||
assertNotNull(cfg.get("layout"));
|
||||
assertNotNull(cfg.get("regList"));
|
||||
|
||||
// 顶层 baseline 必有
|
||||
assertNotNull(parsed.get("clearable"));
|
||||
assertNotNull(parsed.get("readonly"));
|
||||
assertNotNull(parsed.get("disabled"));
|
||||
assertNotNull(parsed.get("placeholder"));
|
||||
assertNotNull(parsed.get("prefixIcon"));
|
||||
assertNotNull(parsed.get("suffixIcon"));
|
||||
assertNotNull(parsed.get("addonBefore"));
|
||||
assertNotNull(parsed.get("addonAfter"));
|
||||
assertNotNull(parsed.get("showPassword"));
|
||||
assertNotNull(parsed.get("style"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputField_dumpToFile() throws Exception {
|
||||
// 工具方法: 把生成结果写到 scripts/InputFieldBuilder-output.json 用于 diff 对比
|
||||
FieldBuildContext ctx = new FieldBuildContext();
|
||||
ctx.field = "f_name";
|
||||
ctx.label = "姓名";
|
||||
ctx.required = true;
|
||||
String json = new InputFieldBuilder().buildFormField(ctx);
|
||||
Path out = Paths.get("../scripts/InputFieldBuilder-output.json");
|
||||
Files.createDirectories(out.getParent());
|
||||
Files.writeString(out, json);
|
||||
assertTrue(Files.exists(out));
|
||||
assertTrue(Files.size(out) > 100);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user