mirror of
https://github.com/strapi/strapi.git
synced 2025-08-13 11:17:42 +00:00
add test file for BulkActionsBar new component
This commit is contained in:
parent
7c9c2d13d7
commit
06d2aefe7e
@ -0,0 +1,87 @@
|
||||
import React from 'react';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { ThemeProvider, lightTheme } from '@strapi/design-system';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import BulkActionsBar from '../index';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
jest.mock('@strapi/helper-plugin', () => ({
|
||||
...jest.requireActual('@strapi/helper-plugin'),
|
||||
useTracking: () => ({
|
||||
trackUsage: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../shared/hooks', () => ({
|
||||
...jest.requireActual('../../../../../shared/hooks'),
|
||||
useInjectionZone: () => [],
|
||||
}));
|
||||
|
||||
describe('BulkActionsBar', () => {
|
||||
const requiredProps = {
|
||||
selectedEntries: [],
|
||||
clearSelectedEntries: jest.fn(),
|
||||
};
|
||||
|
||||
const TestComponent = (props) => (
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<IntlProvider locale="en" messages={{}} defaultLocale="en">
|
||||
<BulkActionsBar {...requiredProps} {...props} />
|
||||
</IntlProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
||||
const setup = (props) => render(<TestComponent {...props} />);
|
||||
|
||||
it('should render publish buttons if showPublish is true', () => {
|
||||
setup({ showPublish: true });
|
||||
|
||||
expect(screen.getByRole('button', { name: /\bPublish\b/ })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /\bUnpublish\b/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not render publish buttons if showPublish is false', () => {
|
||||
setup({ showPublish: false });
|
||||
|
||||
expect(screen.queryByRole('button', { name: /\bPublish\b/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: /\bUnpublish\b/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render delete button if showDelete is true', () => {
|
||||
setup({ showDelete: true });
|
||||
|
||||
expect(screen.getByRole('button', { name: /\bDelete\b/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not render delete button if showDelete is false', () => {
|
||||
setup({ showDelete: false });
|
||||
|
||||
expect(screen.queryByRole('button', { name: /\bDelete\b/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show delete modal if delete button is clicked', () => {
|
||||
setup({ showDelete: true });
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /\bDelete\b/ }));
|
||||
});
|
||||
|
||||
expect(screen.getByText('Confirmation')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should call confirm delete all if confirmation button is clicked', async () => {
|
||||
const mockConfirmDeleteAll = jest.fn();
|
||||
|
||||
setup({
|
||||
showDelete: true,
|
||||
onConfirmDeleteAll: mockConfirmDeleteAll,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await fireEvent.click(screen.getByRole('button', { name: /\bDelete\b/ }));
|
||||
fireEvent.click(screen.getByRole('button', { name: /confirm/i }));
|
||||
});
|
||||
|
||||
expect(mockConfirmDeleteAll).toHaveBeenCalledWith([]);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user