import { Meta, StoryObj } from '@storybook/react-webpack5';
import { fn, within, expect, screen } from 'storybook/test';
import Stepper from '../Stepper';
import { useRtlDiffI18n, withRTLDiff } from '../../../.storybook/decorators/RtlDiffDecorator';
const STEPS = [
{
label: 'One',
onClick: fn(),
},
{
label: 'Two',
hoverLabel: (
<>
Diana Jaramillo
dianajarm123@gmail.com
>
),
onClick: fn(),
},
{ label: 'Three', onClick: fn() },
{ label: 'Four', onClick: fn() },
{ label: 'Five', onClick: fn() },
];
const meta = {
component: Stepper,
title: 'Navigation/Stepper/Tests',
tags: ['!manifest'],
argTypes: {
activeStep: {
control: 'radio',
options: [...Array(STEPS.length).keys()],
},
},
} satisfies Meta;
export default meta;
type Story = StoryObj;
export const ProgressbarWidth: Story = {
play: async ({ step }) => {
const getBarBaseWidth = (stepIndex: number) => {
const instance = screen.getByTestId(`stepper${stepIndex}`);
return within(instance).getByTestId('progress-bar')?.style.width;
};
await step('activeStep: -10 (negative) ▸ width should be 0', async () => {
await expect(getBarBaseWidth(-10)).toBe(`0%`);
});
await step('activeStep: 0 ▸ width should be 0', async () => {
await expect(getBarBaseWidth(0)).toBe(`0%`);
});
const WIDTHS = [0, 25, 50, 75, 100];
// eslint-disable-next-line no-plusplus
for (let stepIndex = 1; stepIndex < STEPS.length; stepIndex++) {
await step(
`activeStep: ${stepIndex} ▸ base width should be ${WIDTHS[stepIndex]}%`,
async () => {
await expect(getBarBaseWidth(stepIndex)).toMatch(
new RegExp(`^calc\\(${WIDTHS[stepIndex]}%.*?`),
);
},
);
}
await step('activeStep: 1000 ▸ base width should be 100%', async () => {
await expect(getBarBaseWidth(1000)).toMatch(/^calc\(100%.*?/);
});
},
render: function Render() {
return (
<>
>
);
},
args: {
steps: STEPS,
},
};
// `steps` is a required prop, so `args` must supply it even though `render` builds its own
// translated steps from the i18n map and ignores this value.
const RTL_STEPS = [{ label: 'Amount' }, { label: 'You' }, { label: 'Review' }, { label: 'Pay' }];
export const RTLDiff: Story = {
args: {
steps: RTL_STEPS,
},
render: () => {
const i18n = useRtlDiffI18n();
const steps = [
{ label: i18n.amount },
{ label: i18n.you },
{ label: i18n.review },
{ label: i18n.pay },
];
return (
);
},
...withRTLDiff({
i18n: {
amount: { en: 'Amount', ar: 'المبلغ' },
you: { en: 'You', ar: 'بياناتك' },
review: { en: 'Review', ar: 'المراجعة' },
pay: { en: 'Pay', ar: 'الدفع' },
},
}),
};