import type { Meta, StoryObj } from '@storybook/react-webpack5'; import { expect, userEvent, waitFor } from 'storybook/test'; import { forEachColumn, useRtlDiffI18n, withRTLDiff, } from '../../../.storybook/decorators/RtlDiffDecorator'; import Upload from '..'; export default { component: Upload, title: 'Forms/Upload/Tests/RTL Diff', tags: ['!autodocs', '!manifest'], } satisfies Meta; type Story = StoryObj; export const Sizes: Story = { render: () => { const i18n = useRtlDiffI18n(); return ( <>
); }, ...withRTLDiff({ fixedRows: { heights: 'auto' }, i18n: { smallUpload: { en: 'Small upload', ar: 'منطقة رفع صغيرة' }, mediumUpload: { en: 'Medium upload', ar: 'منطقة رفع متوسطة' }, largeUpload: { en: 'Large upload', ar: 'منطقة رفع كبيرة' }, }, }), }; export const WithError: Story = { render: () => { const i18n = useRtlDiffI18n(); return ( ); }, play: async ({ canvasElement }) => { await forEachColumn(canvasElement, async (column) => { const fileInput = column.querySelector('input[type="file"]'); if (!fileInput) return; const file = new File(['content larger than 1 byte'], 'test-file.txt', { type: 'text/plain', }); await userEvent.upload(fileInput, file); await waitFor( async () => expect(column.querySelector('.upload-error-message')).not.toBeNull(), { timeout: 3000 }, ); }); }, ...withRTLDiff({ i18n: { label: { en: 'Upload a file', ar: 'رفع ملف' }, placeholder: { en: 'Maximum filesize is 1B', ar: 'الحد الأقصى لحجم الملف هو ١ بايت' }, }, }), };