diff --git a/src/__tests__/components/Navbar.test.tsx b/src/__tests__/components/Navbar.test.tsx index feee51b62a..775dd11e95 100644 --- a/src/__tests__/components/Navbar.test.tsx +++ b/src/__tests__/components/Navbar.test.tsx @@ -85,6 +85,36 @@ describe('Navbar', () => { }) }) + describe('labs', () => { + const labsLinkList = hospitalRunNavbar.find('.labs-link-list') + + it('should render a labs dropdown', () => { + expect(labsLinkList.first().props().title).toEqual('labs.label') + expect(labsLinkList.first().props().children[0].props.children).toEqual('labs.label') + expect(labsLinkList.first().props().children[1].props.children).toEqual('labs.requests.new') + }) + + it('should navigate to to /labs when the labs list option is selected', () => { + act(() => { + labsLinkList + .first() + .props() + .children[0].props.onClick() + }) + expect(history.location.pathname).toEqual('/labs') + }) + + it('should navigate to /labs/new when the new labs list option is selected', () => { + act(() => { + labsLinkList + .first() + .props() + .children[1].props.onClick() + }) + expect(history.location.pathname).toEqual('/labs/new') + }) + }) + describe('search', () => { const navSearch = hospitalRunNavbar.find('.nav-search') diff --git a/src/__tests__/components/Sidebar.test.tsx b/src/__tests__/components/Sidebar.test.tsx index f02ae96ac9..afb593fb67 100644 --- a/src/__tests__/components/Sidebar.test.tsx +++ b/src/__tests__/components/Sidebar.test.tsx @@ -29,13 +29,18 @@ describe('Sidebar', () => { ) } - describe('dashboard link', () => { + describe('dashboard links', () => { it('should render the dashboard link', () => { const wrapper = setup('/') const listItems = wrapper.find(ListItem) - expect(listItems.at(1).text().trim()).toEqual('dashboard.label') + expect( + listItems + .at(1) + .text() + .trim(), + ).toEqual('dashboard.label') }) it('should be active when the current path is /', () => { @@ -60,16 +65,47 @@ describe('Sidebar', () => { }) }) - describe('patients link', () => { - it('should render the dashboard link', () => { + describe('patients links', () => { + it('should render the patients main link', () => { const wrapper = setup('/') const listItems = wrapper.find(ListItem) - expect(listItems.at(2).text().trim()).toEqual('patients.label') + expect( + listItems + .at(2) + .text() + .trim(), + ).toEqual('patients.label') }) - it('should be active when the current path is /', () => { + it('should render the new_patient link', () => { + const wrapper = setup('/patients') + + const listItems = wrapper.find(ListItem) + + expect( + listItems + .at(3) + .text() + .trim(), + ).toEqual('patients.newPatient') + }) + + it('should render the patients_list link', () => { + const wrapper = setup('/patients') + + const listItems = wrapper.find(ListItem) + + expect( + listItems + .at(4) + .text() + .trim(), + ).toEqual('patients.patientsList') + }) + + it('main patients link should be active when the current path is /patients', () => { const wrapper = setup('/patients') const listItems = wrapper.find(ListItem) @@ -77,7 +113,7 @@ describe('Sidebar', () => { expect(listItems.at(2).prop('active')).toBeTruthy() }) - it('should navigate to /patients when the patients link is clicked', () => { + it('should navigate to /patients when the patients main link is clicked', () => { const wrapper = setup('/') const listItems = wrapper.find(ListItem) @@ -89,18 +125,29 @@ describe('Sidebar', () => { expect(history.location.pathname).toEqual('/patients') }) - }) - describe('patients_list link', () => { - it('should render the patients_list link', () => { + it('new patient should be active when the current path is /patients/new', () => { + const wrapper = setup('/patients/new') + + const listItems = wrapper.find(ListItem) + + expect(listItems.at(3).prop('active')).toBeTruthy() + }) + + it('should navigate to /patients/new when the patients new link is clicked', () => { const wrapper = setup('/patients') const listItems = wrapper.find(ListItem) - expect(listItems.at(4).text().trim()).toEqual('patients.patientsList') + act(() => { + const onClick = listItems.at(3).prop('onClick') as any + onClick() + }) + + expect(history.location.pathname).toEqual('/patients/new') }) - it('should be active when the current path is /patients', () => { + it('patients list link should be active when the current path is /patients', () => { const wrapper = setup('/patients') const listItems = wrapper.find(ListItem) @@ -108,7 +155,7 @@ describe('Sidebar', () => { expect(listItems.at(4).prop('active')).toBeTruthy() }) - it('should navigate to /patients when the patients link is clicked', () => { + it('should navigate to /patients when the patients list link is clicked', () => { const wrapper = setup('/patients') const listItems = wrapper.find(ListItem) @@ -122,46 +169,47 @@ describe('Sidebar', () => { }) }) - describe('new_patient link', () => { - it('should render the new_patient link', () => { - const wrapper = setup('/patients') - - const listItems = wrapper.find(ListItem) - - expect(listItems.at(3).text().trim()).toEqual('patients.newPatient') - }) - - it('should be active when the current path is /patients/new', () => { - const wrapper = setup('/patients/new') + describe('appointments link', () => { + it('should render the scheduling link', () => { + const wrapper = setup('/appointments') const listItems = wrapper.find(ListItem) - expect(listItems.at(3).prop('active')).toBeTruthy() + expect( + listItems + .at(3) + .text() + .trim(), + ).toEqual('scheduling.label') }) - it('should navigate to /patients/new when the patients link is clicked', () => { - const wrapper = setup('/patients') + it('should render the new appointment link', () => { + const wrapper = setup('/appointments/new') const listItems = wrapper.find(ListItem) - act(() => { - ;(listItems.at(3).prop('onClick') as any)() - }) - - expect(history.location.pathname).toEqual('/patients/new') + expect( + listItems + .at(4) + .text() + .trim(), + ).toEqual('scheduling.appointments.new') }) - }) - describe('appointments link', () => { - it('should render the scheduling link', () => { + it('should render the appointments schedule link', () => { const wrapper = setup('/appointments') const listItems = wrapper.find(ListItem) - expect(listItems.at(3).text().trim()).toEqual('scheduling.label') + expect( + listItems + .at(5) + .text() + .trim(), + ).toEqual('scheduling.appointments.schedule') }) - it('should be active when the current path is /appointments', () => { + it('main scheduling link should be active when the current path is /appointments', () => { const wrapper = setup('/appointments') const listItems = wrapper.find(ListItem) @@ -169,7 +217,7 @@ describe('Sidebar', () => { expect(listItems.at(3).prop('active')).toBeTruthy() }) - it('should navigate to /appointments when the scheduling link is clicked', () => { + it('should navigate to /appointments when the main scheduling link is clicked', () => { const wrapper = setup('/') const listItems = wrapper.find(ListItem) @@ -181,18 +229,29 @@ describe('Sidebar', () => { expect(history.location.pathname).toEqual('/appointments') }) - }) - describe('appointment_schedule link', () => { - it('should render the appointment_schedule link', () => { + it('new appointment link should be active when the current path is /appointments/new', () => { + const wrapper = setup('/appointments/new') + + const listItems = wrapper.find(ListItem) + + expect(listItems.at(4).prop('active')).toBeTruthy() + }) + + it('should navigate to /appointments/new when the new appointment link is clicked', () => { const wrapper = setup('/appointments') const listItems = wrapper.find(ListItem) - expect(listItems.at(5).text().trim()).toEqual('scheduling.appointments.schedule') + act(() => { + const onClick = listItems.at(4).prop('onClick') as any + onClick() + }) + + expect(history.location.pathname).toEqual('/appointments/new') }) - it('should be active when the current path is /appointments', () => { + it('appointments schedule link should be active when the current path is /appointments', () => { const wrapper = setup('/appointments') const listItems = wrapper.find(ListItem) @@ -200,7 +259,7 @@ describe('Sidebar', () => { expect(listItems.at(5).prop('active')).toBeTruthy() }) - it('should navigate to /appointments when the appointments_schedule link is clicked', () => { + it('should navigate to /appointments when the appointments schedule link is clicked', () => { const wrapper = setup('/appointments') const listItems = wrapper.find(ListItem) @@ -214,25 +273,56 @@ describe('Sidebar', () => { }) }) - describe('new_appointment link', () => { - it('should render the new_appointment link', () => { - const wrapper = setup('/appointments/new') + describe('labs links', () => { + it('should render the main labs link', () => { + const wrapper = setup('/labs') const listItems = wrapper.find(ListItem) - expect(listItems.at(4).text().trim()).toEqual('scheduling.appointments.new') + expect( + listItems + .at(4) + .text() + .trim(), + ).toEqual('labs.label') }) - it('should be active when the current path is /appointments/new', () => { - const wrapper = setup('/appointments/new') + it('should render the new labs request link', () => { + const wrapper = setup('/labs') + + const listItems = wrapper.find(ListItem) + + expect( + listItems + .at(5) + .text() + .trim(), + ).toEqual('labs.requests.new') + }) + + it('should render the labs list link', () => { + const wrapper = setup('/labs') + + const listItems = wrapper.find(ListItem) + + expect( + listItems + .at(6) + .text() + .trim(), + ).toEqual('labs.requests.label') + }) + + it('main labs link should be active when the current path is /labs', () => { + const wrapper = setup('/labs') const listItems = wrapper.find(ListItem) expect(listItems.at(4).prop('active')).toBeTruthy() }) - it('should navigate to /appointments/new when the new_appointment link is clicked', () => { - const wrapper = setup('/appointments') + it('should navigate to /labs when the main lab link is clicked', () => { + const wrapper = setup('/') const listItems = wrapper.find(ListItem) @@ -241,7 +331,49 @@ describe('Sidebar', () => { onClick() }) - expect(history.location.pathname).toEqual('/appointments/new') + expect(history.location.pathname).toEqual('/labs') + }) + + it('new lab request link should be active when the current path is /labs/new', () => { + const wrapper = setup('/labs/new') + + const listItems = wrapper.find(ListItem) + + expect(listItems.at(5).prop('active')).toBeTruthy() + }) + + it('should navigate to /labs/new when the new labs link is clicked', () => { + const wrapper = setup('/labs') + + const listItems = wrapper.find(ListItem) + + act(() => { + const onClick = listItems.at(5).prop('onClick') as any + onClick() + }) + + expect(history.location.pathname).toEqual('/labs/new') + }) + + it('labs list link should be active when the current path is /labs', () => { + const wrapper = setup('/labs') + + const listItems = wrapper.find(ListItem) + + expect(listItems.at(6).prop('active')).toBeTruthy() + }) + + it('should navigate to /labs when the labs list link is clicked', () => { + const wrapper = setup('/labs/new') + + const listItems = wrapper.find(ListItem) + + act(() => { + const onClick = listItems.at(6).prop('onClick') as any + onClick() + }) + + expect(history.location.pathname).toEqual('/labs') }) }) }) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index c935d88273..fe90ff8df7 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -73,7 +73,7 @@ const Navbar = () => { { type: 'link-list', label: t('labs.label'), - className: 'labs-link-list', + className: 'labs-link-list d-md-none d-block', children: [ { type: 'link', diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index fb08421f20..d4ed204d4f 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -37,6 +37,8 @@ const Sidebar = () => { ? 'patient' : splittedPath[1].includes('appointments') ? 'appointment' + : splittedPath[1].includes('labs') + ? 'labs' : 'none', ) @@ -71,107 +73,186 @@ const Sidebar = () => { : 'black', } - return ( -