|
1 | 1 | import React from 'react'; |
2 | 2 | import {render} from '@testing-library/react'; |
| 3 | +import userEvent from '@testing-library/user-event'; |
3 | 4 | import NavbarBrand from '../NavbarBrand'; |
4 | 5 |
|
5 | 6 | describe('NavbarBrand', () => { |
@@ -28,4 +29,34 @@ describe('NavbarBrand', () => { |
28 | 29 | } = render(<NavbarBrand href={href} />); |
29 | 30 | expect(navbarBrand.getAttribute('href')).toBe(href); |
30 | 31 | }); |
| 32 | + |
| 33 | + test('relative links are internal by default', () => { |
| 34 | + const navbarBrand = render( |
| 35 | + <NavbarBrand href="/relative">Clickable</NavbarBrand> |
| 36 | + ); |
| 37 | + |
| 38 | + const mockEventListener = jest.fn(); |
| 39 | + window.addEventListener('_dashprivate_pushstate', mockEventListener); |
| 40 | + window.scrollTo = jest.fn(); |
| 41 | + |
| 42 | + expect(mockEventListener.mock.calls).toHaveLength(0); |
| 43 | + userEvent.click(navbarBrand.getByText('Clickable')); |
| 44 | + expect(mockEventListener.mock.calls).toHaveLength(1); |
| 45 | + }); |
| 46 | + |
| 47 | + test('relative links are external with external_link=true', () => { |
| 48 | + const navbarBrand = render( |
| 49 | + <NavbarBrand href="/relative" external_link> |
| 50 | + Clickable |
| 51 | + </NavbarBrand> |
| 52 | + ); |
| 53 | + |
| 54 | + const mockEventListener = jest.fn(); |
| 55 | + window.addEventListener('_dashprivate_pushstate', mockEventListener); |
| 56 | + window.scrollTo = jest.fn(); |
| 57 | + |
| 58 | + expect(mockEventListener.mock.calls).toHaveLength(0); |
| 59 | + userEvent.click(navbarBrand.getByText('Clickable')); |
| 60 | + expect(mockEventListener.mock.calls).toHaveLength(0); |
| 61 | + }); |
31 | 62 | }); |
0 commit comments