diff --git a/src/components/ButtonsToolbar/test.spec.jsx b/src/components/ButtonsToolbar/test.spec.jsx
index 46f0ab835..3254d9bb1 100644
--- a/src/components/ButtonsToolbar/test.spec.jsx
+++ b/src/components/ButtonsToolbar/test.spec.jsx
@@ -1,8 +1,6 @@
-import {render as renderTest, screen} from '@testing-library/react';
+import {render, screen} from '@testing-library/react';
import messagesNL from 'i18n/compiled/nl.json';
import React from 'react';
-import {createRoot} from 'react-dom/client';
-import {act} from 'react-dom/test-utils';
import {IntlProvider} from 'react-intl';
import {MemoryRouter} from 'react-router-dom';
@@ -11,25 +9,6 @@ import {SUBMISSION_ALLOWED} from 'components/constants';
import ButtonsToolbar from './index';
-let container = null;
-let root = null;
-beforeEach(() => {
- // setup a DOM element as a render target
- container = document.createElement('div');
- document.body.appendChild(container);
- root = createRoot(container);
-});
-
-afterEach(() => {
- // cleanup on exiting
- act(() => {
- root.unmount();
- container.remove();
- root = null;
- container = null;
- });
-});
-
const LITERALS = {
nextText: {value: '', resolved: 'Next step'},
saveText: {value: '', resolved: 'Save step'},
@@ -47,130 +26,111 @@ const Wrap = ({children}) => (
it('Last step of submittable form, button is present', () => {
const mockFunction = vi.fn();
- act(() => {
- root.render(
-
-
-
- );
- });
-
- const buttons = container.getElementsByClassName('openforms-toolbar__list-item');
-
- expect(buttons.length).toEqual(4);
- expect(buttons[0].textContent).toEqual('Previous step');
- expect(buttons[1].textContent).toEqual('Save step');
- expect(buttons[2].textContent).toEqual('Next step');
- expect(buttons[3].textContent).toEqual('Afbreken');
+ render(
+
+
+
+ );
+
+ expect(screen.getByRole('link', {name: 'Previous step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Save step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Next step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Afbreken'})).toBeVisible();
});
it('Last step of non-submittable form with overview, button is present', () => {
const mockFunction = vi.fn();
- act(() => {
- root.render(
-
-
-
- );
- });
-
- const buttons = container.getElementsByClassName('openforms-toolbar__list-item');
-
- expect(buttons.length).toEqual(4);
- expect(buttons[0].textContent).toEqual('Previous step');
- expect(buttons[1].textContent).toEqual('Save step');
- expect(buttons[2].textContent).toEqual('Next step');
- expect(buttons[3].textContent).toEqual('Afbreken');
+ render(
+
+
+
+ );
+
+ expect(screen.getByRole('link', {name: 'Previous step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Save step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Next step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Afbreken'})).toBeVisible();
});
it('Last step of non-submittable form without overview, button is NOT present', () => {
const mockFunction = vi.fn();
- act(() => {
- root.render(
-
-
-
- );
- });
-
- const buttons = container.getElementsByClassName('openforms-toolbar__list-item');
-
- expect(buttons.length).toEqual(3);
- expect(buttons[0].textContent).toEqual('Previous step');
- expect(buttons[1].textContent).toEqual('Save step');
- expect(buttons[2].textContent).toEqual('Afbreken');
+ render(
+
+
+
+ );
+
+ expect(screen.getByRole('link', {name: 'Previous step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Save step'})).toBeVisible();
+ expect(screen.queryByRole('button', {name: 'Next step'})).not.toBeInTheDocument();
+ expect(screen.getByRole('button', {name: 'Afbreken'})).toBeVisible();
});
it('Non-last step of non-submittable form without overview, button IS present', () => {
const mockFunction = vi.fn();
- act(() => {
- root.render(
-
-
-
- );
- });
-
- const buttons = container.getElementsByClassName('openforms-toolbar__list-item');
-
- expect(buttons.length).toEqual(4);
- expect(buttons[0].textContent).toEqual('Previous step');
- expect(buttons[1].textContent).toEqual('Save step');
- expect(buttons[2].textContent).toEqual('Next step');
- expect(buttons[3].textContent).toEqual('Afbreken');
+ render(
+
+
+
+ );
+
+ expect(screen.getByRole('link', {name: 'Previous step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Save step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Next step'})).toBeVisible();
+ expect(screen.getByRole('button', {name: 'Afbreken'})).toBeVisible();
});
it('Suspending form allowed, button is present', () => {
const mockFunction = vi.fn();
- renderTest(
+ render(
{
it('Suspending form not allowed, button is NOT present', () => {
const mockFunction = vi.fn();
- renderTest(
+ render(
{
- // setup a DOM element as a render target
- container = document.createElement('div');
- document.body.appendChild(container);
- root = createRoot(container);
-});
-
-afterEach(() => {
- // cleanup on exiting
- act(() => {
- root.unmount();
- container.remove();
- root = null;
- container = null;
- });
-});
-
const Wrap = ({children}) => (
{children}
@@ -70,21 +49,19 @@ it('Summary displays logout button if isAuthenticated is true', () => {
useAsync.mockReturnValue({loading: false, value: []});
useRefreshSubmission.mockReturnValue(submissionIsAuthenticated);
- act(() => {
- root.render(
-
- {}}
- />
-
- );
- });
-
- expect(container.textContent).toContain('Uitloggen');
+ render(
+
+ {}}
+ />
+
+ );
+
+ expect(screen.getByRole('button', {name: 'Uitloggen'})).toBeVisible();
});
it('Summary does not display logout button if loginRequired is false', () => {
@@ -98,21 +75,19 @@ it('Summary does not display logout button if loginRequired is false', () => {
useAsync.mockReturnValue({loading: false, value: []});
useRefreshSubmission.mockReturnValue({...SUBMISSION, isAuthenticated: false});
- act(() => {
- root.render(
-
- {}}
- />
-
- );
- });
-
- expect(container.textContent).not.toContain('Uitloggen');
+ render(
+
+ {}}
+ />
+
+ );
+
+ expect(screen.queryByRole('button', {name: 'Uitloggen'})).toBeNull();
});
it('Summary displays abort button if isAuthenticated is false', () => {
@@ -122,7 +97,7 @@ it('Summary displays abort button if isAuthenticated is false', () => {
useAsync.mockReturnValue({loading: false, value: []});
useRefreshSubmission.mockReturnValue({...SUBMISSION, isAuthenticated: false});
- renderTest(
+ render(
{
- // setup a DOM element as a render target
- container = document.createElement('div');
- document.body.appendChild(container);
- root = createRoot(container);
-});
-
-afterEach(() => {
- // cleanup on exiting
- act(() => {
- root.unmount();
- container.remove();
- root = null;
- container = null;
- });
-});
-
const LITERALS = {
confirmText: {value: '', resolved: 'Submit form'},
previousText: {value: '', resolved: 'Previous step'},
@@ -49,8 +27,7 @@ const Wrapper = ({children}) => (
it('Summary of non-submittable form, button is NOT present', () => {
const mockFunction = vi.fn();
-
- renderTest(
+ render(
{
it('Summary of submittable form, button IS present', () => {
const mockFunction = vi.fn();
-
- renderTest(
+ render(