2020-04-21 22:28:31 +03:00
|
|
|
import { BrowserWindow } from 'electron';
|
|
|
|
import * as path from 'path';
|
2023-01-26 00:01:25 +03:00
|
|
|
import { delay } from './lib/spec-helpers';
|
2020-04-21 22:28:31 +03:00
|
|
|
import { expect } from 'chai';
|
2023-01-26 00:01:25 +03:00
|
|
|
import { closeAllWindows } from './lib/window-helpers';
|
2020-04-21 22:28:31 +03:00
|
|
|
|
2022-08-16 22:23:13 +03:00
|
|
|
const fixturesPath = path.resolve(__dirname, 'fixtures');
|
2020-04-21 22:28:31 +03:00
|
|
|
|
|
|
|
describe('autofill', () => {
|
|
|
|
afterEach(closeAllWindows);
|
|
|
|
|
2023-01-23 19:21:28 +03:00
|
|
|
it('can be selected via keyboard for a <datalist> with text type', async () => {
|
2020-04-21 22:28:31 +03:00
|
|
|
const w = new BrowserWindow({ show: true });
|
2023-01-23 19:21:28 +03:00
|
|
|
await w.loadFile(path.join(fixturesPath, 'pages', 'datalist-text.html'));
|
2020-04-21 22:28:31 +03:00
|
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
|
2023-01-23 19:21:28 +03:00
|
|
|
|
2020-04-21 22:28:31 +03:00
|
|
|
const inputText = 'clap';
|
|
|
|
for (const keyCode of inputText) {
|
|
|
|
w.webContents.sendInputEvent({ type: 'char', keyCode });
|
|
|
|
await delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Down' });
|
|
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Enter' });
|
|
|
|
|
|
|
|
const value = await w.webContents.executeJavaScript("document.querySelector('input').value");
|
|
|
|
expect(value).to.equal('Eric Clapton');
|
|
|
|
});
|
2023-01-23 19:21:28 +03:00
|
|
|
|
|
|
|
it('can be selected via keyboard for a <datalist> with time type', async () => {
|
|
|
|
const w = new BrowserWindow({ show: true });
|
|
|
|
await w.loadFile(path.join(fixturesPath, 'pages', 'datalist-time.html'));
|
|
|
|
|
|
|
|
const inputText = '11P'; // 1:01 PM
|
|
|
|
for (const keyCode of inputText) {
|
|
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
|
|
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode });
|
|
|
|
w.webContents.sendInputEvent({ type: 'char', keyCode });
|
|
|
|
await delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
|
|
|
|
|
|
|
|
const value = await w.webContents.executeJavaScript("document.querySelector('input').value");
|
|
|
|
expect(value).to.equal('13:01');
|
|
|
|
});
|
2020-04-21 22:28:31 +03:00
|
|
|
});
|