diff --git a/packages/app/obojobo-document-engine/__tests__/common/chunk/text-chunk/text-group-el.test.js b/packages/app/obojobo-document-engine/__tests__/common/chunk/text-chunk/text-group-el.test.js index 789cb5e070..1bb005a1fa 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/chunk/text-chunk/text-group-el.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/chunk/text-chunk/text-group-el.test.js @@ -1,4 +1,3 @@ -import { mount } from 'enzyme' import React from 'react' import renderer from 'react-test-renderer' import TextGroupEl from '../../../../src/scripts/common/chunk/text-chunk/text-group-el' @@ -39,11 +38,24 @@ describe('TextGroupEl', () => { }) test('Renders text', () => { - const component = mount( + const component = renderer.create( ) - expect(component.text()).toBe('First line') + const tree = component.toJSON() + + const findText = node => { + if (typeof node === 'string') { + return node + } + if (Array.isArray(node.children) && node.children.length > 0) { + return findText(node.children[0]) + } + return null + } + + const textContent = findText(tree) + expect(textContent).toBe('First line') }) test('Variable replacement', () => { @@ -51,11 +63,23 @@ describe('TextGroupEl', () => { event.text = 'REPLACE(' + variable + ')' }) - const component = mount( + const component = renderer.create( ) + const tree = component.toJSON() - expect(component.text()).toBe('Some BOLD text with a REPLACE(variable) included') + const findText = node => { + if (typeof node === 'string') { + return node + } + if (Array.isArray(node.children) && node.children.length > 0) { + return node.children.map(child => findText(child)).join('') + } + return '' + } + + const textContent = findText(tree) + expect(textContent).toBe('Some BOLD text with a REPLACE(variable) included') }) test('Variable replacement with no match', () => { @@ -63,11 +87,24 @@ describe('TextGroupEl', () => { event.text = null }) - const component = mount( + const component = renderer.create( ) - expect(component.text()).toBe('Some BOLD text with a {{variable}} included') + const tree = component.toJSON() + + const findText = node => { + if (typeof node === 'string') { + return node + } + if (Array.isArray(node.children) && node.children.length > 0) { + return node.children.map(child => findText(child)).join('') + } + return '' + } + + const textContent = findText(tree) + expect(textContent).toBe('Some BOLD text with a {{variable}} included') }) test('String values of hangingIndent work as expected', () => { diff --git a/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js b/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js index e7fea9c6ba..35ae262613 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js @@ -1,7 +1,6 @@ import React from 'react' import ButtonBar from '../../../src/scripts/common/components/button-bar' import renderer from 'react-test-renderer' -import { mount } from 'enzyme' describe('ButtonBar', () => { test('ButtonBar component', () => { @@ -35,21 +34,17 @@ describe('ButtonBar', () => { } ] const mockClick = jest.fn() - const component = mount({children}) + const component = renderer.create({children}) + const buttonInstance = component.root.findByType('button') - component - .childAt(0) - .find('button') - .simulate('click') - expect(mockClick).toBeCalledTimes(1) + buttonInstance.props.onClick() + expect(mockClick).toHaveBeenCalledTimes(1) - // default function coverage for buttonBarOnClick - const componentNoClick = mount({children}) - componentNoClick - .childAt(0) - .find('button') - .simulate('click') - expect(mockClick).toBeCalledTimes(1) + const componentNoClick = renderer.create({children}) + const buttonInstanceNoClick = componentNoClick.root.findByType('button') + + buttonInstanceNoClick.props.onClick() + expect(mockClick).toHaveBeenCalledTimes(1) }) test('ButtonBar component clicks button but does not fire', () => { @@ -59,13 +54,10 @@ describe('ButtonBar', () => { } ] const mockClick = jest.fn() - const component = mount({children}) - - component - .childAt(0) - .find('button') - .simulate('click') + const component = renderer.create({children}) + const buttonInstance = component.root.findByType('button') + buttonInstance.props.onClick() expect(mockClick).toHaveBeenCalled() }) }) diff --git a/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js b/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js index 125b662712..13c51751f6 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js @@ -1,7 +1,6 @@ import React from 'react' import DeleteButton from '../../../src/scripts/common/components/delete-button' import DeleteButtonBase from '../../../src/scripts/common/components/delete-button-base' -import { mount } from 'enzyme' import renderer from 'react-test-renderer' jest.mock('../../../src/scripts/common/page/focus') @@ -44,8 +43,8 @@ describe('DeleteButton', () => { test('DeleteButton calls focus callback with ref argument', () => { const focus = require('../../../src/scripts/common/page/focus').default - const wrapper = mount() - const inst = wrapper.find(DeleteButtonBase).instance() + const component = renderer.create() + const inst = component.root.findByType(DeleteButtonBase).instance inst.focus() expect(focus).toHaveBeenCalledWith(inst.deleteButtonRef) }) 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(