diff --git a/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/tests/index.test.js b/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/tests/index.test.js new file mode 100644 index 0000000000..90202ed36b --- /dev/null +++ b/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/tests/index.test.js @@ -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) => ( + + + + + + ); + + const setup = (props) => render(); + + 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([]); + }); +});