BlueGit

timfa questward

Files

questward / client / tests / editor-save-ack.test.js

editor-save-ack.test.js

fix: apply editor chunk save acks so dirty drafts clear
timfa project_85689633_bot_782f591ee30607a5698798444cb41267 · pushed by timfa · 2 months ago
cf62e091 History
editor-save-ack.test.js 1.1 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import { OVERWORLD_ID } from "../../shared/world/dimensions.js";
4import { editorChunkSaveKey, shouldApplySelectedEditorChunk } from "../src/editor/saveAck.js";
5
6test("editorChunkSaveKey is dimension-scoped", () =>
7{
8 assert.equal(editorChunkSaveKey(OVERWORLD_ID, 1, 2), "overworld:1,2");
9 assert.equal(editorChunkSaveKey("Cave A", 1, 2), "cave-a:1,2");
10 assert.notEqual(
11 editorChunkSaveKey(OVERWORLD_ID, 0, 0),
12 editorChunkSaveKey("cave_a", 0, 0)
13 );
14 assert.equal(editorChunkSaveKey(undefined, 0, 0), editorChunkSaveKey(OVERWORLD_ID, 0, 0));
15});
16
17test("save ack applies even when the local draft is still dirty", () =>
18{
19 assert.equal(shouldApplySelectedEditorChunk({ isSaveAck: true, isDirty: true }), true);
20 assert.equal(shouldApplySelectedEditorChunk({ isSaveAck: true, isDirty: false }), true);
21});
22
23test("non-ack reload keeps unsaved paint on the selected chunk", () =>
24{
25 assert.equal(shouldApplySelectedEditorChunk({ isSaveAck: false, isDirty: true }), false);
26 assert.equal(shouldApplySelectedEditorChunk({ isSaveAck: false, isDirty: false }), true);
27});