Skip to content

Commit 5bfbf4d

Browse files
committed
feat(metadata-view): bulk custom actions
Refactor to use RTL
1 parent 1419ef0 commit 5bfbf4d

2 files changed

Lines changed: 52 additions & 48 deletions

File tree

src/elements/content-explorer/__tests__/ContentExplorer.test.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,58 @@ describe('elements/content-explorer/ContentExplorer', () => {
505505

506506
expect(screen.getByRole('button', { name: 'Metadata' })).toBeInTheDocument();
507507
});
508+
509+
test('should call onClick when bulk item action is clicked', async () => {
510+
const mockOnClick = jest.fn();
511+
const metadataViewV2WithBulkItemActions = {
512+
...metadataViewV2ElementProps,
513+
bulkItemActions: [
514+
{
515+
label: 'Download',
516+
onClick: mockOnClick,
517+
},
518+
],
519+
};
520+
521+
renderComponent(metadataViewV2WithBulkItemActions);
522+
523+
await waitFor(() => {
524+
expect(screen.getByTestId('content-explorer')).toBeInTheDocument();
525+
});
526+
527+
await waitFor(() => {
528+
expect(screen.getByRole('row', { name: /Child 2/i })).toBeInTheDocument();
529+
});
530+
531+
const firstRow = screen.getByRole('row', { name: /Child 2/i });
532+
const checkbox = within(firstRow).getByRole('checkbox');
533+
await userEvent.click(checkbox);
534+
535+
await waitFor(() => {
536+
expect(screen.getByRole('button', { name: 'Bulk actions' })).toBeInTheDocument();
537+
});
538+
539+
const ellipsisButton = screen.getByRole('button', { name: 'Bulk actions' });
540+
await userEvent.click(ellipsisButton);
541+
542+
await waitFor(() => {
543+
expect(screen.getByRole('menuitem', { name: 'Download' })).toBeInTheDocument();
544+
});
545+
546+
const downloadAction = screen.getByRole('menuitem', { name: 'Download' });
547+
await userEvent.click(downloadAction);
548+
549+
const expectedOnClickArgument = new Set(['1188890835']);
550+
await waitFor(() => {
551+
expect(mockOnClick).toHaveBeenCalled();
552+
553+
// Array conversion from sets to avoid set comparison issues in Jest
554+
const argsForFirstMockCall = mockOnClick.mock.calls[0];
555+
const firstArgToMockOnClick = argsForFirstMockCall[0];
556+
557+
expect(Array.from(firstArgToMockOnClick)).toEqual(Array.from(expectedOnClickArgument));
558+
});
559+
});
508560
});
509561
});
510562

src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,6 @@ export const sidePanelOpenWithSingleItemSelected: Story = {
205205
},
206206
};
207207

208-
export const metadataViewV2WithBulkItemActionMenuShowsEllipsis: Story = {
209-
args: metadataViewV2WithBulkItemActions,
210-
play: async ({ canvas }) => {
211-
await waitFor(() => {
212-
expect(canvas.getByRole('row', { name: /Child 2/i })).toBeInTheDocument();
213-
});
214-
215-
const firstRow = canvas.getByRole('row', { name: /Child 2/i });
216-
const checkbox = within(firstRow).getByRole('checkbox');
217-
userEvent.click(checkbox);
218-
219-
await waitFor(() => {
220-
expect(canvas.getByRole('button', { name: 'Bulk actions' })).toBeInTheDocument();
221-
});
222-
},
223-
};
224-
225208
export const metadataViewV2WithBulkItemActionMenuShowsItemActionMenu: Story = {
226209
args: metadataViewV2WithBulkItemActions,
227210
play: async ({ canvas }) => {
@@ -247,37 +230,6 @@ export const metadataViewV2WithBulkItemActionMenuShowsItemActionMenu: Story = {
247230
},
248231
};
249232

250-
export const metadataViewV2WithBulkItemActionMenuCallsOnClick: Story = {
251-
args: metadataViewV2WithBulkItemActions,
252-
play: async ({ canvas, args }) => {
253-
await waitFor(() => {
254-
expect(canvas.getByRole('row', { name: /Child 2/i })).toBeInTheDocument();
255-
});
256-
257-
const firstRow = canvas.getByRole('row', { name: /Child 2/i });
258-
const checkbox = within(firstRow).getByRole('checkbox');
259-
userEvent.click(checkbox);
260-
261-
await waitFor(() => {
262-
expect(canvas.getByRole('button', { name: 'Bulk actions' })).toBeInTheDocument();
263-
});
264-
265-
const ellipsisButton = canvas.getByRole('button', { name: 'Bulk actions' });
266-
267-
userEvent.click(ellipsisButton);
268-
269-
await waitFor(() => {
270-
expect(screen.getByRole('menuitem', { name: 'Download' })).toBeInTheDocument();
271-
});
272-
const downloadAction = screen.getByRole('menuitem', { name: 'Download' });
273-
userEvent.click(downloadAction);
274-
275-
await waitFor(() => {
276-
expect(args.bulkItemActions[0].onClick).toHaveBeenCalled();
277-
});
278-
},
279-
};
280-
281233
const meta: Meta<typeof ContentExplorer> = {
282234
title: 'Elements/ContentExplorer/tests/MetadataView/visual',
283235
component: ContentExplorer,

0 commit comments

Comments
 (0)