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 = aliceadmin; describe('shared states', () => { it('loading is announced once, with words', () => { renderUi(); 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(content); expect(screen.getByTestId('loading-state')).toBeInTheDocument(); view.unmount(); view = renderUi(content); fireEvent.click(screen.getByTestId('error-retry')); expect(refetch).toHaveBeenCalledOnce(); view.unmount(); view = renderUi(No users yet.

}>content
); expect(screen.getByText('No users yet.')).toBeInTheDocument(); view.unmount(); view = renderUi(content); expect(screen.getByText('content')).toBeInTheDocument(); }); it('DataTable is a named, keyboard-reachable region with loading and empty rows', () => { let view = renderUi({rows}); 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({rows}); expect(screen.getByTestId('table-empty')).toHaveTextContent('No users yet.'); view.unmount(); view = renderUi({rows}); expect(screen.getByRole('cell', { name: 'alice' })).toBeInTheDocument(); }); it('pagination controls have names', () => { renderUi( {}} />); 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(); 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'); }); });