Skip to content

Commit 82b0bb6

Browse files
author
Leemalin Moodley
committed
fix: added a test and fixed bad test setup
1 parent bb3e1eb commit 82b0bb6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/main/frontend/common/components/status-icon.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ describe("StatusIcon", () => {
127127
expect(result.current).to.equal(0);
128128
unmount();
129129
});
130+
it("should continue progress when waitingForInput is true", async () => {
131+
const { result, unmount } = renderHook(() => {
132+
return useStageProgress({
133+
...mockStage,
134+
state: Result.running,
135+
startTimeMillis: now - 2_000,
136+
previousTotalDurationMillis: 20_000,
137+
waitingForInput: true,
138+
});
139+
});
140+
expect(result.current).to.equal(10);
141+
await act(() => vi.advanceTimersByTime(1_000));
142+
expect(result.current).to.equal(15);
143+
await act(() => vi.advanceTimersByTime(1_000));
144+
expect(result.current).to.equal(20);
145+
unmount();
146+
});
130147
});
131148
describe("other states", function () {
132149
for (const state in Result) {

src/main/frontend/setupTests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,20 @@ const IntersectionObserverMock = vi.fn(() => ({
88
}));
99

1010
vi.stubGlobal("IntersectionObserver", IntersectionObserverMock);
11+
12+
// Ensure a functional localStorage implementation for tests that persist user preferences.
13+
if (
14+
!('localStorage' in window) ||
15+
typeof window.localStorage?.getItem !== 'function' ||
16+
typeof window.localStorage?.setItem !== 'function'
17+
) {
18+
const store: Record<string, string> = {};
19+
const localStoragePolyfill = {
20+
getItem: (key: string) => (key in store ? store[key] : null),
21+
setItem: (key: string, value: string) => { store[key] = String(value); },
22+
removeItem: (key: string) => { delete store[key]; },
23+
clear: () => { Object.keys(store).forEach(k => delete store[k]); },
24+
};
25+
// @ts-expect-error override for test environment
26+
window.localStorage = localStoragePolyfill;
27+
}

0 commit comments

Comments
 (0)