|
| 1 | +import { describe, expect, it, vi } from 'vitest'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import NotFound from './not-found'; |
| 4 | + |
| 5 | +vi.mock('next/link', () => ({ |
| 6 | + default: ({ href, children, ...props }: { href: string; children: React.ReactNode }) => ( |
| 7 | + <a href={href} {...props}> |
| 8 | + {children} |
| 9 | + </a> |
| 10 | + ), |
| 11 | +})); |
| 12 | + |
| 13 | +describe('NotFound', () => { |
| 14 | + it('renders without crashing', () => { |
| 15 | + render(<NotFound />); |
| 16 | + |
| 17 | + expect(document.body).toBeTruthy(); |
| 18 | + }); |
| 19 | + |
| 20 | + it('renders the oops text', () => { |
| 21 | + render(<NotFound />); |
| 22 | + |
| 23 | + expect(screen.getAllByText('𝒐𝒐𝒑𝒔')).toHaveLength(2); |
| 24 | + }); |
| 25 | + |
| 26 | + it('renders git checkout main text', () => { |
| 27 | + render(<NotFound />); |
| 28 | + |
| 29 | + expect(screen.getByText(/git checkout main/i)).toBeTruthy(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('renders go back home link with root href', () => { |
| 33 | + render(<NotFound />); |
| 34 | + |
| 35 | + const homeLink = screen.getByRole('link', { |
| 36 | + name: /go back home/i, |
| 37 | + }); |
| 38 | + |
| 39 | + expect(homeLink.getAttribute('href')).toBe('/'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('renders github link pointing to commitpulse repository', () => { |
| 43 | + render(<NotFound />); |
| 44 | + |
| 45 | + const githubLink = screen.getByRole('link', { |
| 46 | + name: /git checkout main/i, |
| 47 | + }); |
| 48 | + |
| 49 | + expect(githubLink.getAttribute('href')).toContain('github.com'); |
| 50 | + expect(githubLink.getAttribute('href')).toContain('commitpulse'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments