-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathResources.test.js
41 lines (27 loc) · 1.38 KB
/
Resources.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import { BrowserRouter, Router, Link } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import data from './components/data/data.json';
import Resources from './components/Resources/Resources';
describe('Resources', () => {
test(" more info Link validation", async () => {
//check the more info link 12 times rendered on /resouces page
//check when click moreinfo link routes to corresponding page /resources/resource.id
//check each page has resource.name by getByText on the screen
let history = createMemoryHistory({ initialEntries: ["/resources"] });
render(<BrowserRouter><Resources ResourcesList={data} /></BrowserRouter>);
let moreinfoButtons = screen.getAllByText("More info");
for (let resource of data)
{
<Router history={history}>
<Link to={{ pathname: `/resources/${resource.id}` }}>More info</Link>
</Router>
expect(moreinfoButtons).toHaveLength(12)
fireEvent.click(moreinfoButtons[`${resource.id-1}`]);
expect(location.pathname).toEqual(`/resources/${resource.id}`);
await expect(screen.getByText(`${resource.name}`)).toBeInTheDocument();
}
});
screen.debug();
});