Skip to content

Commit f032e18

Browse files
fix: custom sounds pagination action buttons when the amount exceeds the specified limit (#40113)
Co-authored-by: Douglas Fabris <devfabris@gmail.com>
1 parent 2353766 commit f032e18

4 files changed

Lines changed: 68 additions & 1 deletion

File tree

.changeset/tall-flowers-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes inability to use custom sounds pagination action buttons when the amount exceeds the specified limit
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { mockAppRoot } from '@rocket.chat/mock-providers';
2+
import { composeStories } from '@storybook/react';
3+
import { render, screen } from '@testing-library/react';
4+
5+
import * as stories from './CustomSoundsTable.stories';
6+
7+
const mockSounds = Array.from({ length: 25 }, (_, i) => ({
8+
_id: `sound-${i}`,
9+
name: `Custom Sound ${i + 1}`,
10+
extension: 'mp3',
11+
}));
12+
13+
const getMockedAppRoot = () =>
14+
mockAppRoot().withEndpoint('GET', '/v1/custom-sounds.list', () => ({
15+
sounds: mockSounds,
16+
total: 50,
17+
count: 25,
18+
offset: 0,
19+
}));
20+
21+
test('should enable pagination when data.total exceeds itemsPerPage', async () => {
22+
const { Default } = composeStories(stories);
23+
render(<Default />, { wrapper: getMockedAppRoot().build() });
24+
25+
const firstSound = await screen.findByText('Custom Sound 1');
26+
expect(firstSound).toBeInTheDocument();
27+
28+
const nextPageButton = screen.getByRole('button', { name: 'Next page' });
29+
expect(nextPageButton).toBeInTheDocument();
30+
expect(nextPageButton).not.toBeDisabled();
31+
32+
const pageTwoButton = screen.getByRole('button', { name: 'Page 2' });
33+
expect(pageTwoButton).toBeInTheDocument();
34+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Margins } from '@rocket.chat/fuselage';
2+
import { PageContent } from '@rocket.chat/ui-client';
3+
import { action } from '@storybook/addon-actions';
4+
import type { Meta, StoryFn } from '@storybook/react';
5+
import { useRef } from 'react';
6+
7+
import CustomSoundsTable from './CustomSoundsTable';
8+
9+
export default {
10+
component: CustomSoundsTable,
11+
decorators: [
12+
(fn) => (
13+
<PageContent mb='neg-x8'>
14+
<Margins block={8}>{fn()}</Margins>
15+
</PageContent>
16+
),
17+
],
18+
} satisfies Meta<typeof CustomSoundsTable>;
19+
20+
const Template: StoryFn<typeof CustomSoundsTable> = (args) => {
21+
const reloadRef = useRef(() => undefined);
22+
return <CustomSoundsTable {...args} reload={reloadRef} />;
23+
};
24+
25+
export const Default = Template.bind({});
26+
Default.args = {
27+
onClick: () => action('clicked'),
28+
};

apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const CustomSoundsTable = ({ reload, onClick }: CustomSoundsTableProps) => {
8888
divider
8989
current={current}
9090
itemsPerPage={itemsPerPage}
91-
count={data.sounds.length || 0}
91+
count={data?.total || 0}
9292
onSetItemsPerPage={onSetItemsPerPage}
9393
onSetCurrent={onSetCurrent}
9494
{...paginationProps}

0 commit comments

Comments
 (0)