From 4a3b43571d2bc89417c7932920b2846c0d7e70c6 Mon Sep 17 00:00:00 2001 From: tigerabrodi Date: Wed, 23 Dec 2020 21:14:43 +0100 Subject: [PATCH] test(view-note): convert to rtl --- .../patients/notes/ViewNote.test.tsx | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/__tests__/patients/notes/ViewNote.test.tsx b/src/__tests__/patients/notes/ViewNote.test.tsx index 74172470c7..fe164a776a 100644 --- a/src/__tests__/patients/notes/ViewNote.test.tsx +++ b/src/__tests__/patients/notes/ViewNote.test.tsx @@ -1,11 +1,9 @@ -import { mount, ReactWrapper } from 'enzyme' +import { render, screen } from '@testing-library/react' import { createMemoryHistory } from 'history' import React from 'react' -import { act } from 'react-dom/test-utils' import { Route, Router } from 'react-router-dom' import ViewNote from '../../../patients/notes/ViewNote' -import TextInputWithLabelFormGroup from '../../../shared/components/input/TextInputWithLabelFormGroup' import PatientRepository from '../../../shared/db/PatientRepository' import Patient from '../../../shared/model/Patient' @@ -15,32 +13,21 @@ describe('View Note', () => { notes: [{ id: '123', text: 'some name', date: '1947-09-09T14:48:00.000Z' }], } as Patient - const setup = async () => { + it('should render a note input with the correct data', async () => { jest.spyOn(PatientRepository, 'find').mockResolvedValue(patient) - const history = createMemoryHistory() - history.push(`/patients/${patient.id}/notes/${patient.notes![0].id}`) - let wrapper: any - - await act(async () => { - wrapper = await mount( - - - - - , - ) + const history = createMemoryHistory({ + initialEntries: [`/patients/${patient.id}/notes/${patient.notes![0].id}`], }) - wrapper.update() - - return { wrapper: wrapper as ReactWrapper } - } - - it('should render a note input with the correct data', async () => { - const { wrapper } = await setup() + render( + + + + + , + ) - const noteText = wrapper.find(TextInputWithLabelFormGroup) - expect(noteText).toHaveLength(1) - expect(noteText.prop('value')).toEqual(patient.notes![0].text) + const input = await screen.findByLabelText(/patient.note/i) + expect(input).toHaveValue(patient.notes![0].text) }) })