mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 14:59:07 +00:00
remove stopPropagation and update tests to use getByRole
This commit is contained in:
parent
7094638c38
commit
1b4dddf59e
@ -1,7 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Trash } from '@strapi/icons';
|
||||
import { IconButton, Box } from '@strapi/design-system';
|
||||
import { stopPropagation, useTracking, ConfirmDialog } from '@strapi/helper-plugin';
|
||||
import { useTracking, ConfirmDialog } from '@strapi/helper-plugin';
|
||||
import { useIntl } from 'react-intl';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
@ -16,7 +16,7 @@ const DeleteButton = ({ tokenName, onClickDelete }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Box paddingLeft={1} {...stopPropagation}>
|
||||
<Box paddingLeft={1}>
|
||||
<IconButton
|
||||
onClick={() => setShowConfirmDialog(true)}
|
||||
label={formatMessage(
|
||||
|
@ -11,10 +11,6 @@ jest.mock('@strapi/helper-plugin', () => ({
|
||||
useTracking: jest.fn(() => ({ trackUsage: jest.fn() })),
|
||||
}));
|
||||
|
||||
function getButton(container, name) {
|
||||
return container.querySelector(`button[name="${name}"]`);
|
||||
}
|
||||
|
||||
function ComponentToTest(props) {
|
||||
return (
|
||||
<IntlProvider locale="en" messages={{}}>
|
||||
@ -36,15 +32,15 @@ describe('DeleteButton', () => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
it('show confirmation delete dialog when the delete button is clicked', () => {
|
||||
const { baseElement, queryByText } = setup();
|
||||
fireEvent.click(getButton(baseElement, 'delete'));
|
||||
const { queryByText, getByRole } = setup();
|
||||
fireEvent.click(getByRole('button', { name: 'Delete test' }));
|
||||
|
||||
expect(queryByText('Are you sure you want to delete this?')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('closes the modal when you click on Cancel button', () => {
|
||||
const { baseElement, queryByText, getByText } = setup();
|
||||
fireEvent.click(getButton(baseElement, 'delete'));
|
||||
const { queryByText, getByText, getByRole } = setup();
|
||||
fireEvent.click(getByRole('button', { name: 'Delete test' }));
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(getByText('Cancel'));
|
||||
@ -55,9 +51,9 @@ describe('DeleteButton', () => {
|
||||
|
||||
it('trigger the onClickDelete function when you click on the Confirm button', () => {
|
||||
const spy = jest.fn();
|
||||
const { baseElement, getByText } = setup({ onClickDelete: spy });
|
||||
const { getByRole, getByText } = setup({ onClickDelete: spy });
|
||||
|
||||
fireEvent.click(getButton(baseElement, 'delete'));
|
||||
fireEvent.click(getByRole('button', { name: 'Delete test' }));
|
||||
fireEvent.click(getByText('Confirm'));
|
||||
|
||||
expect(spy).toBeCalledTimes(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user