2019-10-11 20:20:08 +03:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import * as path from 'path'
|
|
|
|
import { BrowserWindow, ipcMain } from 'electron'
|
|
|
|
import { closeAllWindows } from './window-helpers'
|
|
|
|
|
|
|
|
describe('webFrame module', () => {
|
|
|
|
const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures')
|
|
|
|
|
|
|
|
afterEach(closeAllWindows)
|
|
|
|
|
|
|
|
it('calls a spellcheck provider', async () => {
|
|
|
|
const w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await w.loadFile(path.join(fixtures, 'pages', 'webframe-spell-check.html'))
|
|
|
|
w.focus()
|
|
|
|
await w.webContents.executeJavaScript('document.querySelector("input").focus()', true)
|
|
|
|
|
|
|
|
const spellCheckerFeedback =
|
|
|
|
new Promise<[string[], boolean]>(resolve => {
|
|
|
|
ipcMain.on('spec-spell-check', (e, words, callbackDefined) => {
|
|
|
|
if (words.length === 5) {
|
|
|
|
// The API calls the provider after every completed word.
|
|
|
|
// The promise is resolved only after this event is received with all words.
|
|
|
|
resolve([words, callbackDefined])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2020-03-20 18:12:18 +03:00
|
|
|
const inputText = 'spleling test you\'re '
|
2019-10-11 20:20:08 +03:00
|
|
|
for (const keyCode of inputText) {
|
|
|
|
w.webContents.sendInputEvent({ type: 'char', keyCode })
|
|
|
|
}
|
|
|
|
const [words, callbackDefined] = await spellCheckerFeedback
|
2020-03-20 18:12:18 +03:00
|
|
|
expect(words.sort()).to.deep.equal(['spleling', 'test', 'you\'re', 'you', 're'].sort())
|
2019-10-11 20:20:08 +03:00
|
|
|
expect(callbackDefined).to.be.true()
|
|
|
|
})
|
2019-11-01 23:37:02 +03:00
|
|
|
})
|