From 0225099c4d6b4cee8f3c21a3ca09366750523288 Mon Sep 17 00:00:00 2001 From: Rachel Dauns Date: Wed, 1 May 2024 09:56:19 -0400 Subject: [PATCH] enzyme removed from modal.js --- .../common/components/modal/modal.test.js | 82 +++++++++---------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/packages/app/obojobo-document-engine/__tests__/common/components/modal/modal.test.js b/packages/app/obojobo-document-engine/__tests__/common/components/modal/modal.test.js index d24f6c456d..ea8a8445f0 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/components/modal/modal.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/components/modal/modal.test.js @@ -1,7 +1,6 @@ import Modal from '../../../../src/scripts/common/components/modal/modal' import ModalUtil from '../../../../src/scripts/common/util/modal-util' import React from 'react' -import { mount } from 'enzyme' import renderer from 'react-test-renderer' jest.mock('../../../../src/scripts/common/util/modal-util') @@ -29,7 +28,7 @@ describe('Modal', () => { }) test('Modal close button closes the modal', () => { - const component = mount( + const component = renderer.create( Content @@ -37,10 +36,9 @@ describe('Modal', () => { expect(onClose).toHaveBeenCalledTimes(0) - component - .find('DeleteButton') - .find('button') - .simulate('click') + const instance = component.root + const deleteButton = instance.findByType('button') + deleteButton.props.onClick() expect(onClose).toHaveBeenCalledTimes(1) @@ -48,7 +46,7 @@ describe('Modal', () => { }) test('Esc closes modal', () => { - const component = mount( + const component = renderer.create( Content @@ -64,7 +62,9 @@ describe('Modal', () => { }) test('Esc closes modal (even when no onClose method present)', () => { - const component = mount(Content) + const component = renderer.create( + Content + ) expect(ModalUtil.hide).toHaveBeenCalledTimes(0) @@ -76,25 +76,32 @@ describe('Modal', () => { }) test('Esc does not work if preventEsc is set', () => { - const component = mount( - + const onCloseMock = jest.fn() + const onKeyUpMock = jest.fn() + const component = renderer.create( + Content ) expect(ModalUtil.hide).toHaveBeenCalledTimes(0) - expect(onClose).toHaveBeenCalledTimes(0) + expect(onCloseMock).toHaveBeenCalledTimes(0) - document.dispatchEvent(new KeyboardEvent('keyup', { keyCode: 27 })) + component.getInstance().onKeyUp({ keyCode: 27 }) expect(ModalUtil.hide).toHaveBeenCalledTimes(0) - expect(onClose).toHaveBeenCalledTimes(0) + expect(onCloseMock).toHaveBeenCalledTimes(0) component.unmount() }) test('Modal does not close with other keys', () => { - const component = mount( + const component = renderer.create( Content @@ -110,7 +117,7 @@ describe('Modal', () => { }) test('Tab will focus on nothing if no close or first element', () => { - const component = mount( + const component = renderer.create(