-
Notifications
You must be signed in to change notification settings - Fork 7
Transform FileInputField jest tests into playwright. (#603) #637
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
Merged
bedrich-schindler
merged 1 commit into
next
from
refactoring/fileinput-jest-to-playwright
Jun 7, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
329 changes: 329 additions & 0 deletions
329
src/components/FileInputField/__tests__/FileInputField.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,329 @@ | ||
| import React from 'react'; | ||
| import { | ||
| expect, | ||
| test, | ||
| } from '@playwright/experimental-ct-react'; | ||
| import { | ||
| mixPropTests, | ||
| propTests, | ||
| } from '../../../../tests/playwright'; | ||
| import type { FileInputFieldForFormLayoutTestsProps } from './FileInputField.story'; | ||
| import { | ||
| FileInputFieldForFormLayoutTests, | ||
| FileInputFieldForRefTest, | ||
| FileInputFieldForTest, | ||
| FileInputFieldWithResetButtonForTest, | ||
| } from './FileInputField.story'; | ||
| import { fileSelectedPropTest } from './_propTests/fileSelectedPropTest'; | ||
|
|
||
| test.describe('FileInputField', () => { | ||
| test.describe('base', () => { | ||
| test.describe('visual', () => { | ||
| [ | ||
| ...propTests.defaultComponentPropTest, | ||
| ...mixPropTests([ | ||
| propTests.disabledPropTest, | ||
| propTests.validationStatePropTest, | ||
| ]), | ||
| ...fileSelectedPropTest, | ||
| ...mixPropTests([ | ||
| propTests.fullWidthPropTest, | ||
| propTests.layoutPropTest, | ||
| ]), | ||
| ...propTests.helpTextAndValidationTextPropType, | ||
| ...propTests.helpTextPropTest, | ||
| ...propTests.isLabelVisiblePropTest, | ||
| ...propTests.labelPropTest, | ||
| ...propTests.requiredPropTest, | ||
| ...propTests.sizePropTest, | ||
| ...propTests.validationTextPropTest, | ||
| ].forEach(({ | ||
| name, | ||
| onBeforeTest, | ||
| onBeforeSnapshot, | ||
| props, | ||
| }) => { | ||
| test(name, async ({ | ||
| mount, | ||
| page, | ||
| }) => { | ||
| if (onBeforeTest) { | ||
| await onBeforeTest(page); | ||
| } | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForTest | ||
| {...props} | ||
| />, | ||
| ); | ||
|
|
||
| if (onBeforeSnapshot) { | ||
| await onBeforeSnapshot(page, component); | ||
| } | ||
|
|
||
| const screenshot = await component.screenshot(); | ||
| expect(screenshot).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('non-visual', () => { | ||
| test('id', async ({ mount }) => { | ||
| const testId = 'testId'; | ||
| const testLabel = 'testLabel'; | ||
| const helpText = 'helpText'; | ||
| const validationText = 'validationText'; | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForTest | ||
| helpText={helpText} | ||
| id={testId} | ||
| label={testLabel} | ||
| validationText={validationText} | ||
| />, | ||
| ); | ||
|
|
||
| expect(component.locator(`div[id="${testId}__root"]`)).toBeDefined(); | ||
| await expect(component.getByText(testLabel)).toHaveAttribute('id', `${testId}__labelText`); | ||
| await expect(component.locator('input[type="file"]')).toHaveAttribute('id', testId); | ||
| await expect(component.getByText(helpText)).toHaveAttribute('id', `${testId}__helpText`); | ||
| await expect(component.getByText(validationText)).toHaveAttribute('id', `${testId}__validationText`); | ||
| }); | ||
|
|
||
| test('ref', async ({ mount }) => { | ||
| const component = await mount( | ||
| <FileInputFieldForRefTest | ||
| testRefAttrName="test-ref" | ||
| testRefAttrValue="test-ref-value" | ||
| />, | ||
| ); | ||
|
|
||
| await expect(component.locator('input[type="file"]')).toHaveAttribute('test-ref', 'test-ref-value'); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('functionality', () => { | ||
| test('Call onFilesChanged callback when file upload.', async ({ mount }) => { | ||
| let called = false; | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForTest | ||
| onFilesChanged={() => { | ||
| called = true; | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const virtualFile = { | ||
| buffer: Buffer.from('This is test file.'), | ||
| mimeType: 'text/plain', | ||
| name: 'testfile.txt', | ||
| }; | ||
|
|
||
| const inputField = component.locator('input[type="file"]'); | ||
| await inputField.setInputFiles(virtualFile); | ||
|
|
||
| expect(called).toBe(true); | ||
| }); | ||
|
|
||
| test('Call onFilesChanged callback when file drag and drop into field.', async ({ | ||
| mount, | ||
| page, | ||
| }) => { | ||
| const id = 'dropzoneId'; | ||
| let called = false; | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForTest | ||
| id={id} | ||
| onFilesChanged={() => { | ||
| called = true; | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const fileName = 'newFile.txt'; | ||
| const fileContent = 'This is a test file'; | ||
|
|
||
| const dataTransfer = await page.evaluateHandle(({ | ||
| name, | ||
| content, | ||
| }) => { | ||
| const dt = new DataTransfer(); | ||
| const file = new File( | ||
| [content], | ||
| name, | ||
| { type: 'text/plain' }, | ||
| ); | ||
| dt.items.add(file); | ||
| return dt; | ||
| }, { | ||
| content: fileContent, | ||
| name: fileName, | ||
| }); | ||
|
|
||
| const dropZone = component.locator(`div[id="${id}__root"]`); | ||
|
|
||
| await dropZone.dispatchEvent('dragenter', { dataTransfer }); | ||
| await dropZone.dispatchEvent('drop', { dataTransfer }); | ||
|
|
||
| expect(called).toBe(true); | ||
| }); | ||
|
|
||
| test('Can upload multiple files.', async ({ mount }) => { | ||
| let listLength = 0; | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForTest | ||
| multiple | ||
| onFilesChanged={(files: FileList) => { | ||
| listLength = Object.keys(files).length; | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const virtualFile1 = { | ||
| buffer: Buffer.from('This is test file.'), | ||
| mimeType: 'text/plain', | ||
| name: 'testfile.txt', | ||
| }; | ||
|
|
||
| const virtualFile2 = { | ||
| buffer: Buffer.from('This is another test file.'), | ||
| mimeType: 'text/plain', | ||
| name: 'testfile.txt', | ||
| }; | ||
|
|
||
| const inputField = component.locator('input[type="file"]'); | ||
| await inputField.setInputFiles([ | ||
| virtualFile1, | ||
| virtualFile2, | ||
| ]); | ||
|
|
||
| expect(listLength).toBe(2); | ||
| }); | ||
|
|
||
| test('Can upload multiple files via drag and drop.', async ({ | ||
| mount, | ||
| page, | ||
| }) => { | ||
| const id = 'dropzoneId'; | ||
| let numberOfCalls = 0; | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForTest | ||
| id={id} | ||
| multiple | ||
| onFilesChanged={() => { | ||
| numberOfCalls += 1; | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const fileName1 = 'newFile1.txt'; | ||
| const fileContent1 = 'This is a test file'; | ||
|
|
||
| const dataTransfer1 = await page.evaluateHandle(({ | ||
| name, | ||
| content, | ||
| }) => { | ||
| const dt = new DataTransfer(); | ||
| const file = new File([content], name, { type: 'text/plain' }); | ||
| dt.items.add(file); | ||
| return dt; | ||
| }, { | ||
| content: fileContent1, | ||
| name: fileName1, | ||
| }); | ||
|
|
||
| const fileName2 = 'newFile2.txt'; | ||
| const fileContent2 = 'This another is a test file'; | ||
|
|
||
| const dataTransfer2 = await page.evaluateHandle(({ | ||
| name, | ||
| content, | ||
| }) => { | ||
| const dt = new DataTransfer(); | ||
| const file = new File([content], name, { type: 'text/plain' }); | ||
| dt.items.add(file); | ||
| return dt; | ||
| }, { | ||
| content: fileContent2, | ||
| name: fileName2, | ||
| }); | ||
|
|
||
| const dropZone = component.locator(`div[id="${id}__root"]`); | ||
|
|
||
| await dropZone.dispatchEvent('dragenter', { dataTransfer: dataTransfer1 }); | ||
| await dropZone.dispatchEvent('drop', { dataTransfer: dataTransfer1 }); | ||
| await page.waitForTimeout(1000); | ||
| await dropZone.dispatchEvent('dragenter', { dataTransfer: dataTransfer2 }); | ||
| await dropZone.dispatchEvent('drop', { dataTransfer: dataTransfer2 }); | ||
|
|
||
| expect(numberOfCalls).toBe(2); | ||
| }); | ||
|
|
||
| test('Able to reset selected file.', async ({ mount }) => { | ||
| let keyLength; | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldWithResetButtonForTest | ||
| onFilesChanged={(files: FileList) => { | ||
| keyLength = Object.keys(files).length; | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| const virtualFile = { | ||
| buffer: Buffer.from('This is test file.'), | ||
| mimeType: 'text/plain', | ||
| name: 'testfile.txt', | ||
| }; | ||
|
|
||
| const inputField = component.locator('input[type="file"]'); | ||
| const resetButton = component.getByText('Reset'); | ||
|
|
||
| await inputField.setInputFiles(virtualFile); | ||
| expect(keyLength).toBe(1); | ||
|
|
||
| await resetButton.click(); | ||
| expect(keyLength).toBe(0); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('formLayout', () => { | ||
| test.describe('visual', () => { | ||
| [ | ||
| ...propTests.layoutPropTest, | ||
| ].forEach(({ | ||
| name, | ||
| onBeforeTest, | ||
| onBeforeSnapshot, | ||
| props, | ||
| }) => { | ||
| test(name, async ({ | ||
| mount, | ||
| page, | ||
| }) => { | ||
| if (onBeforeTest) { | ||
| await onBeforeTest(page); | ||
| } | ||
|
|
||
| const component = await mount( | ||
| <FileInputFieldForFormLayoutTests | ||
| {...props as unknown as FileInputFieldForFormLayoutTestsProps} | ||
| />, | ||
| ); | ||
|
|
||
| if (onBeforeSnapshot) { | ||
| await onBeforeSnapshot(page, component); | ||
| } | ||
|
|
||
| const screenshot = await component.screenshot(); | ||
| expect(screenshot).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Binary file added
BIN
+5.19 KB
...ts/FileInputField-base-visual-defaultComponentProps-object-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.33 KB
...sual-disabled-boolean-false-validationState-string-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.4 KB
...visual-disabled-boolean-false-validationState-string-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.13 KB
...sual-disabled-boolean-false-validationState-string-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.19 KB
...se-visual-disabled-boolean-false-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.82 KB
...isual-disabled-boolean-true-validationState-string-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.9 KB
...-visual-disabled-boolean-true-validationState-string-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.65 KB
...isual-disabled-boolean-true-validationState-string-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.74 KB
...ase-visual-disabled-boolean-true-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.74 KB
...apshots/FileInputField-base-visual-filledInputField-object-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.74 KB
...ual-filledInputField-object-validationState-string-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.81 KB
...isual-filledInputField-object-validationState-string-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.74 KB
...ual-filledInputField-object-validationState-string-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.74 KB
...e-visual-filledInputField-object-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.6 KB
...se-visual-fullWidth-boolean-false-layout-string-horizontal-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.07 KB
...base-visual-fullWidth-boolean-false-layout-string-vertical-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.36 KB
...ase-visual-fullWidth-boolean-true-layout-string-horizontal-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.12 KB
...-base-visual-fullWidth-boolean-true-layout-string-vertical-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.61 KB
...-snapshots/FileInputField-base-visual-helpText-node-normal-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.3 KB
...-snapshots/FileInputField-base-visual-helpText-string-long-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.15 KB
...napshots/FileInputField-base-visual-helpText-string-normal-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.29 KB
...putField-base-visual-helpText-string-validationText-string-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.15 KB
...Field-base-visual-helpText-string-validationText-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.65 KB
...Field-base-visual-helpText-undefined-validationText-string-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.68 KB
...ts/FileInputField-base-visual-isLabelVisible-boolean-false-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.19 KB
...ots/FileInputField-base-visual-isLabelVisible-boolean-true-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.46 KB
...tsx-snapshots/FileInputField-base-visual-label-node-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+10.6 KB
...tsx-snapshots/FileInputField-base-visual-label-string-long-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.19 KB
...napshots/FileInputField-base-visual-required-boolean-false-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.32 KB
...snapshots/FileInputField-base-visual-required-boolean-true-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.31 KB
...tsx-snapshots/FileInputField-base-visual-size-string-large-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.19 KB
...sx-snapshots/FileInputField-base-visual-size-string-medium-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+4.81 KB
...tsx-snapshots/FileInputField-base-visual-size-string-small-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+6.96 KB
...hots/FileInputField-base-visual-validationText-node-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+12.6 KB
...hots/FileInputField-base-visual-validationText-string-long-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+7.65 KB
...ts/FileInputField-base-visual-validationText-string-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+4.42 KB
.../FileInputField-formLayout-visual-layout-string-horizontal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+6.63 KB
...ts/FileInputField-formLayout-visual-layout-string-vertical-1-chromium-linux.png
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.