forked from riccardo-forina/use-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseBreadcrumb.test.tsx
41 lines (34 loc) · 1.24 KB
/
useBreadcrumb.test.tsx
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
39
40
41
import * as React from 'react';
import { Link, Route, Switch } from 'react-router-dom';
import { render, fireEvent } from '@test/setup';
import { AppLayout, useBreadcrumb } from '.';
const SampleBreadcrumb = <div data-testid={'test-breadcrumb'}>breadcrumb</div>;
const SamplePageWithBreadcrumb: React.FunctionComponent = () => {
useBreadcrumb(SampleBreadcrumb);
return (
<div>
<Link to={'/no-breadcrumb'} data-testid={'go-to-page-without-breadcrumb'}>
Go to page without breadcrumb
</Link>
</div>
);
};
describe('useBreadcrumb tests', () => {
test('should render a breadcrumb, and then remove it if the content changes to a page without a breadcrumb', async () => {
const { getByTestId, getByText, queryByTestId } = render(
<AppLayout>
<Switch>
<Route path={'/'} exact={true}>
<SamplePageWithBreadcrumb />
</Route>
<Route path={'/no-breadcrumb'}>page with no breadcrumb</Route>
</Switch>
</AppLayout>
);
getByTestId('test-breadcrumb');
getByText('breadcrumb');
fireEvent.click(getByTestId('go-to-page-without-breadcrumb'));
getByText('page with no breadcrumb');
expect(queryByTestId('test-breadcrumb')).toBeNull();
});
});