Skip to content

Commit

Permalink
GOK-319 | Refactor. Allow user to select only one test at a time | [S…
Browse files Browse the repository at this point in the history
…weety/Riya]
riyaTw committed Sep 18, 2023
1 parent c8e7ce2 commit 4872301
Showing 3 changed files with 51 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -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)
@@ -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(
@@ -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
Original file line number Diff line number Diff line change
@@ -62,7 +62,6 @@ describe('Paginated Table', () => {
patientUuid={mockPatientUuid}
onButtonClick={false}
onEnterResultButtonClick={false}

/>
</PendingLabOrdersProvider>
</BrowserRouter>
@@ -84,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,
@@ -120,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)
Original file line number Diff line number Diff line change
@@ -119,19 +119,7 @@ const PendingLabOrdersTable = ({
<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>
{headers.map(header => (
<TableHeader {...getHeaderProps({header})}>
{header.header}
@@ -149,16 +137,9 @@ const PendingLabOrdersTable = ({
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}
@@ -190,9 +171,7 @@ const PendingLabOrdersTable = ({

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

0 comments on commit 4872301

Please sign in to comment.