fix: ask before replacing a saved preset

Saving a character, object, or scene reused an existing name and
overwrote that preset without asking. Updating the preset already
linked to the region still saves directly.
This commit is contained in:
by-ae
2026-11-01 07:31:19 +10:00
parent 17858e1963
commit 479e0bb069
4 changed files with 61 additions and 5 deletions
+23 -1
View File
@@ -8,7 +8,9 @@ globalThis.window = {
},
};
const { loadStores, deleteStoreEntry, saveStoreEntry, normalizeStoreName } = await import("../web/js/ideogram4_shared.js");
const {
loadStores, deleteStoreEntry, saveStoreEntry, normalizeStoreName, savedPresetCollision,
} = await import("../web/js/ideogram4_shared.js");
describe("loadStores", () => {
const originalFetch = globalThis.fetch;
@@ -54,6 +56,26 @@ describe("loadStores", () => {
});
});
describe("savedPresetCollision", () => {
it("names a different preset that would be replaced", () => {
assert.equal(savedPresetCollision(["Ada", "Bea"], "Bea"), "Bea");
assert.equal(savedPresetCollision(["Ada"], "Cara"), null);
assert.equal(savedPresetCollision(["Ada"], " "), null);
assert.equal(savedPresetCollision([], "Ada"), null);
});
it("does not treat an update of the linked preset as a replacement", () => {
assert.equal(savedPresetCollision(["Ada"], "Ada", "Ada"), null);
assert.equal(savedPresetCollision(["Ada", "Bea"], "Bea", "Ada"), "Bea");
});
it("matches a composed name to the stored spelling", () => {
const nfd = "Émilie".normalize("NFD");
assert.equal(savedPresetCollision(["Émilie"], nfd), "Émilie");
assert.equal(savedPresetCollision(["Émilie"], ` ${nfd} `, "Émilie"), null);
});
});
describe("saveStoreEntry", () => {
const originalFetch = globalThis.fetch;