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