Skip to content

Commit

Permalink
small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
framitdavid committed Jan 19, 2025
1 parent ff6412f commit 43b03e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Preview: Story = () => {

return (
<StudioPaginatedContent
buttonTexts={{ previous: 'Previous', next: 'Next' }}
navigationButtonTexts={{ previous: 'Previous', next: 'Next' }}
componentToRender={pages[currentPage]}
navigation={navigation}
currentPageNumber={currentPage}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { StudioPaginatedContent, type StudioPaginatedContentProps } from './StudioPaginatedContent';

const navigationMock: StudioPaginatedContentProps['navigation'] = {
Expand All @@ -10,7 +10,7 @@ const navigationMock: StudioPaginatedContentProps['navigation'] = {
onPrevious: jest.fn(),
};

const buttonTextsMock: StudioPaginatedContentProps['buttonTexts'] = {
const buttonTextsMock: StudioPaginatedContentProps['navigationButtonTexts'] = {
previous: 'Previous',
next: 'Next',
};
Expand All @@ -19,7 +19,7 @@ const defaultProps: StudioPaginatedContentProps = {
totalPages: 5,
currentPageNumber: 2,
componentToRender: <div>Content</div>,
buttonTexts: buttonTextsMock,
navigationButtonTexts: buttonTextsMock,
navigation: navigationMock,
};

Expand Down Expand Up @@ -68,16 +68,19 @@ describe('StudioPaginatedContent', () => {
expect(screen.getByText('Next')).toBeDisabled();
});

it('calls onPrevious when the previous button is clicked', () => {
it('calls onPrevious when the previous button is clicked', async () => {
const user = userEvent.setup();
renderStudioPaginatedContent();

fireEvent.click(screen.getByText('Previous'));
await user.click(screen.getByText('Previous'));
expect(defaultProps.navigation.onPrevious).toHaveBeenCalled();
});

it('calls onNext when the next button is clicked', () => {
it('calls onNext when the next button is clicked', async () => {
const user = userEvent.setup();
renderStudioPaginatedContent();
fireEvent.click(screen.getByText('Next'));

await user.click(screen.getByText('Next'));
expect(defaultProps.navigation.onNext).toHaveBeenCalled();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StudioButton } from '../StudioButton';
import { ChevronLeftIcon, ChevronRightIcon } from '@studio/icons';
import { type StudioPaginatedNavigation } from './types/StudioPaginatedNavigation';

type ButtonTexts = {
type NavigationButtonTexts = {
previous: string;
next: string;
};
Expand All @@ -13,7 +13,7 @@ export type StudioPaginatedContentProps = {
totalPages: number;
currentPageNumber: number;
componentToRender: ReactNode;
buttonTexts: ButtonTexts;
navigationButtonTexts: NavigationButtonTexts;
navigation: StudioPaginatedNavigation;
};

Expand All @@ -22,7 +22,7 @@ export const StudioPaginatedContent = ({
totalPages,
componentToRender,
currentPageNumber,
buttonTexts: { previous: previousButtonText, next: nextButtonText },
navigationButtonTexts: { previous: previousButtonText, next: nextButtonText },
}: StudioPaginatedContentProps): ReactElement => {
return (
<div className={classes.wrapper}>
Expand All @@ -32,7 +32,7 @@ export const StudioPaginatedContent = ({
<ChevronLeftIcon className={classes.icon} />
{previousButtonText}
</StudioButton>
<NavigationCircles totalPages={totalPages} currentPageNumber={currentPageNumber} />
<NavigationStepIndicator totalPages={totalPages} currentPageNumber={currentPageNumber} />
<StudioButton variant='tertiary' size='sm' onClick={onNext} disabled={!canGoNext}>
{nextButtonText}
<ChevronRightIcon />
Expand All @@ -47,7 +47,10 @@ type NavigationCirclesProps = {
currentPageNumber: number;
};

const NavigationCircles = ({ totalPages, currentPageNumber }: NavigationCirclesProps) => {
const NavigationStepIndicator = ({
totalPages,
currentPageNumber,
}: NavigationCirclesProps): React.ReactElement => {
return (
<div className={classes.statusBarContainer}>
{getArrayFromLength(totalPages).map((_, index) => (
Expand Down

0 comments on commit 43b03e3

Please sign in to comment.