Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-flowers-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes inability to use custom sounds pagination action buttons when the amount exceeds the specified limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { composeStories } from '@storybook/react';
import { render, screen } from '@testing-library/react';

import * as stories from './CustomSoundsTable.stories';

const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]);

const mockSounds = Array.from({ length: 25 }, (_, i) => ({
_id: `sound-${i}`,
name: `Custom Sound ${i + 1}`,
extension: 'mp3',
}));

const getMockedAppRoot = () =>
mockAppRoot().withEndpoint('GET', '/v1/custom-sounds.list', () => ({
sounds: mockSounds,
total: 50,
count: 25,
offset: 0,
}));

test.each(testCases)(`renders %s without crashing`, async (_storyname, Story) => {
const { baseElement } = render(<Story />, { wrapper: getMockedAppRoot().build() });
expect(baseElement).toMatchSnapshot();
});

test('should enable pagination when data.total exceeds itemsPerPage', async () => {
const { Default } = composeStories(stories);
const { container } = render(<Default />, { wrapper: getMockedAppRoot().build() });

const firstSound = await screen.findByText('Custom Sound 1');
expect(firstSound).toBeInTheDocument();

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: added this comment to suppress the warning of using node access instead of name access, since it's the only way to locate the element currently

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the unit tests action failing output, you can find the button by its role button and name "Next page"

const forwardButton = container.querySelector('.rcx-pagination__forward');
expect(forwardButton).toBeInTheDocument();
expect(forwardButton).not.toBeDisabled();

const pageTwoButton = screen.getByRole('button', { name: '2' });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here you should update the button name to Page 2

expect(pageTwoButton).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Margins } from '@rocket.chat/fuselage';
import { PageContent } from '@rocket.chat/ui-client';
import type { Meta, StoryFn } from '@storybook/react';
import { useRef } from 'react';

import CustomSoundsTable from './CustomSoundsTable';

export default {
component: CustomSoundsTable,
decorators: [
(fn) => (
<PageContent mb='neg-x8'>
<Margins block={8}>{fn()}</Margins>
</PageContent>
),
],
} satisfies Meta<typeof CustomSoundsTable>;

const Template: StoryFn<typeof CustomSoundsTable> = (args) => {
const reloadRef = useRef(() => undefined);
return <CustomSoundsTable {...args} reload={reloadRef} />;
};

export const Default = Template.bind({});
Default.args = {
onClick: (soundId: string) => () => console.log('Clicked sound', soundId),
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const CustomSoundsTable = ({ reload, onClick }: CustomSoundsTableProps) => {
divider
current={current}
itemsPerPage={itemsPerPage}
count={data.sounds.length || 0}
count={data?.total || 0}
onSetItemsPerPage={onSetItemsPerPage}
onSetCurrent={onSetCurrent}
{...paginationProps}
Expand Down
Loading
Loading