From de198ff58b060b00cf443c1a15c61c4a0c17ddf2 Mon Sep 17 00:00:00 2001 From: MohdMaaz000 Date: Thu, 13 Aug 2026 17:19:45 +0530 Subject: [PATCH] fix(live-stats): update progress after custom text change --- frontend/__tests__/states/live-stats.spec.ts | 32 ++++++++++++++++++++ frontend/src/ts/states/live-stats.ts | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 frontend/__tests__/states/live-stats.spec.ts diff --git a/frontend/__tests__/states/live-stats.spec.ts b/frontend/__tests__/states/live-stats.spec.ts new file mode 100644 index 000000000000..8a0d37bb44ce --- /dev/null +++ b/frontend/__tests__/states/live-stats.spec.ts @@ -0,0 +1,32 @@ +import { createRoot } from "solid-js"; +import { describe, expect, it } from "vitest"; +import { setConfigStore } from "../../src/ts/config/store"; +import { getTimerText } from "../../src/ts/states/live-stats"; +import { setIsTestRestarting } from "../../src/ts/states/test"; +import * as CustomText from "../../src/ts/test/custom-text"; + +describe("live-stats", () => { + describe("getTimerText", () => { + it("updates progress text immediately when test is restarted after custom text limit change", () => { + createRoot((dispose) => { + setConfigStore("mode", "custom"); + CustomText.setLimitMode("word"); + CustomText.setLimitValue(9); + + expect(getTimerText()).toBe("0/9"); + + // Update custom text limit (simulating custom text change to 2 words) + CustomText.setLimitValue(2); + + // Trigger test restart signals (as occurs in restart()) + setIsTestRestarting(true); + setIsTestRestarting(false); + + // Progress text should immediately reflect the updated total without typing + expect(getTimerText()).toBe("0/2"); + + dispose(); + }); + }); + }); +}); diff --git a/frontend/src/ts/states/live-stats.ts b/frontend/src/ts/states/live-stats.ts index 37c218889a0b..2bf65106f1ed 100644 --- a/frontend/src/ts/states/live-stats.ts +++ b/frontend/src/ts/states/live-stats.ts @@ -13,6 +13,7 @@ import { getFocus, isResultCalculating, isTestActive, + isTestRestarting, } from "./test"; /** Whether this test counts down a time limit rather than a number of words. */ @@ -105,6 +106,7 @@ export const getLiveBurstText = createMemo(() => /** Countdown / word counter shown by the timer displays. */ export const getTimerText = createMemo(() => { + isTestRestarting(); if (isTimeLimitedTest()) { const limit = getTestTimeLimit(); const seconds = currentLiveStats.seconds ?? 0;