From fa758973f7545703ec625f10b24981b3e4b9e18e Mon Sep 17 00:00:00 2001 From: Juhana Jauhiainen Date: Wed, 30 Dec 2020 00:55:08 +0200 Subject: [PATCH 1/2] Started converting NotesTab.test.tsx --- .../patients/notes/NotesTab.test.tsx | 75 ++++++++++--------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/src/__tests__/patients/notes/NotesTab.test.tsx b/src/__tests__/patients/notes/NotesTab.test.tsx index 76ff3cc278..f6227067da 100644 --- a/src/__tests__/patients/notes/NotesTab.test.tsx +++ b/src/__tests__/patients/notes/NotesTab.test.tsx @@ -1,7 +1,7 @@ /* eslint-disable no-console */ -import * as components from '@hospitalrun/components' -import { mount } from 'enzyme' +import { screen, render } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import { createMemoryHistory } from 'history' import assign from 'lodash/assign' import React from 'react' @@ -43,18 +43,13 @@ const setup = (props: any = {}) => { user = { permissions } store = mockStore({ patient, user } as any) history.push(route) - let wrapper: any - act(() => { - wrapper = mount( - - - - - , - ) - }) - - return wrapper + return render( + + + + + , + ) } describe('Notes Tab', () => { @@ -65,39 +60,51 @@ describe('Notes Tab', () => { }) it('should render a add notes button', () => { - const wrapper = setup() + setup() - const addNoteButton = wrapper.find(components.Button) - expect(addNoteButton).toHaveLength(1) - expect(addNoteButton.text().trim()).toEqual('patient.notes.new') + expect(screen.getByRole('button', { name: /patient\.notes\.new/i })).toBeInTheDocument() + // const addNoteButton = wrapper.find(components.Button) + // expect(addNoteButton).toHaveLength(1) + // expect(addNoteButton.text().trim()).toEqual('patient.notes.new') }) it('should not render a add notes button if the user does not have permissions', () => { - const wrapper = setup({ permissions: [] }) + setup({ permissions: [] }) - const addNotesButton = wrapper.find(components.Button) - expect(addNotesButton).toHaveLength(0) + expect(screen.queryByRole('button', { name: /patient\.notes\.new/i })).not.toBeInTheDocument() + // const addNotesButton = wrapper.find(components.Button) + // expect(addNotesButton).toHaveLength(0) }) it('should open the Add Notes Modal', () => { - const wrapper = setup() - act(() => { - const onClick = wrapper.find(components.Button).prop('onClick') as any - onClick() - }) - wrapper.update() - - expect(wrapper.find(components.Modal).prop('show')).toBeTruthy() + setup() + + expect(screen.queryByRole('dialog')).not.toBeInTheDocument() + + const addButton = screen.getByRole('button', { name: /patient\.notes\.new/i }) + userEvent.click(addButton) + + expect(screen.getByRole('dialog')).toBeInTheDocument() + // screen.logTestingPlaygroundURL() + // act(() => { + // const onClick = wrapper.find(components.Button).prop('onClick') as any + // onClick() + // }) + // wrapper.update() + + // expect(wrapper.find(components.Modal).prop('show')).toBeTruthy() }) }) describe('/patients/:id/notes', () => { - it('should render the view notes screen when /patients/:id/notes is accessed', () => { + it('should render the view notes screen when /patients/:id/notes is accessed', async () => { const route = '/patients/123/notes' const permissions = [Permissions.WritePatients] - const wrapper = setup({ route, permissions }) - act(() => { - expect(wrapper.exists(NoteTab)).toBeTruthy() - }) + setup({ route, permissions }) + + // await screen.findByText('asd') + // act(() => { + // expect(wrapper.exists(NoteTab)).toBeTruthy() + // }) }) }) }) From 4b96df4b81d161ba3e0e1d609d92a2f609a04f87 Mon Sep 17 00:00:00 2001 From: Juhana Jauhiainen Date: Wed, 30 Dec 2020 14:57:30 +0200 Subject: [PATCH 2/2] Convert last test from NotesTab.test.tsx --- .../patients/notes/NotesTab.test.tsx | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/__tests__/patients/notes/NotesTab.test.tsx b/src/__tests__/patients/notes/NotesTab.test.tsx index f6227067da..0d9c46eaa2 100644 --- a/src/__tests__/patients/notes/NotesTab.test.tsx +++ b/src/__tests__/patients/notes/NotesTab.test.tsx @@ -5,7 +5,6 @@ import userEvent from '@testing-library/user-event' import { createMemoryHistory } from 'history' import assign from 'lodash/assign' import React from 'react' -import { act } from 'react-dom/test-utils' import { Provider } from 'react-redux' import { Router } from 'react-router-dom' import createMockStore from 'redux-mock-store' @@ -63,17 +62,12 @@ describe('Notes Tab', () => { setup() expect(screen.getByRole('button', { name: /patient\.notes\.new/i })).toBeInTheDocument() - // const addNoteButton = wrapper.find(components.Button) - // expect(addNoteButton).toHaveLength(1) - // expect(addNoteButton.text().trim()).toEqual('patient.notes.new') }) it('should not render a add notes button if the user does not have permissions', () => { setup({ permissions: [] }) expect(screen.queryByRole('button', { name: /patient\.notes\.new/i })).not.toBeInTheDocument() - // const addNotesButton = wrapper.find(components.Button) - // expect(addNotesButton).toHaveLength(0) }) it('should open the Add Notes Modal', () => { @@ -85,26 +79,15 @@ describe('Notes Tab', () => { userEvent.click(addButton) expect(screen.getByRole('dialog')).toBeInTheDocument() - // screen.logTestingPlaygroundURL() - // act(() => { - // const onClick = wrapper.find(components.Button).prop('onClick') as any - // onClick() - // }) - // wrapper.update() - - // expect(wrapper.find(components.Modal).prop('show')).toBeTruthy() }) }) describe('/patients/:id/notes', () => { - it('should render the view notes screen when /patients/:id/notes is accessed', async () => { + it('should render the view notes screen when /patients/:id/notes is accessed', () => { const route = '/patients/123/notes' const permissions = [Permissions.WritePatients] setup({ route, permissions }) - // await screen.findByText('asd') - // act(() => { - // expect(wrapper.exists(NoteTab)).toBeTruthy() - // }) + expect(screen.getByText(/patient\.notes\.new/i)).toBeInTheDocument() }) }) })