From 412c3d5b71797e310e85cd1e72d6f2f31d3f046f Mon Sep 17 00:00:00 2001 From: Konstantinos Familonidis Date: Tue, 30 Jun 2026 17:41:10 +0300 Subject: [PATCH] Fixes #39501: Replace enzyme test in Form with RTL --- .../components/common/forms/Form.test.js | 52 ++++---- .../forms/__snapshots__/Form.test.js.snap | 125 ------------------ 2 files changed, 28 insertions(+), 149 deletions(-) delete mode 100644 webpack/assets/javascripts/react_app/components/common/forms/__snapshots__/Form.test.js.snap diff --git a/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js b/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js index 7e119ef570..1ef0f0dcd2 100644 --- a/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js +++ b/webpack/assets/javascripts/react_app/components/common/forms/Form.test.js @@ -1,23 +1,29 @@ -import { shallow } from 'enzyme'; import React from 'react'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; import Form from './Form'; describe('Form', () => { - it('should render a form', () => { - const wrapper = shallow(
); + it('renders a form without an error alert', () => { + const { container } = render(); - expect(wrapper).toMatchSnapshot(); + expect(container.querySelector('form.form-horizontal')).toBeInTheDocument(); + expect(container.querySelector('.alert')).not.toBeInTheDocument(); }); - it('should display one base error', () => { - const wrapper = shallow( + + it('displays one base error with the default title', () => { + const { container } = render( ); - expect(wrapper).toMatchSnapshot(); + expect(container.querySelector('.alert-danger')).toBeInTheDocument(); + expect(screen.getByText('Unable to save.')).toBeInTheDocument(); + expect(screen.getByText('invalid something')).toBeInTheDocument(); }); - it('should display multiple base errors', () => { - const wrapper = shallow( + + it('displays multiple base errors', () => { + render( { /> ); - expect(wrapper).toMatchSnapshot(); + expect(screen.getByText('invalid something')).toBeInTheDocument(); + expect(screen.getByText('error too')).toBeInTheDocument(); }); - it('should accept base error title', () => { - const wrapper = shallow( + + it('accepts a base error title', () => { + render( ); - expect(wrapper).toMatchSnapshot(); + expect(screen.getByText('Oops')).toBeInTheDocument(); }); - it('should dispaly form errors as warning', () => { - const wrapper = shallow( + + it('displays form errors as a warning', () => { + const { container } = render( ); - expect(wrapper).toMatchSnapshot(); + expect(container.querySelector('.alert-warning')).toBeInTheDocument(); + expect(screen.getByText('Do not feed the trolls')).toBeInTheDocument(); }); }); diff --git a/webpack/assets/javascripts/react_app/components/common/forms/__snapshots__/Form.test.js.snap b/webpack/assets/javascripts/react_app/components/common/forms/__snapshots__/Form.test.js.snap deleted file mode 100644 index da363924b1..0000000000 --- a/webpack/assets/javascripts/react_app/components/common/forms/__snapshots__/Form.test.js.snap +++ /dev/null @@ -1,125 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Form should accept base error title 1`] = ` - - - - - invalid something - - - - - -`; - -exports[`Form should dispaly form errors as warning 1`] = ` -
- - - - Do not feed the trolls - - - - - -`; - -exports[`Form should display multiple base errors 1`] = ` -
- - -
  • - invalid something -
  • -
  • - error too -
  • -
    -
    - - -`; - -exports[`Form should display one base error 1`] = ` -
    - - - - invalid something - - - - - -`; - -exports[`Form should render a form 1`] = ` -
    - - -`;