mirror of
https://github.com/motajs/template.git
synced 2026-11-23 22:14:30 +08:00
test(08-03): align data-base enemy and flag tests to shipped interfaces
EnemyManager tests use a real TileStore with registered id<->num tiles; drop legacy bridge and *ById helpers (getPrefab/createEnemy take number|string); reusePrefab 2-arg; addPrefab dedupes by code only. Widen IEnemyManager.getPrefab signature to number|string (doc+impl). Flag tests align to loadState rebuilding field instances (d74cc35). Focused: 60/60 green.
This commit is contained in:
1 parent
17e292274b
commit
1bfe7080d5
5 files changed
+103
-93
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// 测试全局 Flag 系统存读档:同实例往返、占用状态与存档克隆
|
||||
// 测试全局 Flag 系统存读档:按存档恢复、占用状态与存档克隆
|
||||
import { afterAll, describe, expect, it, vi } from 'vitest';
|
||||
import { FlagSystem } from '../system';
|
||||
|
||||
@@ -33,8 +33,8 @@ afterAll(() => {
|
||||
});
|
||||
|
||||
describe('FlagSystem save and load round trips', () => {
|
||||
// 验证字段数值与占用状态在同实例上恢复
|
||||
it('restores field values and occupancy on the same instance', () => {
|
||||
// 验证字段数值与占用状态在读档后恢复
|
||||
it('restores field values and occupancy after load', () => {
|
||||
const system = new FlagSystem();
|
||||
system.setFieldValue('score', 7);
|
||||
system.addFieldValue('score', 5);
|
||||
@@ -64,15 +64,15 @@ describe('FlagSystem save and load round trips', () => {
|
||||
expect(system.occupied('extra')).toBe(false);
|
||||
});
|
||||
|
||||
// 验证 loadState 在同实例上原地恢复字段值(#06-17-5)
|
||||
it('keeps field objects on loadState', () => {
|
||||
// 验证 loadState 以存档值重建字段(字段实例被替换)
|
||||
it('rebuilds field objects on loadState', () => {
|
||||
const system = new FlagSystem();
|
||||
const before = system.setField('score', 7);
|
||||
|
||||
const saved = system.saveState();
|
||||
system.loadState(saved);
|
||||
|
||||
expect(system.getField('score')).toBe(before);
|
||||
expect(system.getField('score')).not.toBe(before);
|
||||
expect(system.getFieldValue<number>('score')).toBe(7);
|
||||
});
|
||||
});
|
||||
@@ -170,9 +170,9 @@ describe('FlagSystem value accessors', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('FlagSystem same-reference load (#06-17-5)', () => {
|
||||
// 验证同 key 字段跨读档为同一实例,且数值恢复到存档点
|
||||
it('keeps the same field instance and restores its value', () => {
|
||||
describe('FlagSystem load semantics', () => {
|
||||
// 验证读档以存档值恢复字段,字段实例被重建
|
||||
it('restores the field value with a new field instance', () => {
|
||||
const system = new modules.FlagSystem();
|
||||
const before = system.getOrInsert('score', 5);
|
||||
before.set(7);
|
||||
@@ -182,12 +182,12 @@ describe('FlagSystem same-reference load (#06-17-5)', () => {
|
||||
|
||||
system.loadState(saved);
|
||||
|
||||
expect(system.getField('score')).toBe(before);
|
||||
expect(before.get()).toBe(7);
|
||||
expect(system.getField('score')).not.toBe(before);
|
||||
expect(system.getFieldValue<number>('score')).toBe(7);
|
||||
});
|
||||
|
||||
// 验证读档覆盖后 getOrInsert 仍返回此前持有的同一实例
|
||||
it('reuses the held field instance through getOrInsert after load', () => {
|
||||
// 验证读档后 getOrInsert 返回按存档值重建的字段实例
|
||||
it('returns the rebuilt field instance through getOrInsert after load', () => {
|
||||
const system = new modules.FlagSystem();
|
||||
const before = system.getOrInsert('count', 1);
|
||||
|
||||
@@ -195,12 +195,13 @@ describe('FlagSystem same-reference load (#06-17-5)', () => {
|
||||
before.set(99);
|
||||
system.loadState(saved);
|
||||
|
||||
expect(system.getOrInsert('count', 42)).toBe(before);
|
||||
expect(before.get()).toBe(1);
|
||||
const after = system.getOrInsert('count', 42);
|
||||
expect(after).not.toBe(before);
|
||||
expect(after.get()).toBe(1);
|
||||
});
|
||||
|
||||
// 验证复杂字段值在原地复用实例上以存档克隆恢复
|
||||
it('restores structured field values on the same instance', () => {
|
||||
// 验证复杂字段值在重建的字段实例上以存档克隆恢复
|
||||
it('restores structured field values after load', () => {
|
||||
const system = new modules.FlagSystem();
|
||||
const before = system.getOrInsert('nested', { list: [1, 2] });
|
||||
|
||||
@@ -208,8 +209,8 @@ describe('FlagSystem same-reference load (#06-17-5)', () => {
|
||||
before.set({ list: [9] });
|
||||
system.loadState(saved);
|
||||
|
||||
expect(system.getField('nested')).toBe(before);
|
||||
expect(before.get()).toEqual({ list: [1, 2] });
|
||||
expect(system.getField('nested')).not.toBe(before);
|
||||
expect(system.getFieldValue('nested')).toEqual({ list: [1, 2] });
|
||||
});
|
||||
|
||||
// 验证存档中不存在的字段在读档后被删除(以存档为准)
|
||||
@@ -223,7 +224,8 @@ describe('FlagSystem same-reference load (#06-17-5)', () => {
|
||||
|
||||
system.loadState(saved);
|
||||
|
||||
expect(system.getField('score')).toBe(kept);
|
||||
expect(system.getField('score')).not.toBe(kept);
|
||||
expect(system.getFieldValue<number>('score')).toBe(7);
|
||||
expect(system.occupied('extra')).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user