Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to select one lab test at a time #13

Merged
merged 1 commit into from
Sep 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('Patient lab details', () => {
expect(screen.getByLabelText(/overlay/i)).toBeInTheDocument()
})

it('should pre-populate the selected tests in upload report and makes pending lab order table read only', async () => {
it('should pre-populate the selected test in upload report and makes pending lab order table read only', async () => {
const mockedOpenmrsFetch = openmrsFetch as jest.Mock
mockedOpenmrsFetch
.mockReturnValueOnce(mockPendingLabOrdersResponse)
Expand Down Expand Up @@ -258,13 +258,8 @@ describe('Patient lab details', () => {
expect(
screen.getByRole('cell', {name: 'Routine Blood'}),
).toBeInTheDocument()
expect(
screen.getByRole('cell', {name: 'Anaemia Panel'}),
).toBeInTheDocument()

userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[0])
userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[1])

userEvent.click(screen.getByRole('button', {name: /upload report/i}))

expect(
Expand All @@ -273,32 +268,73 @@ describe('Patient lab details', () => {

await waitFor(() => {
expect(screen.getByTestId(/selected-tests/i)).toHaveTextContent(
'Selected Tests ( 2 )',
'Selected Tests ( 1 )',
)
})

expect(screen.queryByText(/absolute eosinphil count/i)).toBeInTheDocument()

expect(
screen.getAllByRole('checkbox', {name: /Select Row/i})[0],
).toBeDisabled()

userEvent.click(screen.getByRole('button', {name: /close-icon/i}))

expect(
screen.getAllByRole('checkbox', {name: /Select Row/i})[0],
screen.getAllByRole('checkbox', {name: /Select Row/i})[1],
).toBeEnabled()

userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[0])

userEvent.click(screen.getByRole('button', {name: /upload report/i}))

await waitFor(() => {
expect(screen.getByTestId(/selected-tests/i)).toHaveTextContent(
'Selected Tests ( 1 )',
'Selected Tests ( 0 )',
)
})
})

it('should select one test at a time', async () => {
const mockedOpenmrsFetch = openmrsFetch as jest.Mock
mockedOpenmrsFetch.mockReturnValueOnce(mockPendingLabOrdersResponse)

render(
<SWRConfig value={{provider: () => new Map()}}>
<BrowserRouter>
<LabTestResultsProvider>
<PendingLabOrdersProvider>
<PatientLabDetails
match={matchParams}
history={undefined}
location={undefined}
/>
</PendingLabOrdersProvider>
</LabTestResultsProvider>
</BrowserRouter>
</SWRConfig>,
)

await waitFor(() => {
expect(screen.getByText(/Pending lab orders/i)).toBeInTheDocument()
})

expect(
screen.getByRole('cell', {name: 'Routine Blood'}),
).toBeInTheDocument()
expect(
screen.getByRole('cell', {name: 'Anaemia Panel'}),
).toBeInTheDocument()

userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[0])
userEvent.click(screen.getAllByRole('checkbox', {name: /Select row/i})[1])

expect(
screen.getAllByRole('checkbox', {name: /select row/i})[0],
).not.toBeChecked()
expect(
screen.getAllByRole('checkbox', {name: /select row/i})[1],
).toBeChecked()
})

it('should show success notification on report upload', async () => {
const mockedOpenmrsFetch = openmrsFetch as jest.Mock
mockedOpenmrsFetch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ describe('Paginated Table', () => {
expect(
screen.getByRole('cell', {name: 'Routine Blood'}),
).toBeInTheDocument()
expect(screen.getByRole('cell', {name: 'Test Orderer'})).toBeInTheDocument()
screen.getByRole('checkbox', {
name: /select all rows/i,
})
expect(
screen.getAllByRole('checkbox', {
name: /select all rows/i,
}).length,
).toEqual(1)
expect(
screen.getAllByRole('checkbox', {
name: /select row/i,
Expand Down Expand Up @@ -119,53 +110,7 @@ describe('Paginated Table', () => {
),
).not.toBeInTheDocument()
})
it('should able to select all tests in pending orders when select all check box is checked', async () => {
const mockedOpenmrsFetch = openmrsFetch as jest.Mock
mockedOpenmrsFetch.mockReturnValue(mockPendingLabOrdersResponse)
when(usePagination)
.calledWith(expect.anything(), 5)
.mockReturnValue({
results: [
{
id: 'abc-123',
testName: 'Routine Blood',
date: 'April 19, 2022',
orderedBy: 'Test Orderer',
},
],
goTo: jest.fn(),
currentPage: 1,
})

render(
<SWRConfig value={{provider: () => new Map()}}>
<BrowserRouter>
<PendingLabOrdersProvider>
<PendingLabOrdersTable
reloadTableData={false}
patientUuid={mockPatientUuid}
onButtonClick={false}
onEnterResultButtonClick={false}
/>
</PendingLabOrdersProvider>
</BrowserRouter>
</SWRConfig>,
)

await waitFor(() => {
expect(screen.getByText(/Pending lab orders/i)).toBeInTheDocument()
})
expect(screen.getByTitle(/lab-order-table/i)).toBeInTheDocument()
headers.map(header => {
expect(
screen.getByRole('columnheader', {name: header.header}),
).toBeInTheDocument()
})

userEvent.click(screen.getByRole('checkbox', {name: /select all rows/i}))

expect(screen.getByRole('checkbox', {name: /select row/i})).toBeChecked()
})
it('should display error message when call for orders data is unsuccessful', async () => {
const mockedOpenmrsFetch = openmrsFetch as jest.Mock
mockedOpenmrsFetch.mockRejectedValueOnce(mockPendingLabOrdersErrorResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
} else {
setSelectedPendingOrder([])
}
}, [selectAll])

Check warning on line 102 in src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.tsx

View workflow job for this annotation

GitHub Actions / Build and Test

React Hook useEffect has missing dependencies: 'pendingLabOrderRows' and 'setSelectedPendingOrder'. Either include them or remove the dependency array

return (
<div title="paginated-table">
Expand All @@ -119,19 +119,7 @@
<Table title="lab-order-table" useZebraStyles={true}>
<TableHead>
<TableRow>
<TableSelectAll
{...getSelectionProps()}
onSelect={() => {
if (selectedPendingOrder.length > 0 && !selectAll) {
setSelectAll(false)
setSelectedPendingOrder([])
} else {
setSelectAll(!selectAll)
}
}}
disabled={onButtonClick || onEnterResultButtonClick}
checked={selectAll}
/>
<TableHeader></TableHeader>
abinaya-u marked this conversation as resolved.
Show resolved Hide resolved
{headers.map(header => (
<TableHeader {...getHeaderProps({header})}>
{header.header}
Expand All @@ -149,16 +137,9 @@
intialRow => intialRow.id === row.id,
)[0]
if (selected) {
setSelectedPendingOrder(prev => [
...prev,
currentRow,
])
setSelectedPendingOrder([currentRow])
} else {
setSelectedPendingOrder(
selectedPendingOrder.filter(
tempRow => tempRow.id !== currentRow.id,
),
)
setSelectedPendingOrder([])
}
}}
disabled={onButtonClick || onEnterResultButtonClick}
Expand Down Expand Up @@ -190,9 +171,7 @@

function isChecked(row: TableSelectRowProps): boolean {
return (
selectedPendingOrder.filter(
pendingOrderRow => pendingOrderRow.id === row.id,
).length === 1
selectedPendingOrder.length === 1 && selectedPendingOrder[0].id === row.id
)
}
}
Expand Down
Loading