73 lines
5.0 KiB
TypeScript
73 lines
5.0 KiB
TypeScript
import { test } from 'node:test';
|
|
import { strict as assert } from 'node:assert';
|
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
|
|
// 校验保存后的场景契约,不通过手工修改场景来修正测试。 / Verify the saved scene contract; never rewrite scenes to satisfy tests.
|
|
type Entry = Record<string, any>;
|
|
const scene: Entry[] = JSON.parse(readFileSync('assets/Welcome.scene', 'utf8'));
|
|
const node = (name: string): Entry => scene.find(value => value.__type__ === 'cc.Node' && value._name === name)!;
|
|
const component = (name: string, type: string): Entry => node(name)._components.map((ref: Entry) => scene[ref.__id__]).find((value: Entry) => value.__type__ === type)!;
|
|
|
|
test('project design resolution and start scene use the portrait login scene', () => {
|
|
const settings = JSON.parse(readFileSync('settings/cocos.config.json', 'utf8'));
|
|
assert.equal(settings.engine.designResolution.width, 1080);
|
|
assert.equal(settings.engine.designResolution.height, 1920);
|
|
assert.equal(settings.builder.common.startScene, JSON.parse(readFileSync('assets/Welcome.scene.meta', 'utf8')).uuid);
|
|
assert.equal(component('Canvas', 'cc.UITransform')._contentSize.width, 1080);
|
|
assert.equal(component('Canvas', 'cc.UITransform')._contentSize.height, 1920);
|
|
assert.equal(node('Canvas')._lpos.x, 540);
|
|
assert.equal(node('Canvas')._lpos.y, 960);
|
|
assert.equal(component('Canvas', 'cc.Widget')._alignFlags, 0);
|
|
});
|
|
|
|
test('reference artwork retains independent editable sprites, exact positions and proportions', () => {
|
|
for (const [name, x, y, width, height] of [
|
|
['BrandMark', 4, 466.5, 982, 643],
|
|
['FruitArrangement', -7.5, -78, 991, 456],
|
|
['GuestAccess', -1.5, -460, 1027, 268],
|
|
] as const) {
|
|
const item = node(name), transform = component(name, 'cc.UITransform'), sprite = component(name, 'cc.Sprite');
|
|
assert.ok(item, name);
|
|
assert.equal(item._lpos.x, x); assert.equal(item._lpos.y, y);
|
|
assert.equal(transform._contentSize.width, width); assert.equal(transform._contentSize.height, height);
|
|
assert.equal(sprite._isTrimmedMode, false); assert.equal(sprite._sizeMode, 0);
|
|
assert.ok(sprite._spriteFrame.__uuid__);
|
|
assert.equal(item._lscale.x, 1); assert.equal(item._lscale.y, 1);
|
|
}
|
|
assert.equal(node('AuthenticationStatus')._active, false);
|
|
assert.deepEqual(component('Camera', 'cc.Camera')._color, { __type__: 'cc.Color', r: 55, g: 0, b: 34, a: 255 });
|
|
});
|
|
|
|
test('decorative backdrop is independent and behind the editable foreground', () => {
|
|
const children = node('Canvas')._children.map((ref: Entry) => scene[ref.__id__]._name);
|
|
assert.ok(children.indexOf('OrchardBackdrop') < children.indexOf('WelcomeComposition'));
|
|
const meta = JSON.parse(readFileSync('assets/login/visuals/orchard-backdrop.jpg.meta', 'utf8'));
|
|
assert.equal(component('OrchardBackdrop', 'cc.Sprite')._spriteFrame.__uuid__, meta.uuid + '@f9941');
|
|
assert.equal(component('OrchardBackdrop', 'cc.UITransform')._contentSize.width, 1080);
|
|
assert.equal(component('OrchardBackdrop', 'cc.UITransform')._contentSize.height, 1920);
|
|
});
|
|
|
|
test('reference footer is editable, underlined and separated from authentication notices', () => {
|
|
assert.equal(component('GuestReassurance', 'cc.Label')._string, 'No account needed');
|
|
assert.equal(component('PrivacyLink', 'cc.Label')._string, 'Privacy Policy');
|
|
assert.equal(component('TermsLink', 'cc.Label')._string, 'Terms of Service');
|
|
assert.equal(component('PrivacyLink', 'cc.Label')._isUnderline, true);
|
|
assert.equal(component('TermsLink', 'cc.Label')._isUnderline, true);
|
|
const controller = node('WelcomeComposition')._components.map((ref: Entry) => scene[ref.__id__]).find((value: Entry) => value.privacyButton);
|
|
assert.equal(scene[controller.privacyButton.__id__].__type__, 'cc.Button');
|
|
assert.equal(scene[controller.termsButton.__id__].__type__, 'cc.Button');
|
|
assert.equal(scene[controller.notice.__id__].__type__, 'cc.Label');
|
|
assert.equal(controller.privacyUrl, ''); assert.equal(controller.termsUrl, '');
|
|
const status = node('AuthenticationStatus'), height = component('AuthenticationStatus', 'cc.UITransform')._contentSize.height;
|
|
assert.ok(status._lpos.y + height / 2 < node('GuestReassurance')._lpos.y - 45);
|
|
assert.ok(status._lpos.y - height / 2 > node('PrivacyLink')._lpos.y + 44);
|
|
});
|
|
|
|
test('login view has explicit button/status bindings and no source artwork filenames', () => {
|
|
const controller = node('WelcomeComposition')._components.map((ref: Entry) => scene[ref.__id__]).find((value: Entry) => value.guestButton);
|
|
assert.equal(scene[controller.guestButton.__id__].__type__, 'cc.Button');
|
|
assert.equal(scene[controller.statusLabel.__id__].__type__, 'cc.Label');
|
|
const names = readdirSync('assets/login/visuals').filter(name => !name.endsWith('.meta')).sort();
|
|
assert.deepEqual(names, ['brand-lockup.png', 'guest-access-pill.png', 'orchard-backdrop.jpg', 'orchard-cluster.png', 'welcome-layout-guide.png']);
|
|
assert.ok(readFileSync('.gitignore', 'utf8').includes('/common-key/'));
|
|
}); |