Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions frontend/__tests__/states/live-stats.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
});
2 changes: 2 additions & 0 deletions frontend/src/ts/states/live-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down
Loading