api-web-frame-spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { expect } from 'chai'
  2. import * as path from 'path'
  3. import { BrowserWindow, ipcMain } from 'electron'
  4. import { closeAllWindows } from './window-helpers'
  5. describe('webFrame module', () => {
  6. const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures')
  7. afterEach(closeAllWindows)
  8. it('calls a spellcheck provider', async () => {
  9. const w = new BrowserWindow({
  10. show: false,
  11. webPreferences: {
  12. nodeIntegration: true
  13. }
  14. })
  15. await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html'))
  16. w.focus()
  17. await w.webContents.executeJavaScript('document.querySelector("input").focus()', true)
  18. const spellCheckerFeedback =
  19. new Promise<[string[], boolean]>(resolve => {
  20. ipcMain.on('spec-spell-check', (e, words, callbackDefined) => {
  21. if (words.length === 5) {
  22. // The API calls the provider after every completed word.
  23. // The promise is resolved only after this event is received with all words.
  24. resolve([words, callbackDefined])
  25. }
  26. })
  27. })
  28. const inputText = `spleling test you're `
  29. for (const keyCode of inputText) {
  30. w.webContents.sendInputEvent({ type: 'char', keyCode })
  31. }
  32. const [words, callbackDefined] = await spellCheckerFeedback
  33. expect(words.sort()).to.deep.equal(['spleling', 'test', `you're`, 'you', 're'].sort())
  34. expect(callbackDefined).to.be.true()
  35. })
  36. })