test: await setInputFiles in flaky input tests (#1345)

This commit is contained in:
Dmitry Gozman 2020-03-11 14:35:48 -07:00 committed by GitHub
parent 823fffaa65
commit 7e8ab8a175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,30 +156,39 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
});
it('should be able to read selected file', async({page, server}) => {
await page.setContent(`<input type=file>`);
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD));
expect(await page.$eval('input', async picker => {
picker.click();
await new Promise(x => picker.oninput = x);
const reader = new FileReader();
const promise = new Promise(fulfill => reader.onload = fulfill);
reader.readAsText(picker.files[0]);
return promise.then(() => reader.result);
})).toBe('contents of the file');
const [, content] = await Promise.all([
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD)),
page.$eval('input', async picker => {
picker.click();
await new Promise(x => picker.oninput = x);
const reader = new FileReader();
const promise = new Promise(fulfill => reader.onload = fulfill);
reader.readAsText(picker.files[0]);
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}) => {
await page.setContent(`<input type=file>`);
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD));
expect(await page.$eval('input', async picker => {
picker.click();
await new Promise(x => picker.oninput = x);
return picker.files.length;
})).toBe(1);
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles([]));
expect(await page.$eval('input', async picker => {
picker.click();
await new Promise(x => picker.oninput = x);
return picker.files.length;
})).toBe(0);
const [, fileLength1] = await Promise.all([
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles(FILE_TO_UPLOAD)),
page.$eval('input', async picker => {
picker.click();
await new Promise(x => picker.oninput = x);
return picker.files.length;
}),
]);
expect(fileLength1).toBe(1);
const [, fileLength2] = await Promise.all([
page.waitForEvent('filechooser').then(({element}) => element.setInputFiles([])),
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}) => {
await page.setContent(`<input type=file>`);