참고소스 수정본
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// @ts-check
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
test.beforeEach(async ({page}) => {
|
||||
await page.addInitScript(() => {
|
||||
class FileSystemHandleMock {
|
||||
constructor({name, children}) {
|
||||
this.name = name;
|
||||
children ??= [];
|
||||
this.kind = children.length ? 'directory' : 'file';
|
||||
this._children = children;
|
||||
}
|
||||
|
||||
values() {
|
||||
// Wrap children data in the same mock.
|
||||
return this._children.map(c => new FileSystemHandleMock(c));
|
||||
}
|
||||
}
|
||||
// Create mock directory
|
||||
const mockDir = new FileSystemHandleMock({
|
||||
name: 'root',
|
||||
children: [
|
||||
{
|
||||
name: 'file1',
|
||||
},
|
||||
{
|
||||
name: 'dir1',
|
||||
children: [
|
||||
{
|
||||
name: 'file2',
|
||||
},
|
||||
{
|
||||
name: 'file3',
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'dir2',
|
||||
children: [
|
||||
{
|
||||
name: 'file4',
|
||||
},
|
||||
{
|
||||
name: 'file5',
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
// Make the picker return mock directory
|
||||
window.showDirectoryPicker = async () => mockDir;
|
||||
});
|
||||
});
|
||||
|
||||
test('should display directory tree', async ({ page }) => {
|
||||
await page.goto('/ls-dir.html');
|
||||
await page.locator('button', { hasText: 'Open directory' }).click();
|
||||
// Check that the displayed entries match mock directory.
|
||||
await expect(page.locator('#dir')).toContainText([
|
||||
'file1',
|
||||
'dir1', 'file2', 'file3',
|
||||
'dir2', 'file4', 'file5'
|
||||
]);
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
// @ts-check
|
||||
const { test, expect } = require('@playwright/test');
|
||||
|
||||
test.beforeEach(async ({page}) => {
|
||||
await page.addInitScript(() => {
|
||||
class FileSystemFileHandleMock {
|
||||
constructor(file) {
|
||||
this._file = file;
|
||||
}
|
||||
|
||||
async getFile() {
|
||||
return this._file;
|
||||
}
|
||||
}
|
||||
window.showOpenFilePicker = async () => [new FileSystemFileHandleMock(new File(['Test content.'], "foo.txt"))];
|
||||
});
|
||||
});
|
||||
|
||||
test('show file picker with mock class', async ({ page }) => {
|
||||
await page.goto('/file-picker.html');
|
||||
await page.locator('button', { hasText: 'Open File' }).click();
|
||||
// Check that the content of the mock file has been loaded.
|
||||
await expect(page.locator('textarea')).toHaveValue('Test content.');
|
||||
});
|
||||
Reference in New Issue
Block a user