Skip to content

Commit 942c139

Browse files
committed
More test
1 parent 81603d3 commit 942c139

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/app/layouts/default/shared.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ type StickyDataWithBanner = StickyDataRaw & {
2424
mode: 'emergency' | 'popup' | 'banner' | null;
2525
};
2626

27-
// Shim for incognito windows that disable localStorage
28-
if (!window.localStorage) {
29-
window.localStorage = {
30-
getItem(key: string) {return window.localStorage[key];},
31-
setItem() {},
32-
removeItem() {},
33-
clear() {},
34-
key() {return null;},
35-
length: 0
36-
};
37-
}
38-
3927
export function useSeenCounter(seenEnough: number): [boolean, () => void] {
4028
const [counter, increment] = React.useReducer(
4129
(s: number) => s + 1,

src/app/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ const GLOBAL_SETTINGS = ['piAId', 'piCId', 'piHostname'];
66

77
window.SETTINGS = {};
88

9+
// Shim for incognito windows that disable localStorage
10+
window.localStorage ??= {
11+
getItem(key) {return window.localStorage[key];},
12+
setItem() {},
13+
removeItem() {},
14+
clear() {},
15+
key() {return null;},
16+
length: 0
17+
};
18+
919
(async () => {
1020
const settings = (await cmsFetch('webview-settings')).settings;
1121

test/src/layouts/default/default.test.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ let mockPathname = {pathname: '/test-path'};
3333
jest.mock('react-router-dom', () => ({
3434
useLocation: () => mockPathname
3535
}));
36-
jest.mock('~/layouts/default/microsurvey-popup/microsurvey-popup', () => ({
37-
__esModule: true,
38-
default: () => <></>
39-
}));
36+
// jest.mock('~/layouts/default/microsurvey-popup/microsurvey-popup', () => ({
37+
// __esModule: true,
38+
// default: () => <></>
39+
// }));
4040

41-
const mockUseSharedDataContext = jest.fn().mockReturnValue(false);
41+
const mockUseSharedDataContext = jest.fn().mockReturnValue({stickyFooterState: [false, () => undefined]});
4242

4343
jest.mock('~/contexts/shared-data', () => ({
4444
__esModule: true,
@@ -70,7 +70,7 @@ describe('Layouts Default TypeScript Conversions', () => {
7070
});
7171

7272
describe('shared.tsx utilities', () => {
73-
test('useSeenCounter hook works with TypeScript types', () => {
73+
test('useSeenCounter hook works with TypeScript types', async () => {
7474
const TestComponent = () => {
7575
const [hasBeenSeenEnough, increment] = useSeenCounter(5);
7676

@@ -84,6 +84,15 @@ describe('Layouts Default TypeScript Conversions', () => {
8484

8585
render(<TestComponent />);
8686
expect(screen.getByTestId('seen-enough')).toHaveTextContent('false');
87+
const saveLS = window.localStorage;
88+
const saveWarn = console.warn;
89+
90+
console.warn = jest.fn();
91+
Reflect.deleteProperty(window, 'localStorage');
92+
await user.click(screen.getByRole('button'));
93+
expect(console.warn).toHaveBeenCalledWith('LocalStorage restricted');
94+
Reflect.defineProperty(window, 'localStorage', {value: saveLS});
95+
console.warn = saveWarn;
8796
});
8897

8998
test('usePutAway hook returns proper TypeScript types', () => {

0 commit comments

Comments
 (0)