test: await setInputFiles in flaky input tests (#1345)
This commit is contained in:
parent
823fffaa65
commit
7e8ab8a175
|
|
@ -156,30 +156,39 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
|
||||||
});
|
});
|
||||||
it('should be able to read selected file', async({page, server}) => {
|
it('should be able to read selected file', async({page, server}) => {
|
||||||
await page.setContent(`<input type=file>`);
|
await page.setContent(`<input type=file>`);
|
||||||
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD));
|
const [, content] = await Promise.all([
|
||||||
expect(await page.$eval('input', async picker => {
|
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD)),
|
||||||
picker.click();
|
page.$eval('input', async picker => {
|
||||||
await new Promise(x => picker.oninput = x);
|
picker.click();
|
||||||
const reader = new FileReader();
|
await new Promise(x => picker.oninput = x);
|
||||||
const promise = new Promise(fulfill => reader.onload = fulfill);
|
const reader = new FileReader();
|
||||||
reader.readAsText(picker.files[0]);
|
const promise = new Promise(fulfill => reader.onload = fulfill);
|
||||||
return promise.then(() => reader.result);
|
reader.readAsText(picker.files[0]);
|
||||||
})).toBe('contents of the file');
|
return promise.then(() => reader.result);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
expect(content).toBe('contents of the file');
|
||||||
});
|
});
|
||||||
it('should be able to reset selected files with empty file list', async({page, server}) => {
|
it('should be able to reset selected files with empty file list', async({page, server}) => {
|
||||||
await page.setContent(`<input type=file>`);
|
await page.setContent(`<input type=file>`);
|
||||||
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD));
|
const [, fileLength1] = await Promise.all([
|
||||||
expect(await page.$eval('input', async picker => {
|
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD)),
|
||||||
picker.click();
|
page.$eval('input', async picker => {
|
||||||
await new Promise(x => picker.oninput = x);
|
picker.click();
|
||||||
return picker.files.length;
|
await new Promise(x => picker.oninput = x);
|
||||||
})).toBe(1);
|
return picker.files.length;
|
||||||
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles([]));
|
}),
|
||||||
expect(await page.$eval('input', async picker => {
|
]);
|
||||||
picker.click();
|
expect(fileLength1).toBe(1);
|
||||||
await new Promise(x => picker.oninput = x);
|
const [, fileLength2] = await Promise.all([
|
||||||
return picker.files.length;
|
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles([])),
|
||||||
})).toBe(0);
|
page.$eval('input', async picker => {
|
||||||
|
picker.click();
|
||||||
|
await new Promise(x => picker.oninput = x);
|
||||||
|
return picker.files.length;
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
expect(fileLength2).toBe(0);
|
||||||
});
|
});
|
||||||
it('should not accept multiple files for single-file input', async({page, server}) => {
|
it('should not accept multiple files for single-file input', async({page, server}) => {
|
||||||
await page.setContent(`<input type=file>`);
|
await page.setContent(`<input type=file>`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue