Skip to content

Commit 072f7a9

Browse files
committed
Fix tests
[DISCO-139]
1 parent 1761159 commit 072f7a9

File tree

8 files changed

+51
-19
lines changed

8 files changed

+51
-19
lines changed

test/src/components/book-selector.test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import {render, screen} from '@testing-library/preact';
33
import BookSelector from '~/components/book-selector/book-selector';
4+
import {MemoryRouter} from 'react-router-dom';
5+
import {it, expect} from '@jest/globals';
46

57
const props = {
68
prompt: 'Which textbook(s) are you currently using?',
@@ -12,8 +14,12 @@ const props = {
1214
}
1315
};
1416

15-
it ('lists the books', async () => {
16-
render(<BookSelector {...props} />);
17+
it('lists the books', async () => {
18+
render(
19+
<MemoryRouter>
20+
<BookSelector {...props} />
21+
</MemoryRouter>
22+
);
1723
const checkboxes = await screen.findAllByRole('checkbox');
1824

1925
expect(checkboxes).toHaveLength(24);

test/src/pages/confirmation.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import {render, screen} from '@testing-library/preact';
33
import Confirmation from '~/pages/confirmation/confirmation';
4+
import {MemoryRouter} from 'react-router-dom';
5+
import {test, expect} from '@jest/globals';
46

57
const referrers = {
68
contact: 'Thanks for contacting us',
@@ -10,7 +12,11 @@ const referrers = {
1012
Reflect.ownKeys(referrers).forEach((ref) => {
1113
test(`does ${ref} thanks`, () => {
1214
window.history.pushState({}, 'confirmation', `/confirmation/${ref}`);
13-
render(<Confirmation />)
15+
render(
16+
<MemoryRouter>
17+
<Confirmation />
18+
</MemoryRouter>
19+
);
1420
expect(screen.getByRole('heading').textContent).toBe(referrers[ref]);
1521
});
1622
});

test/src/pages/details/book-details-context.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import LoaderPage from '~/components/jsx-helpers/loader-page';
33
import ShellContextProvider from '../../../helpers/shell-context';
44
import {DetailsContextProvider} from '~/pages/details/context';
5+
import {MemoryRouter} from 'react-router-dom';
56

67
function BookDetailsWithContext({data, children}) {
78
return (
@@ -15,6 +16,8 @@ function BookDetailsWithContext({data, children}) {
1516

1617
export default function BookDetailsLoader({slug, children}) {
1718
return (
18-
<LoaderPage slug={slug} Child={BookDetailsWithContext} doDocumentSetup props={{children}} />
19+
<MemoryRouter initialEntries={[slug]}>
20+
<LoaderPage slug={slug} Child={BookDetailsWithContext} doDocumentSetup props={{children}} />
21+
</MemoryRouter>
1922
);
2023
}

test/src/pages/details/let-us-know.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const polishTitle = 'Fizyka dla szkół wyższych. Tom 1';
88

99
test('handles English title', async () => {
1010
render(
11-
<BookDetailsLoader slug={'books/college-algebra'}>
11+
<BookDetailsLoader slug='books/college-algebra'>
1212
<LetUsKnow title={englishTitle} />
1313
</BookDetailsLoader>
1414
);
1515
await screen.findByText('Using this book? Let us know.');
1616
});
1717
test('handles Polish title', async () => {
1818
render(
19-
<BookDetailsLoader slug={'books/college-algebra'}>
19+
<BookDetailsLoader slug='books/college-algebra'>
2020
<LetUsKnow title={polishTitle} />
2121
</BookDetailsLoader>
2222
);

test/src/pages/details/resource-boxes.test.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
22
import {render, screen} from '@testing-library/preact';
33
import BookDetailsLoader from './book-details-context';
4-
import {MemoryRouter} from 'react-router-dom';
54
import ResourceBoxes from '~/pages/details/common/resource-box/resource-boxes';
65
import {
76
instructorResourceBoxPermissions,
87
studentResourceBoxPermissions
98
} from '~/pages/details/common/resource-box/resource-box';
9+
import {test, expect} from '@jest/globals';
1010

1111
// Test all the conditions in here:
1212
// userStatus: isInstructor: true|false
@@ -25,17 +25,15 @@ const userStatus = {
2525
};
2626
const payload = {
2727
heading: 'This is the heading',
28-
description: 'This is <b>a description</b> in HTML',
29-
}
28+
description: 'This is <b>a description</b> in HTML'
29+
};
3030

3131
function LangWrapResourceBoxes({models}) {
3232
// console.info('*** MODELS', models);
3333
return (
34-
<MemoryRouter initialEntries={['/details/books/sometitle?Instructor%20resources']}>
35-
<BookDetailsLoader slug='books/college-algebra'>
36-
<ResourceBoxes models={models} />
37-
</BookDetailsLoader>
38-
</MemoryRouter>
34+
<BookDetailsLoader slug='books/college-algebra'>
35+
<ResourceBoxes models={models} />
36+
</BookDetailsLoader>
3937
);
4038
}
4139

test/src/pages/errata/errata-summary.test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {render, screen} from '@testing-library/preact';
33
import {within} from '@testing-library/dom';
44
import userEvent from '@testing-library/user-event';
55
import ErrataSummaryLoader from '~/pages/errata-summary/errata-summary';
6-
import Table from '~/pages/errata-summary/table/table';
6+
import {MemoryRouter} from 'react-router-dom';
7+
import {test, expect} from '@jest/globals';
78

89
const searchStr = '/errata/?book=Anatomy%20and%20Physiology';
910

@@ -21,11 +22,19 @@ async function getTableRows() {
2122
}
2223

2324
test('shows all items in table', async () => {
24-
render(<ErrataSummaryLoader />)
25+
render(
26+
<MemoryRouter>
27+
<ErrataSummaryLoader />
28+
</MemoryRouter>
29+
);
2530
expect(await getTableRows()).toHaveLength(54);
2631
});
2732
test('filters', async () => {
28-
render(<ErrataSummaryLoader />)
33+
render(
34+
<MemoryRouter>
35+
<ErrataSummaryLoader />
36+
</MemoryRouter>
37+
);
2938
const filters = await screen.findByRole('radiogroup');
3039
const user = userEvent.setup({delay: null});
3140
const reviewButton = within(filters).queryByText('In Review');

test/src/pages/institutional-partnership/institutional-partnership.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React from 'react';
22
import InstitutionalPartnership from '~/pages/institutional-partnership/institutional-partnership';
33
import {render, screen} from '@testing-library/preact';
4+
import {MemoryRouter} from 'react-router-dom';
5+
import {describe, it, expect} from '@jest/globals';
46

57
describe('InstitutionalPartnership', () => {
68
it('creates', async () => {
79
render(
8-
<InstitutionalPartnership />
10+
<MemoryRouter>
11+
<InstitutionalPartnership />
12+
</MemoryRouter>
913
);
1014

1115
await screen.findByText('About the program');

test/src/pages/team.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import React from 'react';
22
import {render, screen} from '@testing-library/preact';
33
import TeamLoader from '~/pages/team/team';
4+
import {MemoryRouter} from 'react-router-dom';
5+
import {it, expect} from '@jest/globals';
46

57
it('creates with a big chunk of data', async () => {
6-
render(<TeamLoader />);
8+
render(
9+
<MemoryRouter>
10+
<TeamLoader />
11+
</MemoryRouter>
12+
);
713
expect(await screen.findByRole('navigation'));
814
expect(screen.queryAllByRole('heading').length).toBeGreaterThan(3);
915
});

0 commit comments

Comments
 (0)