import type { Meta, StoryObj } from '@storybook/react-webpack5'; import { userEvent, within, waitFor } from 'storybook/test'; import Upload from '.'; import { Field } from '../field/Field'; const meta = { component: Upload, title: 'Forms/Upload/Tests', tags: ['!manifest'], argTypes: { maxSize: { control: { type: 'number', min: 0, }, }, }, } satisfies Meta; export default meta; export const MaxSizes = () => { const bKB = 1024; const bMB = 1024 * bKB; const dKB = 1000; const dMB = 1000 * dKB; const binarySizes = [ 10 * bMB, 5 * bMB, 1 * bMB, 500 * bKB, 100 * bKB, 50 * bKB, 10 * bKB, 5 * bKB, 1 * bKB, ]; const decimalSizes = [ 10 * dMB, 5 * dMB, 1 * dMB, 500 * dKB, 100 * dKB, 50 * dKB, 10 * dKB, 5 * dKB, 1 * dKB, ]; return (
{binarySizes.map((maxSize) => ( ))}
{decimalSizes.map((maxSize) => ( ))}
); }; export const WithError: StoryObj = { render: () => ( ), play: async ({ canvasElement }) => { const canvas = within(canvasElement); const fileInput = canvasElement.querySelector('input[type="file"]'); if (!fileInput) { throw new Error('File input not found'); } const file = new File(['This file content is definitely more than 1 byte'], 'test-file.txt', { type: 'text/plain', }); await userEvent.upload(fileInput, file); await waitFor(async () => canvas.findByText(/Maximum filesize is/i), { timeout: 3000 }); }, }; export const AllVariants = () => { return (
); };