add vitest and regression tests for arc 1
This commit is contained in:
parent
0074f0e10c
commit
9f538b1543
9 changed files with 1561 additions and 4 deletions
106
src/editorCore.test.ts
Normal file
106
src/editorCore.test.ts
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import {
|
||||
getSpriteRows,
|
||||
normalizeImageRecordForSave,
|
||||
normalizeImagesPayloadForSave,
|
||||
normalizeTileRecordForSave,
|
||||
resolveUnifiedColorSymbol,
|
||||
setUnifiedColorEntries,
|
||||
} from "./editorCore";
|
||||
import type { JsonObject, JsonValue } from "./editorCore";
|
||||
|
||||
describe("editorCore", () => {
|
||||
it("normalizes tile records with padded rows and compatibility symbols", () => {
|
||||
const result = normalizeTileRecordForSave({
|
||||
id: "tile_grass",
|
||||
rows: ["A", "BC", "DROP"],
|
||||
width: 2,
|
||||
height: 2,
|
||||
});
|
||||
|
||||
expect(result).toEqual(expect.objectContaining({
|
||||
id: "tile_grass",
|
||||
symbol: "t",
|
||||
rows: ["A.", "BC"],
|
||||
width: 2,
|
||||
height: 2,
|
||||
}));
|
||||
});
|
||||
|
||||
it("normalizes image records into frame-based storage while preserving tile compatibility", () => {
|
||||
const result = normalizeImageRecordForSave({
|
||||
id: "tile_tree",
|
||||
roles: ["tile", "sprite", "other", "tile"],
|
||||
rows: ["A", "BC"],
|
||||
width: 2,
|
||||
height: 2,
|
||||
speed: -10,
|
||||
playback: "invalid",
|
||||
tileSymbol: "$",
|
||||
});
|
||||
|
||||
expect(result.rows).toBeUndefined();
|
||||
expect(result.symbol).toBeUndefined();
|
||||
expect(result.graphicRole).toBeUndefined();
|
||||
expect(result.roles).toEqual(["tile", "sprite"]);
|
||||
expect(result.defaultFrame).toBe("frame_0");
|
||||
expect(result.speed).toBe(0);
|
||||
expect(result.playback).toBe("normal");
|
||||
expect(result.tileSymbol).toBe("$");
|
||||
expect(result.frames).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "frame_0",
|
||||
rows: ["A.", "BC"],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("resolves sprite rows from the default enabled frame", () => {
|
||||
const record: JsonObject = {
|
||||
defaultFrame: "walk_1",
|
||||
frames: [
|
||||
{ id: "idle", rows: ["II"], enabled: true },
|
||||
{ id: "walk_1", rows: ["WW"], enabled: true },
|
||||
{ id: "disabled", rows: ["DD"], enabled: false },
|
||||
],
|
||||
};
|
||||
|
||||
expect(getSpriteRows(record)).toEqual(["WW"]);
|
||||
});
|
||||
|
||||
it("normalizes image payload arrays without changing non-record entries", () => {
|
||||
const payload: JsonValue = {
|
||||
schemaVersion: 1,
|
||||
images: [
|
||||
{
|
||||
id: "sprite_hero",
|
||||
roles: ["sprite"],
|
||||
rows: ["X"],
|
||||
},
|
||||
"leave-me-alone",
|
||||
],
|
||||
};
|
||||
|
||||
expect(normalizeImagesPayloadForSave(payload)).toEqual({
|
||||
schemaVersion: 1,
|
||||
images: [
|
||||
expect.objectContaining({
|
||||
id: "sprite_hero",
|
||||
roles: ["sprite"],
|
||||
defaultFrame: "frame_0",
|
||||
}),
|
||||
"leave-me-alone",
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("updates the unified color lookup from catalog entries", () => {
|
||||
setUnifiedColorEntries([
|
||||
{ key: "A", color: "#123456" },
|
||||
{ key: "!", color: "#FFFFFF" },
|
||||
]);
|
||||
|
||||
expect(resolveUnifiedColorSymbol("A")).toBe("#123456");
|
||||
expect(resolveUnifiedColorSymbol(".")).toBe("#00000000");
|
||||
expect(resolveUnifiedColorSymbol("Z", "#ABCDEF")).toBe("#ABCDEF");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue