diff --git a/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-login.test.mjs b/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-login.test.mjs new file mode 100644 index 0000000..4b44254 --- /dev/null +++ b/cocoscreator_projects/framework-tests/legacy-layer-migration/poc-login.test.mjs @@ -0,0 +1,44 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { execSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; + +// PoC 阶段 3 端到端: Layer00002.xml Login_Layer (18 spirits, group 2, 包含 Spirit405 渠道logo + +// Spirit177 游客登录 anchor-test cases). 验证生成 prefab 与 fixtures/Login_Layer.prefab 在 +// 渠道logo + 游客登录两个 anchor 节点 _lpos 精度 < 0.001. +// +// 路径从 cocoscreator_projects/ 运行 (与 poc-protocol.test.mjs / poc-iconbutton.test.mjs 风格一致). +const CLI = 'node scripts/legacy-layer-to-cocos-prefab-cli.mjs'; +const INPUT = '../projects/Game_Surface_3/save/Layer00002.xml'; +const TARGET = 'YouleNexus/assets/framework/ui/prefabs/Login_Layer.prefab'; +const OUTPUT_DIR = 'YouleNexus/out/legacy-migration/'; +const OUTPUT = 'YouleNexus/out/legacy-migration/Login_Layer.prefab'; + +test('Login_Layer 端到端 - 渠道logo _lpos 误差 < 0.001', () => { + execSync(`${CLI} ${INPUT} ${TARGET} ${OUTPUT_DIR}`, { stdio: 'pipe' }); + + const generated = JSON.parse(readFileSync(OUTPUT, 'utf8')); + const expected = JSON.parse(readFileSync(TARGET, 'utf8')); + + // 找渠道logo 节点(_name 包含"渠道") + const genLogo = generated.find(o => o.__type__ === 'cc.Node' && o._name && o._name.includes('渠道')); + const expLogo = expected.find(o => o.__type__ === 'cc.Node' && o._name && o._name.includes('渠道')); + assert.ok(genLogo, 'generated 缺渠道logo node'); + assert.ok(expLogo, 'expected 缺渠道logo node'); + assert.ok(Math.abs(genLogo._lpos.x - expLogo._lpos.x) < 0.001, `x mismatch: gen=${genLogo._lpos.x} exp=${expLogo._lpos.x}`); + assert.ok(Math.abs(genLogo._lpos.y - expLogo._lpos.y) < 0.001, `y mismatch: gen=${genLogo._lpos.y} exp=${expLogo._lpos.y}`); +}); + +test('Login_Layer 端到端 - 游客登录 _lpos 误差 < 0.001', () => { + execSync(`${CLI} ${INPUT} ${TARGET} ${OUTPUT_DIR}`, { stdio: 'pipe' }); + + const generated = JSON.parse(readFileSync(OUTPUT, 'utf8')); + const expected = JSON.parse(readFileSync(TARGET, 'utf8')); + + const genVisitor = generated.find(o => o.__type__ === 'cc.Node' && o._name && o._name.includes('游客')); + const expVisitor = expected.find(o => o.__type__ === 'cc.Node' && o._name && o._name.includes('游客')); + assert.ok(genVisitor); + assert.ok(expVisitor); + assert.ok(Math.abs(genVisitor._lpos.x - expVisitor._lpos.x) < 0.001); + assert.ok(Math.abs(genVisitor._lpos.y - expVisitor._lpos.y) < 0.001); +});