-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(elements/ino-input-file): migrate stencil e2e tests to playw…
…right (#1375) Part of #1258 ## Proposed Changes - migrate tests to playwright <!-- ## Things to check - [ ] Does the change need to be documented? - [ ] Does any existing example code needs to be updated? - [ ] Is the change properly tested? - [ ] Is it helpful to provide another example to demonstrate the new feature? - [ ] Are there other code lines that need to be modified? -->
- Loading branch information
Showing
3 changed files
with
115 additions
and
44 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
packages/elements/src/components/ino-input-file/ino-input-file.e2e.ts
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
packages/storybook/src/stories/ino-input-file/ino-input-file.spec.ts
This file contains 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,102 @@ | ||
/// <reference lib="dom"/> | ||
import { expect, test } from '@playwright/test'; | ||
import { goToStory } from '../test-utils'; | ||
import { readFileSync } from 'fs'; | ||
|
||
test.describe('ino-input-file', () => { | ||
test('should open file dialog on click', async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-input-file', 'default']); | ||
const inputFile = page.locator('ino-input-file'); | ||
const fileChooserPromise = page.waitForEvent('filechooser'); | ||
|
||
await expect(inputFile).toBeVisible(); | ||
await inputFile.click(); | ||
const fileChooser = await fileChooserPromise; | ||
expect(fileChooser).toBeTruthy(); | ||
expect(fileChooser.isMultiple()).toBeFalsy(); | ||
}); | ||
|
||
test('should allow multiply files', async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-input-file', 'multiple']); | ||
const inputFile = page.locator('ino-input-file'); | ||
const fileChooserPromise = page.waitForEvent('filechooser'); | ||
|
||
await expect(inputFile).toBeVisible(); | ||
await inputFile.click(); | ||
const fileChooser = await fileChooserPromise; | ||
expect(fileChooser.isMultiple()).toBeTruthy(); | ||
}); | ||
|
||
test('should not open file dialog if disabled', async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-input-file', 'disabled']); | ||
const inputFile = page.locator('ino-input-file'); | ||
const fileChooserPromise = page.waitForEvent('filechooser', { | ||
timeout: 1000, | ||
}); | ||
await inputFile.click(); | ||
|
||
let error = false; | ||
try { | ||
await fileChooserPromise; | ||
} catch { | ||
error = true; | ||
} | ||
expect(error).toBeTruthy(); | ||
}); | ||
|
||
test('should select file with drag and drop', async ({ page }) => { | ||
await goToStory(page, ['Input', 'ino-input-file', 'drag-and-drop']); | ||
const inputFile = page.locator('ino-input-file'); | ||
const inputFileBtn = inputFile.locator('ino-button'); | ||
const fileChooserPromise = page.waitForEvent('filechooser'); | ||
|
||
await inputFileBtn.click(); | ||
const fileChooser = await fileChooserPromise; | ||
expect(fileChooser).toBeTruthy(); | ||
|
||
// Create the DataTransfer and File | ||
const buffer = btoa('Example file content'); // create a base64 string | ||
const dataTransfer = await page.evaluateHandle(async (data) => { | ||
const dt = new DataTransfer(); | ||
const blobData = await fetch(data).then((res) => res.blob()); | ||
const file = new File([blobData], 'myFile.txt', { | ||
type: 'text/plain', | ||
}); | ||
dt.items.add(file); | ||
return dt; | ||
}, `data:application/octet-stream;base64,${buffer}`); | ||
|
||
// Now dispatch | ||
await page.dispatchEvent('ino-input-file', 'drop', { dataTransfer }); | ||
|
||
await expect(page.getByText('myFile.txt')).toBeVisible(); | ||
}); | ||
|
||
test('should display drag and drop area without secondary text', async ({ | ||
page, | ||
}) => { | ||
await goToStory(page, ['Input', 'ino-input-file', 'drag-and-drop']); | ||
const inputFileBtn = page.locator('ino-input-file ino-button'); | ||
const dndLabel = page.getByText('Drag your files here'); | ||
|
||
await expect(dndLabel).toBeVisible(); | ||
await expect(inputFileBtn).toBeVisible(); | ||
}); | ||
|
||
test('should display drag and drop area with secondary text', async ({ | ||
page, | ||
}) => { | ||
await goToStory(page, [ | ||
'Input', | ||
'ino-input-file', | ||
'drag-and-drop-secondary-text', | ||
]); | ||
const inputFileBtn = page.locator('ino-input-file ino-button'); | ||
const dndLabel = page.getByText('click and drag here'); | ||
const dndSecondLabel = page.getByText('click the button below'); | ||
|
||
await expect(dndLabel).toBeVisible(); | ||
await expect(dndSecondLabel).toBeVisible(); | ||
await expect(inputFileBtn).toBeVisible(); | ||
}); | ||
}); |
This file contains 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