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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

### Refactored

- updated the link to the demo in the README.
- updated the link to the demo in the README ([ef4a642](https://github.com/hyparam/hightable/commit/ef4a642c0c8dc5478abb675e200e2bab2c274518)).
- removed call to `act()` in tests where not required ([#54](https://github.com/hyparam/hightable/pull/54)).

## [0.10.0](https://github.com/hyparam/hightable/compare/v0.9.2...v0.10.0) - 2025-02-11

Expand Down
47 changes: 26 additions & 21 deletions test/HighTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ describe('HighTable', () => {


describe('When sorted, HighTable', () => {

function checkRowContents(row: HTMLElement, rowNumber: string, ID: string, Count: string) {
const selectionCell = within(row).getByRole('rowheader')
expect(selectionCell).toBeDefined()
Expand Down Expand Up @@ -281,9 +280,10 @@ describe('in controlled selection state (selection and onSelection props), ', ()

const rowHeader = cell.closest('[role="row"]')?.querySelector('[role="rowheader"]')
expect(rowHeader).not.toBeNull()
await act(async () => {
rowHeader && await user.click(rowHeader)
})

if (!rowHeader) throw new Error('rowHeader is null')
await user.click(rowHeader)

expect(onSelectionChange).toHaveBeenCalledWith({ ranges: [{ start, end: start + 1 }], anchor: start })
expect(queryByRole('row', { selected: true })).toBeNull()
})
Expand All @@ -299,9 +299,10 @@ describe('in controlled selection state (selection and onSelection props), ', ()

const rowHeader = row.querySelector('[role="rowheader"]')
expect(rowHeader).not.toBeNull()
await act(async () => {
rowHeader && await user.click(rowHeader)
})
if (!rowHeader) throw new Error('rowHeader is null')

await user.click(rowHeader)

expect(onSelectionChange).toHaveBeenCalledWith({ ranges: [], anchor: start })
})

Expand All @@ -316,11 +317,12 @@ describe('in controlled selection state (selection and onSelection props), ', ()
onSelectionChange.mockClear()
const otherRowHeader = cell.closest('[role="row"]')?.querySelector('[role="rowheader"]')
expect(otherRowHeader).not.toBeNull()
await act(async () => {
// see https://testing-library.com/docs/user-event/setup/#starting-a-session-per-setup
await user.keyboard('[ShiftLeft>]') // Press Shift (without releasing it)
otherRowHeader && await user.click(otherRowHeader) // Perform a click with `shiftKey: true`
})
if (!otherRowHeader) throw new Error('otherRowHeader is null')

// see https://testing-library.com/docs/user-event/setup/#starting-a-session-per-setup
await user.keyboard('[ShiftLeft>]') // Press Shift (without releasing it)
await user.click(otherRowHeader) // Perform a click with `shiftKey: true`

expect(onSelectionChange).toHaveBeenCalledWith({ ranges: [{ start: start, end: other + 1 }], anchor: start })
})
})
Expand Down Expand Up @@ -431,9 +433,10 @@ describe('in uncontrolled selection state (onSelection prop), ', () => {

const rowHeader = cell.closest('[role="row"]')?.querySelector('[role="rowheader"]')
expect(rowHeader).not.toBeNull()
await act(async () => {
rowHeader && await user.click(rowHeader)
})

if (!rowHeader) throw new Error('rowHeader is null')
await user.click(rowHeader)

expect(onSelectionChange).toHaveBeenCalledWith({ ranges: [{ start, end: start + 1 }], anchor: start })
expect(queryByRole('row', { selected: true })?.getAttribute('aria-rowindex')).toBe(`${start + 2}`)
})
Expand All @@ -450,9 +453,10 @@ describe('in uncontrolled selection state (onSelection prop), ', () => {
// select a row
const rowHeader = cell.closest('[role="row"]')?.querySelector('[role="rowheader"]')
expect(rowHeader).not.toBeNull()
await act(async () => {
rowHeader && await user.click(rowHeader)
})

if (!rowHeader) throw new Error('rowHeader is null')
await user.click(rowHeader)

expect(onSelectionChange).toHaveBeenCalledWith({ ranges: [{ start, end: start + 1 }], anchor: start })

rerender(<HighTable data={otherData} onSelectionChange={onSelectionChange}/>)
Expand Down Expand Up @@ -501,9 +505,10 @@ describe('in disabled selection state (neither selection nor onSelection props),

const rowHeader = cell.closest('[role="row"]')?.querySelector('[role="rowheader"]')
expect(rowHeader).not.toBeNull()
await act(async () => {
rowHeader && await user.click(rowHeader)
})
if (!rowHeader) throw new Error('rowHeader is null')

await user.click(rowHeader)

expect(queryByRole('row', { selected: true })).toBeNull()
})
})