autofill-spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { BrowserWindow } from 'electron';
  2. import * as path from 'node:path';
  3. import { expect } from 'chai';
  4. import { closeAllWindows } from './lib/window-helpers';
  5. import { setTimeout } from 'node:timers/promises';
  6. const fixturesPath = path.resolve(__dirname, 'fixtures');
  7. describe('autofill', () => {
  8. afterEach(closeAllWindows);
  9. it('can be selected via keyboard for a <datalist> with text type', async () => {
  10. const w = new BrowserWindow({ show: true });
  11. await w.loadFile(path.join(fixturesPath, 'pages', 'datalist-text.html'));
  12. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
  13. const inputText = 'clap';
  14. for (const keyCode of inputText) {
  15. w.webContents.sendInputEvent({ type: 'char', keyCode });
  16. await setTimeout(100);
  17. }
  18. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Down' });
  19. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Enter' });
  20. const value = await w.webContents.executeJavaScript("document.querySelector('input').value");
  21. expect(value).to.equal('Eric Clapton');
  22. });
  23. it('can be selected via keyboard for a <datalist> with time type', async () => {
  24. const w = new BrowserWindow({ show: true });
  25. await w.loadFile(path.join(fixturesPath, 'pages', 'datalist-time.html'));
  26. const inputText = '11P'; // 1:01 PM
  27. for (const keyCode of inputText) {
  28. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
  29. w.webContents.sendInputEvent({ type: 'keyDown', keyCode });
  30. w.webContents.sendInputEvent({ type: 'char', keyCode });
  31. await setTimeout(100);
  32. }
  33. w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Tab' });
  34. const value = await w.webContents.executeJavaScript("document.querySelector('input').value");
  35. expect(value).to.equal('13:01');
  36. });
  37. });