Skip to content

Commit 41e1e5a

Browse files
committed
test(app): cover scrollRestoration mount/unmount in HomePage and PlotsPage
The cleanup-on-unmount branch added in the previous commit wasn't exercised, so codecov/patch/frontend stayed below the 80% threshold. Add a mount/unmount test to each page that asserts scrollRestoration flips to 'manual' on mount and back to 'auto' on unmount.
1 parent dac7125 commit 41e1e5a

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

app/src/pages/HomePage.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from 'vitest';
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import { render, screen } from '../test-utils';
33

44
// Mock hooks
@@ -116,4 +116,20 @@ describe('HomePage', () => {
116116
render(<HomePage />);
117117
expect(screen.getByTestId('helmet')).toBeInTheDocument();
118118
});
119+
120+
describe('scrollRestoration', () => {
121+
const original = history.scrollRestoration;
122+
123+
afterEach(() => {
124+
history.scrollRestoration = original;
125+
});
126+
127+
it("sets scrollRestoration to 'manual' on mount and restores 'auto' on unmount", () => {
128+
history.scrollRestoration = 'auto';
129+
const { unmount } = render(<HomePage />);
130+
expect(history.scrollRestoration).toBe('manual');
131+
unmount();
132+
expect(history.scrollRestoration).toBe('auto');
133+
});
134+
});
119135
});

app/src/pages/PlotsPage.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from 'vitest';
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22
import { render, screen } from '../test-utils';
33

44
vi.mock('../hooks', () => ({
@@ -68,4 +68,20 @@ describe('PlotsPage', () => {
6868
render(<PlotsPage />);
6969
expect(screen.getByTestId('helmet')).toBeInTheDocument();
7070
});
71+
72+
describe('scrollRestoration', () => {
73+
const original = history.scrollRestoration;
74+
75+
afterEach(() => {
76+
history.scrollRestoration = original;
77+
});
78+
79+
it("sets scrollRestoration to 'manual' on mount and restores 'auto' on unmount", () => {
80+
history.scrollRestoration = 'auto';
81+
const { unmount } = render(<PlotsPage />);
82+
expect(history.scrollRestoration).toBe('manual');
83+
unmount();
84+
expect(history.scrollRestoration).toBe('auto');
85+
});
86+
});
7187
});

0 commit comments

Comments
 (0)