Download web/src/components/states.test.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 3.6 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/states.test.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/components/states.test.tsx
-
curl -L -o states.test.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/components/states.test.tsx
3.6 kB
| import { Table } from '@mantine/core'; | |
| import { fireEvent, screen } from '@testing-library/react'; | |
| import { describe, expect, it, vi } from 'vitest'; | |
| import { renderUi } from '../test/utils'; | |
| import { Pager } from './common'; | |
| import { NavTabs } from './NavTabs'; | |
| import { DataTable, LoadingState, QueryState } from './states'; | |
| const rows = <Table.Tr><Table.Td>alice</Table.Td><Table.Td>admin</Table.Td></Table.Tr>; | |
| describe('shared states', () => { | |
| it('loading is announced once, with words', () => { | |
| renderUi(<LoadingState label="Loading the users" />); | |
| expect(screen.getByRole('status')).toHaveTextContent('Loading the users'); | |
| }); | |
| it('QueryState shows loading, then the error with Try again, then empty, then the content', () => { | |
| const refetch = vi.fn(); | |
| let view = renderUi(<QueryState q={{ isLoading: true }}>content</QueryState>); | |
| expect(screen.getByTestId('loading-state')).toBeInTheDocument(); | |
| view.unmount(); | |
| view = renderUi(<QueryState q={{ error: new Error('boom'), refetch }}>content</QueryState>); | |
| fireEvent.click(screen.getByTestId('error-retry')); | |
| expect(refetch).toHaveBeenCalledOnce(); | |
| view.unmount(); | |
| view = renderUi(<QueryState q={{}} isEmpty empty={<p>No users yet.</p>}>content</QueryState>); | |
| expect(screen.getByText('No users yet.')).toBeInTheDocument(); | |
| view.unmount(); | |
| view = renderUi(<QueryState q={{}}>content</QueryState>); | |
| expect(screen.getByText('content')).toBeInTheDocument(); | |
| }); | |
| it('DataTable is a named, keyboard-reachable region with loading and empty rows', () => { | |
| let view = renderUi(<DataTable label="Users" columns={['User', { label: 'Actions', hidden: true }]} q={{ isLoading: true }} rowCount={0}>{rows}</DataTable>); | |
| const region = screen.getByRole('region', { name: 'Users' }); | |
| expect(region).toHaveAttribute('tabindex', '0'); | |
| expect(screen.getByRole('table', { name: 'Users' })).toBeInTheDocument(); | |
| expect(screen.getByRole('columnheader', { name: 'Actions' })).toBeInTheDocument(); // hidden visually, still named | |
| expect(screen.getAllByTestId('table-loading')).toHaveLength(3); | |
| view.unmount(); | |
| view = renderUi(<DataTable label="Users" columns={['User', 'Role']} q={{}} rowCount={0} empty="No users yet.">{rows}</DataTable>); | |
| expect(screen.getByTestId('table-empty')).toHaveTextContent('No users yet.'); | |
| view.unmount(); | |
| view = renderUi(<DataTable label="Users" columns={['User', 'Role']} q={{}} rowCount={1}>{rows}</DataTable>); | |
| expect(screen.getByRole('cell', { name: 'alice' })).toBeInTheDocument(); | |
| }); | |
| it('pagination controls have names', () => { | |
| renderUi(<Pager total={120} limit={50} offset={0} onChange={() => {}} />); | |
| expect(screen.getByRole('navigation', { name: 'Pagination' })).toBeInTheDocument(); | |
| expect(screen.getByRole('button', { name: 'Page 2 of 3' })).toBeInTheDocument(); | |
| expect(screen.getByRole('button', { name: 'Next page' })).toBeInTheDocument(); | |
| }); | |
| it('NavTabs marks the current view for screen readers', () => { | |
| renderUi(<NavTabs label="Views of this test run" items={[{ to: '/runs/1/scenarios', label: 'Scenarios', active: true }, { to: '/runs/1/report', label: 'Report', active: false }]} />); | |
| expect(screen.getByRole('navigation', { name: 'Views of this test run' })).toBeInTheDocument(); | |
| expect(screen.getByRole('link', { name: 'Scenarios' })).toHaveAttribute('aria-current', 'page'); | |
| expect(screen.getByRole('link', { name: 'Report' })).not.toHaveAttribute('aria-current'); | |
| }); | |
| }); | |