|
| 1 | +/** |
| 2 | + * Sanity test for @uirouter/react with React 17 |
| 3 | + * This test verifies basic functionality works with React 17 |
| 4 | + */ |
| 5 | +import { describe, it, expect } from 'vitest'; |
| 6 | +import * as React from 'react'; |
| 7 | +import { render, screen, waitFor } from '@testing-library/react'; |
| 8 | +import { UIRouter, UIView, UISref, pushStateLocationPlugin } from '@uirouter/react'; |
| 9 | +import { memoryLocationPlugin } from '@uirouter/core'; |
| 10 | + |
| 11 | +const Home = () => <div data-testid="home">Home Page</div>; |
| 12 | +const About = () => <div data-testid="about">About Page</div>; |
| 13 | + |
| 14 | +const states = [ |
| 15 | + { name: 'home', url: '/home', component: Home }, |
| 16 | + { name: 'about', url: '/about', component: About }, |
| 17 | +]; |
| 18 | + |
| 19 | +describe('@uirouter/react with React 17', () => { |
| 20 | + it('renders UIRouter and UIView', async () => { |
| 21 | + render( |
| 22 | + <UIRouter plugins={[memoryLocationPlugin]} states={states}> |
| 23 | + <UIView /> |
| 24 | + </UIRouter> |
| 25 | + ); |
| 26 | + |
| 27 | + // Should render without crashing |
| 28 | + expect(document.body).toBeDefined(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('navigates to a state and renders the component', async () => { |
| 32 | + const { container } = render( |
| 33 | + <UIRouter plugins={[memoryLocationPlugin]} states={states}> |
| 34 | + <div> |
| 35 | + <nav> |
| 36 | + <UISref to="home"> |
| 37 | + <a data-testid="home-link">Home</a> |
| 38 | + </UISref> |
| 39 | + <UISref to="about"> |
| 40 | + <a data-testid="about-link">About</a> |
| 41 | + </UISref> |
| 42 | + </nav> |
| 43 | + <UIView /> |
| 44 | + </div> |
| 45 | + </UIRouter> |
| 46 | + ); |
| 47 | + |
| 48 | + // Click home link |
| 49 | + screen.getByTestId('home-link').click(); |
| 50 | + |
| 51 | + await waitFor(() => { |
| 52 | + expect(screen.getByTestId('home')).toBeDefined(); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it('UISref generates correct href', async () => { |
| 57 | + render( |
| 58 | + <UIRouter plugins={[memoryLocationPlugin]} states={states}> |
| 59 | + <UISref to="about"> |
| 60 | + <a data-testid="link">About</a> |
| 61 | + </UISref> |
| 62 | + </UIRouter> |
| 63 | + ); |
| 64 | + |
| 65 | + await waitFor(() => { |
| 66 | + const link = screen.getByTestId('link'); |
| 67 | + expect(link.getAttribute('href')).toContain('/about'); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments