Skip to content

Commit a041882

Browse files
authored
test: add test for datalist autofills (electron#23110)
* test: add test for datalist autofills * address style nits * move fixture to spec-main
1 parent cd0dda0 commit a041882

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

spec-main/autofill-spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { BrowserWindow } from 'electron';
2+
import * as path from 'path';
3+
import { delay } from './spec-helpers';
4+
import { expect } from 'chai';
5+
import { closeAllWindows } from './window-helpers';
6+
7+
const fixturesPath = path.resolve(__dirname, '..', 'spec-main', 'fixtures');
8+
9+
describe('autofill', () => {
10+
afterEach(closeAllWindows);
11+
12+
it('can be selected via keyboard', async () => {
13+
const w = new BrowserWindow({ show: true });
14+
await w.loadFile(path.join(fixturesPath, 'pages', 'datalist.html'));
15+
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
16+
const inputText = 'clap';
17+
for (const keyCode of inputText) {
18+
w.webContents.sendInputEvent({ type: 'char', keyCode });
19+
await delay(100);
20+
}
21+
22+
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Down' });
23+
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Enter' });
24+
25+
const value = await w.webContents.executeJavaScript("document.querySelector('input').value");
26+
expect(value).to.equal('Eric Clapton');
27+
});
28+
});
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<input type="text" list="guitarists" />
5+
<datalist id="guitarists">
6+
<select>
7+
<option value="John Mayer"></option>
8+
<option value="Eric Clapton"></option>
9+
<option value="Django Reinhardt"></option>
10+
</select>
11+
</datalist>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)