Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions src/components/ColumnMenu/ColumnMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ describe('ColumnMenu', () => {
const { getByRole, getByText } = render(<ColumnMenu {...defaultProps} />)

const menu = getByRole('menu')
expect(menu).toBeDefined()
const ariaLabelledBy = menu.getAttribute('aria-labelledby')
expect(ariaLabelledBy).toBeDefined()
expect(ariaLabelledBy).toBeTruthy()
const labelElement = getByText('Test Column')
expect(labelElement).toBeDefined()
expect(labelElement.getAttribute('id')).toBe(ariaLabelledBy)
})

Expand All @@ -75,7 +73,7 @@ describe('ColumnMenu', () => {
const { container } = render(<ColumnMenu {...defaultProps} />)

const overlay = container.querySelector('[role="presentation"]')
expect(overlay).toBeDefined()
expect(overlay).toBeTruthy()
})
})

Expand All @@ -86,7 +84,6 @@ describe('ColumnMenu', () => {
)

const sortButton = getByRole('menuitem')
expect(sortButton).toBeDefined()
expect(sortButton.textContent).toBe('No sort')
})

Expand Down Expand Up @@ -127,7 +124,6 @@ describe('ColumnMenu', () => {
<ColumnMenu {...defaultProps} hideColumn={hideColumn} />
)
const hideOption = getByText('Hide column')
expect(hideOption).toBeDefined()
hideOption.click()
expect(hideColumn).toHaveBeenCalled()
})
Expand All @@ -142,7 +138,6 @@ describe('ColumnMenu', () => {
<ColumnMenu {...defaultProps} showAllColumns={showAllColumns} />
)
const showOption = getByText('Show all columns')
expect(showOption).toBeDefined()
showOption.click()
expect(showAllColumns).toHaveBeenCalled()
})
Expand All @@ -160,8 +155,8 @@ describe('ColumnMenu', () => {
showAllColumns={showAllColumns}
/>
)
expect(getByText('Hide column')).toBeDefined()
expect(getByText('Show all columns')).toBeDefined()
getByText('Hide column')
getByText('Show all columns')
})
})

Expand Down Expand Up @@ -247,7 +242,6 @@ describe('ColumnMenu', () => {
await user.keyboard('{ArrowUp}')

// Navigation should be handled (no specific assertion as useFocusManagement is mocked)
expect(menu).toBeDefined()
})

it('handles ArrowDown key', async () => {
Expand All @@ -258,8 +252,6 @@ describe('ColumnMenu', () => {
const menu = getByRole('menu')
menu.focus()
await user.keyboard('{ArrowDown}')

expect(menu).toBeDefined()
})

it('handles ArrowLeft key', async () => {
Expand All @@ -270,8 +262,6 @@ describe('ColumnMenu', () => {
const menu = getByRole('menu')
menu.focus()
await user.keyboard('{ArrowLeft}')

expect(menu).toBeDefined()
})

it('handles ArrowRight key', async () => {
Expand All @@ -282,8 +272,6 @@ describe('ColumnMenu', () => {
const menu = getByRole('menu')
menu.focus()
await user.keyboard('{ArrowRight}')

expect(menu).toBeDefined()
})
})

Expand All @@ -297,8 +285,6 @@ describe('ColumnMenu', () => {
const menu = getByRole('menu')
menu.focus()
await user.keyboard('{Tab}')

expect(menu).toBeDefined()
})

it('handles Shift+Tab key', async () => {
Expand All @@ -309,8 +295,6 @@ describe('ColumnMenu', () => {
const menu = getByRole('menu')
menu.focus()
await user.keyboard('{Shift>}{Tab}{/Shift}')

expect(menu).toBeDefined()
})
})

Expand All @@ -324,7 +308,6 @@ describe('ColumnMenu', () => {
menu.focus()
await user.keyboard('{Home}')
// Navigation should be handled (no specific assertion as useFocusManagement is mocked)
expect(menu).toBeDefined()
})
it('handles End key', async () => {
const { user, getByRole } = render(
Expand All @@ -334,7 +317,6 @@ describe('ColumnMenu', () => {
menu.focus()
await user.keyboard('{End}')
// Navigation should be handled (no specific assertion as useFocusManagement is mocked)
expect(menu).toBeDefined()
})
})

Expand All @@ -355,8 +337,6 @@ describe('ColumnMenu', () => {
await user.keyboard('{ArrowLeft}')
await user.keyboard('{ArrowRight}')
await user.keyboard('{Tab}')

expect(menu).toBeDefined()
})

it('handles unknown keys with default prevention', async () => {
Expand All @@ -365,8 +345,6 @@ describe('ColumnMenu', () => {
const menu = getByRole('menu')
menu.focus()
await user.keyboard('a')

expect(menu).toBeDefined()
})
})

Expand All @@ -375,7 +353,7 @@ describe('ColumnMenu', () => {
const { user, container } = render(<ColumnMenu {...defaultProps} />)

const overlay = container.querySelector('[role="presentation"]')
expect(overlay).toBeDefined()
expect(overlay).toBeTruthy()

if (overlay) {
await user.click(overlay)
Expand All @@ -389,7 +367,6 @@ describe('ColumnMenu', () => {
const { getByRole } = render(<ColumnMenu {...defaultProps} />)

const menu = getByRole('menu')
expect(menu).toBeDefined()

// Menu should not be a direct child of the render container
// since it's rendered in a portal
Expand All @@ -403,8 +380,7 @@ describe('ColumnMenu', () => {
<ColumnMenu {...defaultProps} sortable={true} />
)

const menu = getByRole('menu')
expect(menu).toBeDefined()
getByRole('menu')
})

it('handles empty column name', () => {
Expand All @@ -419,7 +395,7 @@ describe('ColumnMenu', () => {
}

const labelElement = menu.querySelector('[role=presentation]')
expect(labelElement).toBeDefined()
expect(labelElement).toBeTruthy()
expect(labelElement?.textContent).toBe('')
expect(labelElement?.getAttribute('id')).toBe(id)
})
Expand All @@ -430,7 +406,7 @@ describe('ColumnMenu', () => {
<ColumnMenu {...defaultProps} columnName={specialName} />
)

expect(getByText(specialName)).toBeDefined()
getByText(specialName)
})
})
})
6 changes: 1 addition & 5 deletions src/components/ColumnMenuButton/ColumnMenuButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('ColumnMenuButton', () => {
const { getByRole } = render(<ColumnMenuButton {...defaultProps} />)
const button = getByRole('button')

expect(button).toBeDefined()
expect(button.getAttribute('aria-label')).toBe('Column menu')
expect(button.getAttribute('aria-haspopup')).toBe('menu')
expect(button.getAttribute('aria-expanded')).toBe('false')
Expand Down Expand Up @@ -61,7 +60,7 @@ describe('ColumnMenuButton', () => {
const { getByTestId } = render(
<ColumnMenuButton {...defaultProps} icon={customIcon} />
)
expect(getByTestId('custom-icon')).toBeDefined()
getByTestId('custom-icon')
})

it('renders with default icon when no icon provided', () => {
Expand Down Expand Up @@ -200,7 +199,6 @@ describe('ColumnMenuButton', () => {
await user.keyboard('{Enter}')

// Should not throw errors
expect(button).toBeDefined()
})

it('works without onEscape handler', async () => {
Expand All @@ -213,7 +211,6 @@ describe('ColumnMenuButton', () => {
await user.keyboard('{Escape}')

// Should not throw errors
expect(button).toBeDefined()
})

it('works without any handlers', async () => {
Expand All @@ -226,7 +223,6 @@ describe('ColumnMenuButton', () => {
await user.keyboard('{Escape}')

// Should not throw errors
expect(button).toBeDefined()
})
})
})
26 changes: 11 additions & 15 deletions src/components/HighTable/HighTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('HighTable', () => {
it('renders initial rows', async () => {
const { getByText } = render(<HighTable data={mockData} />)
await waitFor(() => {
expect(getByText('ID')).toBeDefined()
getByText('ID')
expect(mockData.getCell).toHaveBeenCalledWith({ row: 0, column: 'ID', orderBy: [] })
expect(mockData.getCell).toHaveBeenCalledWith({ row: 23, column: 'Age', orderBy: [] })
expect(mockData.getCell).not.toHaveBeenCalledWith({ row: 24, column: 'Age', orderBy: [] })
Expand All @@ -110,7 +110,7 @@ describe('HighTable', () => {
it('uses overscan option', async () => {
const { getByText } = render(<HighTable data={mockData} overscan={10} />)
await waitFor(() => {
expect(getByText('ID')).toBeDefined()
getByText('ID')
expect(mockData.getCell).toHaveBeenCalledWith({ row: 13, column: 'Age', orderBy: [] })
expect(mockData.getCell).not.toHaveBeenCalledWith({ row: 14, column: 'Age', orderBy: [] })
})
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('with async data, HighTable', () => {
const asyncData = createAsyncDataFrame()
const { getByText } = render(<HighTable data={asyncData} />)
await waitFor(() => {
expect(getByText('ID')).toBeDefined()
getByText('ID')
expect(asyncData.fetch).toHaveBeenCalledExactlyOnceWith({ rowStart: 0, rowEnd, columns: ['ID', 'Name', 'Age'], orderBy: [], signal: expect.any(AbortSignal) })
expect(asyncData.getCell).toHaveBeenCalledWith({ row: 0, column: 'ID', orderBy: [] })
expect(asyncData.getCell).toHaveBeenCalledWith({ row: rowEnd - 1, column: 'Age', orderBy: [] })
Expand All @@ -278,7 +278,7 @@ describe('with async data, HighTable', () => {
const asyncData = createAsyncDataFrame()
const { getByText } = render(<HighTable data={asyncData} overscan={overscan} />)
await waitFor(() => {
expect(getByText('ID')).toBeDefined()
getByText('ID')
expect(asyncData.fetch).toHaveBeenCalledExactlyOnceWith({ rowStart: 0, rowEnd, columns: ['ID', 'Name', 'Age'], orderBy: [], signal: expect.any(AbortSignal) })
expect(asyncData.getCell).toHaveBeenCalledWith({ row: rowEnd - 1, column: 'Age', orderBy: [] })
expect(asyncData.getCell).not.toHaveBeenCalledWith({ row: rowEnd, column: 'Age', orderBy: [] })
Expand All @@ -291,7 +291,7 @@ describe('with async data, HighTable', () => {
// initially, the cell is not there because the data is not fetched yet
expect(queryByRole('cell', { name: 'async 0' })).toBeNull()
// after some delay, the cell should be there
await expect(findByRole('cell', { name: 'async 0' })).resolves.toBeDefined()
await findByRole('cell', { name: 'async 0' })
})

it('handles scroll to load more rows', async () => {
Expand All @@ -302,7 +302,7 @@ describe('with async data, HighTable', () => {
expect(asyncData.getCell).toHaveBeenCalledWith({ row: 23, column: 'Age', orderBy: [] })
expect(asyncData.getCell).not.toHaveBeenCalledWith({ row: 24, column: 'Age', orderBy: [] })
})
await expect(findByRole('cell', { name: 'async 0' })).resolves.toBeDefined()
await findByRole('cell', { name: 'async 0' })
expect(queryByRole('cell', { name: 'async 24' })).toBeNull()

act(() => {
Expand All @@ -314,7 +314,7 @@ describe('with async data, HighTable', () => {
await waitFor(() => {
expect(asyncData.getCell).toHaveBeenCalledWith({ row: 24, column: 'Age', orderBy: [] })
})
await expect(findByRole('cell', { name: 'async 24' })).resolves.toBeDefined()
await findByRole('cell', { name: 'async 24' })
expect(queryByRole('cell', { name: 'async 50' })).toBeNull()

act(() => {
Expand All @@ -325,7 +325,7 @@ describe('with async data, HighTable', () => {
await waitFor(() => {
expect(asyncData.getCell).toHaveBeenCalledWith({ row: 50, column: 'Age', orderBy: [] })
})
await expect(findByRole('cell', { name: 'async 50' })).resolves.toBeDefined()
await findByRole('cell', { name: 'async 50' })

expect(asyncData._forTests.signalAborted).toHaveLength(0) // the fetches are too fast to be cancelled (10ms)
})
Expand Down Expand Up @@ -408,13 +408,11 @@ describe('When sorted, HighTable', () => {
})

function checkRowContents(row: HTMLElement | undefined, rowNumber: string, ID: string, Count: string) {
expect(row).toBeDefined()
if (!row) {
throw new Error('Row is undefined')
}

const selectionCell = within(row).getByRole('rowheader')
expect(selectionCell).toBeDefined()
expect(selectionCell.textContent).toBe(rowNumber)

const columns = within(row).getAllByRole('cell')
Expand All @@ -426,7 +424,7 @@ describe('When sorted, HighTable', () => {
it('shows the rows in the right order', async () => {
const { user, findByRole, getByRole, findAllByRole } = render(<HighTable data={sortableDataFrame(data)} />)

expect(getByRole('columnheader', { name: 'ID' })).toBeDefined()
getByRole('columnheader', { name: 'ID' })
await findByRole('cell', { name: 'row 0' })

const table = getByRole('grid') // not table! because the table is interactive. See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/grid_role
Expand Down Expand Up @@ -1170,8 +1168,8 @@ describe('Navigating Hightable with the keyboard', () => {
const focusedElement = document.activeElement
const rowIndex = focusedElement?.getAttribute('aria-rowindex')
const colIndex = focusedElement?.getAttribute('aria-colindex')
expect(rowIndex).toBeDefined()
expect(colIndex).toBeDefined()
expect(rowIndex).toBeTruthy()
expect(colIndex).toBeTruthy()
return { rowIndex: Number(rowIndex), colIndex: Number(colIndex) }
}

Expand Down Expand Up @@ -1427,8 +1425,6 @@ describe('When the table scroller is focused', () => {
// <HighTable data={smallData} />
// </ErrorBoundary>
// )

// expect(getByRole('alert'), 'Something went wrong').toBeDefined()
// })
// })

Expand Down
7 changes: 3 additions & 4 deletions src/components/TableHeader/TableHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('TableHeader', () => {
/>
</tr></thead></table>)
columnsParameters.forEach(descriptor => {
expect(getByText(descriptor.name)).toBeDefined()
getByText(descriptor.name)
})
})

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('TableHeader', () => {

// Test integration: menu is properly labeled by column name
const labelId = menu.getAttribute('aria-labelledby')
expect(labelId).toBeDefined()
expect(labelId).toBeTruthy()
if (!labelId) throw new Error('labelId should be defined')
const label = document.getElementById(labelId)
if (!label) throw new Error('label element should exist')
Expand Down Expand Up @@ -177,10 +177,9 @@ describe('TableHeader', () => {
})

await user.click(menuButton)
const menu = getByRole('menu')
getByRole('menu')

// Test integration: menu opens within table and can be closed
expect(menu).toBeDefined()
await user.click(menuButton)
expect(queryByRole('menu')).toBeNull()
})
Expand Down