From af0102175f1f7dc90482eb680cbeb69975c4ef9c Mon Sep 17 00:00:00 2001 From: Emma Slight Date: Thu, 24 Dec 2020 13:04:41 +1300 Subject: [PATCH] test(viewmedication.test.tsx): update cancelled on test to RTL #55 --- .../medications/ViewMedication.test.tsx | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/__tests__/medications/ViewMedication.test.tsx b/src/__tests__/medications/ViewMedication.test.tsx index 8aa86ec4f2..957d7e4f16 100644 --- a/src/__tests__/medications/ViewMedication.test.tsx +++ b/src/__tests__/medications/ViewMedication.test.tsx @@ -242,30 +242,26 @@ describe('View Medication', () => { }) }) }) - /* - describe.skip('on cancel', () => { + + describe('on cancel', () => { it('should mark the status as canceled and fill in the cancelled on date with the current time', async () => { - const { wrapper, expectedMedication, medicationRepositorySaveSpy, history } = await setup( - {}, - [Permissions.ViewMedication, Permissions.CompleteMedication, Permissions.CancelMedication], - ) - - const cancelButton = wrapper.find(Button).at(1) - await act(async () => { - const onClick = cancelButton.prop('onClick') - await onClick() - }) - wrapper.update() + const expectedMedication = { ...mockMedication } as Medication + setup(expectedMedication, [ + Permissions.ViewMedication, + Permissions.CompleteMedication, + Permissions.CancelMedication, + ]) - expect(medicationRepositorySaveSpy).toHaveBeenCalled() - expect(medicationRepositorySaveSpy).toHaveBeenCalledWith( - expect.objectContaining({ - ...expectedMedication, - status: 'canceled', - canceledOn: expectedDate.toISOString(), - }), - ) - expect(history.location.pathname).toEqual('/medications') + const cancelButton = screen.getByRole('button', { name: /medications\.requests\.cancel/ }) + + userEvent.click(cancelButton) + + expect(MedicationRepository.saveOrUpdate).toHaveBeenCalled() + expect(MedicationRepository.saveOrUpdate).toHaveBeenCalledWith({ + ...expectedMedication, + status: 'canceled', + canceledOn: expectedDate.toISOString(), + }) }) - }) */ + }) })