From b59bc5495a2565055f004fbf18b78d2eadc25690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Mon, 2 Dec 2024 15:03:58 +0100 Subject: [PATCH] test: Delete enzyme tests for deprecated components --- react/deprecated/ActionMenu/index.spec.jsx | 115 --------------------- react/deprecated/Alerter/alerter.spec.js | 78 -------------- react/deprecated/Modal/index.spec.jsx | 70 ------------- react/deprecated/ViewStack/index.spec.jsx | 64 ------------ 4 files changed, 327 deletions(-) delete mode 100644 react/deprecated/ActionMenu/index.spec.jsx delete mode 100644 react/deprecated/Alerter/alerter.spec.js delete mode 100644 react/deprecated/Modal/index.spec.jsx delete mode 100644 react/deprecated/ViewStack/index.spec.jsx diff --git a/react/deprecated/ActionMenu/index.spec.jsx b/react/deprecated/ActionMenu/index.spec.jsx deleted file mode 100644 index 814c9aaa28..0000000000 --- a/react/deprecated/ActionMenu/index.spec.jsx +++ /dev/null @@ -1,115 +0,0 @@ -import { render } from '@testing-library/react' -import { mount } from 'enzyme' -import React from 'react' -import { act } from 'react-dom/test-utils' - -import ActionMenu, { ActionMenuItem, ActionMenuRadio } from '.' -import Icon from '../../Icon' -import FileIcon from '../../Icons/File' -import WarningIcon from '../../Icons/Warning' -import { fixPopperTesting } from '../../Popper/testing' -import Typography from '../../Typography' -import { BreakpointsProvider } from '../../providers/Breakpoints' - -xdescribe('ActionMenu', () => { - fixPopperTesting() - - // The update-not-wrapping-in-act warning is disabled for ActionMenuWrapper since - // we have not found how to remove the "update" happening when mounting the - // ActionMenu. - let originalConsoleError = console.error - - beforeEach(() => { - // eslint-disable-next-line no-console - console.error = function (msg, arg) { - if ( - msg.includes('An update to %s inside a test was not wrapped in act') && - arg == 'ActionMenuWrapper' - ) { - return - } else { - return originalConsoleError.apply(this, arguments) - } - } - }) - - afterEach(() => { - // eslint-disable-next-line no-console - console.error = originalConsoleError - }) - - it('should support null children', async () => { - const comp = mount( - - - Item 1 - {null} - - - ) - // Remove an update was not wrapped in act() warning - await act(async () => {}) - expect(comp.find(ActionMenuItem).parent().getElement()).toMatchSnapshot() - }) - - it('should support auto-closing the menu', async () => { - const closeMenu = jest.fn() - const menuAction1 = jest.fn() - const menuAction2 = jest.fn() - const menuActionStoppingPropagation = e => { - e.stopPropagation() - menuAction2() - } - - const comp = mount( - - - Item 1 - - Item 2 - - - - ) - - await act(async () => { - comp.find(ActionMenuItem).at(1).simulate('click') - }) - expect(menuAction2).toHaveBeenCalled() - expect(closeMenu).not.toHaveBeenCalled() - - act(() => { - comp.find(ActionMenuItem).at(0).simulate('click') - }) - expect(menuAction1).toHaveBeenCalled() - expect(closeMenu).toHaveBeenCalled() - }) - - it('should render as expected', async () => { - const { container } = render( - - } - right={} - onClick={() => alert('click')} - > - Item 1 with onclick action - - }> - Item 2 with dialog action - - }>Item 3 - }> - - Item 4 - - - Descriptive text to elaborate on what item 3 does. - - - - ) - - expect(container).toMatchSnapshot() - }) -}) diff --git a/react/deprecated/Alerter/alerter.spec.js b/react/deprecated/Alerter/alerter.spec.js deleted file mode 100644 index 33c6f6e3e6..0000000000 --- a/react/deprecated/Alerter/alerter.spec.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict' -/* eslint-env jest */ - -import { shallow } from 'enzyme' -import React from 'react' - -import Alerter from '.' -import Alert from './Alert' -import Button from '../Button' - -describe('Alerter component', () => { - beforeEach(() => { - Alerter.reset() - }) - // - ;['info', 'success', 'error'].forEach(type => { - it(`renders correctly an ${type} alert`, () => { - const wrapper = shallow() - Alerter[type](`Test ${type} alert`) - expect(wrapper.find(Alert).dive().getElement()).toMatchSnapshot() - }) - }) - - it('should not render too much alerts', () => { - const wrapper = shallow() - Alerter.info(`Test 1`) - Alerter.info(`Test 2`) - Alerter.info(`Test 3`) - expect(wrapper.find(Alert).length).toBe(3) - }) - - it('renders button if buttonText provided', () => { - const wrapper = shallow() - Alerter.info(`Test alert with button`, { - buttonText: 'BTN' - }) - expect(wrapper.find(Alert).dive().getElement()).toMatchSnapshot() - }) - - it('handles dismiss provided to buttonAction', () => { - const alerterWrapper = shallow() - Alerter.info(`Test alert with button`, { - buttonText: 'BTN', - buttonAction: dismiss => { - console.log('DISMISS') - dismiss() - }, - duration: 20000 - }) - const alertWrapper = alerterWrapper.find(Alert) - const alert = alertWrapper.dive() - expect(alert.getElement()).toMatchSnapshot() - alert.instance().base = document.createElement('div') - // we have to wait the same delay as in the Alerter didMount - setTimeout(() => { - expect(alert.state('hidden')).toBe(false) - alert.children().find(Button).simulate('click') - expect(alert.state('hidden')).toBe(true) - }, 20) - }) - - it('handles programmatic removal', () => { - const wrapper = shallow() - const notif = Alerter.info(`Test alert with button`, { - duration: 20000 - }) - Alerter.info(`Test another alert`, { - duration: 20000 - }) - expect(wrapper.find(Alert).length).toBe(2) - Alerter.removeNotification(notif) - expect(wrapper.find(Alert).length).toBe(1) - - // Nothing should happen if we try to remove a non existing notification - Alerter.removeNotification(notif) - expect(wrapper.find(Alert).length).toBe(1) - }) -}) diff --git a/react/deprecated/Modal/index.spec.jsx b/react/deprecated/Modal/index.spec.jsx deleted file mode 100644 index b756959a39..0000000000 --- a/react/deprecated/Modal/index.spec.jsx +++ /dev/null @@ -1,70 +0,0 @@ -import { mount } from 'enzyme' -import React, { useState } from 'react' -import { act } from 'react-dom/test-utils' - -import Modal, { BODY_CLASS } from '.' -import { BreakpointsProvider } from '../../providers/Breakpoints' - -describe('Modal', () => { - const Example = () => { - const [showModal, setShowModal] = useState(false) - const [showModal2, setShowModal2] = useState(false) - return ( - - {showModal ? 1 : null} - {showModal2 ? 2 : null} -