diff --git a/frontend/__tests__/root/config.spec.ts b/frontend/__tests__/root/config.spec.ts index 7af04363c..d75583bc9 100644 --- a/frontend/__tests__/root/config.spec.ts +++ b/frontend/__tests__/root/config.spec.ts @@ -157,7 +157,7 @@ describe("Config", () => { expect(dispatchConfigEventMock).toHaveBeenCalledWith( "stopOnError", "off", - true, + false, "letter" ); @@ -195,6 +195,35 @@ describe("Config", () => { expect.stringContaining("numbers") ); }); + + it("saves configOverride values to localstorage if nosave=false", async () => { + //GIVEN + replaceConfig({}); + + //WHEN + Config.genericSet("minWpmCustomSpeed", 120); + + //THEN + //wait for debounce + await vi.advanceTimersByTimeAsync(2500); + + //save + expect(dbSaveConfigMock).toHaveBeenCalledWith({ + minWpmCustomSpeed: 120, + minWpm: "custom", + }); + + //send event + expect(dispatchConfigEventMock).toHaveBeenCalledWith( + "saveToLocalStorage", + expect.stringContaining("minWpmCustomSpeed") + ); + expect(dispatchConfigEventMock).toHaveBeenCalledWith( + "saveToLocalStorage", + expect.stringContaining("minWpm") + ); + }); + it("does not save to localstorage if nosave=true", async () => { //GIVEN diff --git a/frontend/src/ts/config.ts b/frontend/src/ts/config.ts index d52655071..cf732b09f 100644 --- a/frontend/src/ts/config.ts +++ b/frontend/src/ts/config.ts @@ -175,7 +175,7 @@ export function genericSet( continue; // no need to set if the value is already the same } - const set = genericSet(targetKey, targetValue, true); + const set = genericSet(targetKey, targetValue, nosave); if (!set) { throw new Error( `Failed to set config key "${targetKey}" with value "${targetValue}" for ${metadata.displayString} config override.`