1 | import React from 'react';
|
2 | import { render, cleanup } from '@testing-library/react';
|
3 | import { NavLink } from 'reactstrap';
|
4 | import Breadcrumbs, { Crumb } from '..';
|
5 |
|
6 | afterEach(cleanup);
|
7 |
|
8 | describe('Breadcrumbs', () => {
|
9 | test('should render', () => {
|
10 | const { container } = render(<Breadcrumbs active="" />);
|
11 | expect(container.firstChild).toMatchSnapshot();
|
12 | });
|
13 |
|
14 | test('should render child as current page', () => {
|
15 | const { container } = render(<Breadcrumbs active="Payer Space" />);
|
16 |
|
17 | expect(container.firstChild).toMatchSnapshot();
|
18 | });
|
19 |
|
20 | test('should render crumbs', () => {
|
21 | const crumbs: Crumb[] = [
|
22 | {
|
23 | name: 'my grand parent page',
|
24 | url: '/parent-page',
|
25 | },
|
26 | {
|
27 | name: 'my parent page',
|
28 | url: '/grand-parent-page',
|
29 | },
|
30 | ];
|
31 | const { container } = render(<Breadcrumbs crumbs={crumbs} active="Payer Space" />);
|
32 | expect(container.firstChild).toMatchSnapshot();
|
33 | });
|
34 |
|
35 | test('should render crumbs with missing values', () => {
|
36 | const crumbs: Crumb[] = [
|
37 | {
|
38 | name: 'my grand parent page',
|
39 | url: '/parent-page',
|
40 | },
|
41 | {
|
42 | name: '',
|
43 | url: '',
|
44 | },
|
45 | ];
|
46 | const { container } = render(<Breadcrumbs crumbs={crumbs} active="Payer Space" />);
|
47 | expect(container.firstChild).toMatchSnapshot();
|
48 | });
|
49 |
|
50 | test('should render custom ellipse', () => {
|
51 | const crumbs: Crumb[] = [
|
52 | {
|
53 | name: '',
|
54 | url: '',
|
55 | },
|
56 | ];
|
57 | const { container } = render(<Breadcrumbs crumbs={crumbs} emptyState="???" active="Payer Space" />);
|
58 |
|
59 | expect(container.firstChild).toMatchSnapshot();
|
60 | });
|
61 |
|
62 | test('should render custom home url', () => {
|
63 | const { getByText } = render(<Breadcrumbs homeUrl="/go-home" active="Payer Space" />);
|
64 |
|
65 | const homeBtn = getByText('Home');
|
66 |
|
67 | expect(homeBtn.getAttribute('href')).toBe('/go-home');
|
68 | });
|
69 |
|
70 | test('should render custom link tag', () => {
|
71 | const { getByText } = render(<Breadcrumbs homeUrl="/go-home" active="Payer Space" linkTag={NavLink} />);
|
72 |
|
73 | const homeBtn = getByText('Home');
|
74 |
|
75 | expect(homeBtn.className).toBe('nav-link');
|
76 | });
|
77 | });
|