diff --git a/tests/renderer/components/editors-toolbar-button-spec.tsx b/rtl-spec/components/editors-toolbar-button.spec.tsx similarity index 53% rename from tests/renderer/components/editors-toolbar-button-spec.tsx rename to rtl-spec/components/editors-toolbar-button.spec.tsx index 4d829de91f..9fb4bbbcef 100644 --- a/tests/renderer/components/editors-toolbar-button-spec.tsx +++ b/rtl-spec/components/editors-toolbar-button.spec.tsx @@ -1,15 +1,15 @@ -import * as React from 'react'; +import userEvent from '@testing-library/user-event'; +import { MosaicContext, MosaicWindowContext } from 'react-mosaic-component'; -import { shallow } from 'enzyme'; - -import { EditorId, MAIN_JS } from '../../../src/interfaces'; +import { EditorId, MAIN_JS } from '../../src/interfaces'; import { MaximizeButton, RemoveButton, -} from '../../../src/renderer/components/editors-toolbar-button'; -import { AppState } from '../../../src/renderer/state'; +} from '../../src/renderer/components/editors-toolbar-button'; +import { AppState } from '../../src/renderer/state'; +import { renderClassComponentWithInstanceRef } from '../test-utils/renderClassComponentWithInstanceRef'; -let mockContext: any = {}; +let mockContext = {} as MosaicWindowContext & MosaicContext; jest.mock('react-mosaic-component', () => { const { MosaicContext, MosaicRootActions, MosaicWindowContext } = @@ -52,44 +52,43 @@ describe('Editor toolbar button component', () => { describe('MaximizeButton', () => { function createMaximizeButton(id: EditorId) { - const wrapper = shallow(, { - context: mockContext, + return renderClassComponentWithInstanceRef(MaximizeButton, { + id, + appState: store, }); - const instance = wrapper.instance(); - return { instance, wrapper }; } it('renders', () => { - const { wrapper } = createMaximizeButton(MAIN_JS); - expect(wrapper).toMatchSnapshot(); + const { renderResult } = createMaximizeButton(MAIN_JS); + expect(renderResult.getByRole('button')).toBeInTheDocument(); }); - it('handles a click', () => { - const { instance, wrapper } = createMaximizeButton(MAIN_JS); - instance.context = mockContext as unknown; - wrapper.dive().dive().find('button').simulate('click'); + it('handles a click', async () => { + const { instance, renderResult } = createMaximizeButton(MAIN_JS); + instance.context = mockContext; + await userEvent.click(renderResult.getByRole('button')); expect(mockContext.mosaicActions.expand).toHaveBeenCalledTimes(1); }); }); describe('RemoveButton', () => { function createRemoveButton(id: EditorId) { - const wrapper = shallow(, { - context: mockContext, + return renderClassComponentWithInstanceRef(RemoveButton, { + id, + appState: store, }); - return { wrapper }; } it('renders', () => { - const { wrapper } = createRemoveButton(MAIN_JS); - expect(wrapper).toMatchSnapshot(); + const { renderResult } = createRemoveButton(MAIN_JS); + expect(renderResult.getByRole('button')).toBeInTheDocument(); }); - it('handles a click', () => { + it('handles a click', async () => { const { editorMosaic } = store; const hideSpy = jest.spyOn(editorMosaic, 'hide'); - const { wrapper } = createRemoveButton(MAIN_JS); - wrapper.dive().dive().find('button').simulate('click'); + const { renderResult } = createRemoveButton(MAIN_JS); + await userEvent.click(renderResult.getByRole('button')); expect(hideSpy).toHaveBeenCalledTimes(1); }); }); diff --git a/tests/renderer/components/__snapshots__/editors-toolbar-button-spec.tsx.snap b/tests/renderer/components/__snapshots__/editors-toolbar-button-spec.tsx.snap deleted file mode 100644 index 176ae8d790..0000000000 --- a/tests/renderer/components/__snapshots__/editors-toolbar-button-spec.tsx.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Editor toolbar button component MaximizeButton renders 1`] = ` - - - -`; - -exports[`Editor toolbar button component RemoveButton renders 1`] = ` - - - -`;