Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87f553321b |
@@ -82,8 +82,8 @@ export function IncidentTable({ incidents, basePath, total, counts, params, site
|
||||
|
||||
const clearable = Boolean(params.q || params.status || params.type || params.siteId || params.truckId)
|
||||
const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE))
|
||||
const from = total === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1
|
||||
const to = Math.min(total, from + incidents.length - 1)
|
||||
const from = incidents.length === 0 ? 0 : (params.page - 1) * PAGE_SIZE + 1
|
||||
const to = incidents.length === 0 ? 0 : from + incidents.length - 1
|
||||
|
||||
const toolbar = (
|
||||
<>
|
||||
@@ -161,7 +161,7 @@ export function IncidentTable({ incidents, basePath, total, counts, params, site
|
||||
const next = nextSort({ key: params.sort, dir: params.dir }, key as SortKey)
|
||||
update({ sort: next.key, dir: next.dir })
|
||||
}}
|
||||
footer={{ from, to, total, page: params.page, pageCount, onPage: p => update({ page: String(p) }) }}
|
||||
footer={total > 0 ? { from, to, total, page: params.page, pageCount, onPage: p => update({ page: String(p) }) } : undefined}
|
||||
empty={{
|
||||
title: 'No incidents found',
|
||||
action: <Button onClick={() => router.push('/report')}>Report incident</Button>,
|
||||
|
||||
@@ -93,6 +93,21 @@ describe('IncidentTable', () => {
|
||||
expect(replace).toHaveBeenCalledWith('/hse/incidents?page=2')
|
||||
})
|
||||
|
||||
it('hides the footer when there are no results', () => {
|
||||
render(<IncidentTable {...props} incidents={[]} total={0} counts={{ all: 0, open: 0, closed: 0 }} />)
|
||||
expect(screen.queryByText(/Showing/)).toBeNull()
|
||||
})
|
||||
|
||||
it('shows a sane range on a page past the end', () => {
|
||||
render(<IncidentTable {...props} incidents={[]} total={7} params={{ ...props.params, page: 2 }} />)
|
||||
expect(screen.getByText('Showing 0–0 of 7')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('shows the range for a partial last page', () => {
|
||||
render(<IncidentTable {...props} total={27} params={{ ...props.params, page: 2 }} />)
|
||||
expect(screen.getByText('Showing 26–27 of 27')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders the stacked mobile list', () => {
|
||||
const { container } = render(<IncidentTable {...props} />)
|
||||
expect(container.querySelector('ul.md\\:hidden')).not.toBeNull()
|
||||
|
||||
Reference in New Issue
Block a user