From 4872301eea5e51dc1d7a490e4a20ba94fa3857b6 Mon Sep 17 00:00:00 2001 From: Riya Kumari Date: Mon, 18 Sep 2023 10:46:42 +0530 Subject: [PATCH] GOK-319 | Refactor. Allow user to select only one test at a time | [Sweety/Riya] --- .../patient-lab-details.test.tsx | 58 +++++++++++++++---- .../pending-lab-orders.test.tsx | 56 ------------------ .../pending-lab-orders/pending-lab-orders.tsx | 29 ++-------- 3 files changed, 51 insertions(+), 92 deletions(-) diff --git a/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx b/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx index 9b0cc4f..f4a9cd2 100644 --- a/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx +++ b/src/patient-lab-dashboard/patient-lab-details/patient-lab-details.test.tsx @@ -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,10 +268,9 @@ 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( @@ -284,21 +278,63 @@ describe('Patient lab details', () => { ).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( + new Map()}}> + + + + + + + + , + ) + + 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 diff --git a/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx b/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx index fd2a2bd..66a50d1 100644 --- a/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx +++ b/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.test.tsx @@ -62,7 +62,6 @@ describe('Paginated Table', () => { patientUuid={mockPatientUuid} onButtonClick={false} onEnterResultButtonClick={false} - /> @@ -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( - new Map()}}> - - - - - - , - ) - - 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) diff --git a/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.tsx b/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.tsx index 8c2c0c2..3301257 100644 --- a/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.tsx +++ b/src/patient-lab-dashboard/table/pending-lab-orders/pending-lab-orders.tsx @@ -119,19 +119,7 @@ const PendingLabOrdersTable = ({ - { - if (selectedPendingOrder.length > 0 && !selectAll) { - setSelectAll(false) - setSelectedPendingOrder([]) - } else { - setSelectAll(!selectAll) - } - }} - disabled={onButtonClick || onEnterResultButtonClick} - checked={selectAll} - /> + {headers.map(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 ) } }