Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #1246947 added Pagination component #3

Merged
merged 5 commits into from
Sep 6, 2023
Merged
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
192 changes: 186 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/react-front-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@storybook/addon-links": "^7.1.0",
"@storybook/blocks": "^7.1.0",
"@storybook/jest": "^0.1.0",
"@storybook/preview-api": "^7.4.0",
"@storybook/react": "^7.1.0",
"@storybook/react-vite": "^7.1.0",
"@storybook/test-runner": "^0.11.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Meta, StoryObj } from '@storybook/react';

import { useStorybookArgsConnect } from '../../../hooks/useStorybookArgsConnect';

import { Pagination as Cmp } from './Pagination';

const meta = {
component: Cmp,
decorators: [
function Component(Story, ctx) {
const args = useStorybookArgsConnect(ctx.args, {
onPageChange: 'page',
onRowsPerPageChange: 'rowsPerPage',
});
return <Story args={{ ...args }} />;
},
],
tags: ['autodocs'],
title: '3-custom/Components/Pagination',
} satisfies Meta<typeof Cmp>;

export default meta;
type IStory = StoryObj<typeof meta>;

export const Pagination: IStory = {
args: {
page: 2,
rowsPerPage: 15,
rowsPerPageLabel: 'Number of results per page',
rowsPerPageOptions: [
{ label: 'Display 1 result', value: 1 },
{ label: 'Display 5 results', value: 5 },
{ label: 'Display 10 results', value: 10 },
{ label: 'Display 15 results', value: 15 },
],
totalPages: 10,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { expect } from '@storybook/jest';
import { within } from '@storybook/testing-library';

import { renderWithProviders } from '../../../utils/tests';

import { Pagination } from './Pagination';

describe('Pagination', () => {
beforeEach(() => {
// Prevent mantine random ID
Math.random = () => 0.42;
});

it('matches snapshot', () => {
const { container } = renderWithProviders(
<Pagination
page={2}
rowsPerPage={15}
rowsPerPageLabel="Number of results per page"
rowsPerPageOptions={[
{ label: 'Display 1 result', value: 1 },
{ label: 'Display 5 results', value: 5 },
{ label: 'Display 10 results', value: 10 },
{ label: 'Display 15 results', value: 15 },
]}
totalPages={10}
/>
);
expect(container).toMatchSnapshot();
});

it('renders with minimal props', () => {
QuentinLeCaignec marked this conversation as resolved.
Show resolved Hide resolved
const { container } = renderWithProviders(
<Pagination page={2} rowsPerPage={15} totalPages={10} />
);
const canvas = within(container);
expect(canvas.queryByTestId('pagination')).toBeVisible();
expect(canvas.queryByTestId('pagination-rowsPerPage')).toBeNull();
expect(canvas.queryByTestId('pagination-page')).toBeVisible();
});

it('renders with full props', () => {
const { container } = renderWithProviders(
<Pagination
page={2}
rowsPerPage={15}
rowsPerPageLabel="Number of results per page"
rowsPerPageOptions={[
{ value: 1 },
{ value: 5 },
{ value: 10 },
{ value: 15 },
]}
totalPages={10}
/>
);
const canvas = within(container);
expect(canvas.queryByTestId('pagination')).toBeVisible();
expect(canvas.queryByTestId('pagination-rowsPerPage')).toBeVisible();
expect(canvas.queryByTestId('pagination-page')).toBeVisible();
});
});
Loading