Skip to content

Commit f661326

Browse files
committed
main-menu test coverage
1 parent 5b78955 commit f661326

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

test/src/layouts/default/data/osmenu.json renamed to test/src/layouts/default/data/oxmenu.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
},
3232
{"label": "Webinars", "partial_url": "/webinars"}
3333
]
34+
},
35+
{
36+
"oops": "Not a valid menu"
3437
}
3538
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import StickyNote from '~/layouts/default/header/sticky-note/sticky-note';
1313
import stickyData from './data/sticky.json';
1414
import fundraiserData from './data/fundraiser.json';
1515
import footerData from './data/footer.json';
16-
import oxmenuData from './data/osmenu.json';
16+
import oxmenuData from './data/oxmenu.json';
1717
import giveTodayData from './data/give-today.json';
1818
import giveBannerData from './data/givebanner.json';
1919
import * as CF from '~/helpers/cms-fetch';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import {render, screen} from '@testing-library/preact';
3+
import ShellContextProvider from '../../../helpers/shell-context';
4+
import MainMenu from '~/layouts/default/header/menus/main-menu/main-menu';
5+
import MemoryRouter from '../../../helpers/future-memory-router';
6+
import * as ULC from '~/contexts/language';
7+
8+
jest.mock('~/models/give-today', () => jest.fn().mockReturnValue({}));
9+
10+
function Component({path = '/'}) {
11+
return <ShellContextProvider>
12+
<MemoryRouter initialEntries={[path]}>
13+
<MainMenu />
14+
</MemoryRouter>
15+
</ShellContextProvider>;
16+
}
17+
18+
describe('main-menu', () => {
19+
it('shows subjects menu when there are subjects', async () => {
20+
render(<Component />);
21+
22+
await screen.findByRole('link', {name: 'Math'});
23+
screen.getByRole('link', {name: 'Spanish'});
24+
screen.getByRole('link', {name: '🍎 For K12 Teachers'});
25+
});
26+
it('hides language options in /details/books paths', async () => {
27+
render(<Component path='/details/books/a-book' />);
28+
29+
await screen.findByRole('link', {name: 'Math'});
30+
expect(screen.queryByRole('link', {name: 'Spanish'})).toBeNull();
31+
});
32+
it('hides k12 item in Spanish', async () => {
33+
const spyLang = jest.spyOn(ULC, 'default').mockReturnValue({language: 'es', setLanguage: jest.fn()});
34+
35+
render(<Component />);
36+
37+
await screen.findByRole('link', {name: 'Math'});
38+
expect(screen.queryByRole('link', {name: '🍎 For K12 Teachers'})).toBeNull();
39+
spyLang.mockReset();
40+
});
41+
});

0 commit comments

Comments
 (0)