Skip to content

Commit 1cb8f5b

Browse files
committed
RouterTab: unit test
1 parent 8a0f302 commit 1cb8f5b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

client/common/RouterTab.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent, waitFor, history } from '../test-utils';
3+
import Tab from './RouterTab';
4+
5+
const mockPath = '/projects';
6+
const mockLinkText = 'Projects';
7+
8+
describe('Tab', () => {
9+
function rerender() {
10+
return render(<Tab to={mockPath}>{mockLinkText}</Tab>);
11+
}
12+
13+
it('renders a react-router NavLink with correct text and path', async () => {
14+
rerender();
15+
16+
const linkElement = screen.getByText(mockLinkText);
17+
expect(linkElement).toBeInTheDocument();
18+
expect(linkElement.getAttribute('href')).toBe(mockPath);
19+
20+
fireEvent.click(linkElement);
21+
await waitFor(() => expect(history.location.pathname).toEqual('/projects'));
22+
});
23+
24+
it('includes the dashboard-header class names', () => {
25+
const { container } = rerender();
26+
27+
const listItem = container.querySelector('li');
28+
const link = container.querySelector('a');
29+
30+
expect(listItem).toHaveClass('dashboard-header__tab');
31+
expect(link).toHaveClass('dashboard-header__tab__title');
32+
});
33+
});

0 commit comments

Comments
 (0)