chore: add tests for the spellchecker (#22099)

* chore: add tests for the spellchecker

* chore: do not run spellchecker tests on windows
This commit is contained in:
Samuel Attard 2020-02-26 17:29:19 -08:00 committed by GitHub
parent 0ea1985ec4
commit 4323b6d618
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,5 @@
<html>
<body>
<textarea style="font-size: 40px; width: 100%; height: 100%"></textarea>
</body>
</html>

View file

@ -0,0 +1,56 @@
import { BrowserWindow } from 'electron'
import { expect } from 'chai'
import * as path from 'path'
import { closeWindow } from './window-helpers'
import { emittedOnce } from './events-helpers'
import { ifit } from './spec-helpers'
describe('spellchecker', () => {
let w: BrowserWindow
beforeEach(async () => {
w = new BrowserWindow({
show: false
})
await w.loadFile(path.resolve(__dirname, './fixtures/chromium/spellchecker.html'))
})
afterEach(async () => {
await closeWindow(w)
})
ifit(process.platform !== 'win32')('should detect correctly spelled words as correct', async () => {
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautiful and lovely"')
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()')
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu')
// Wait for spellchecker to load
await new Promise(resolve => setTimeout(resolve, 500))
w.webContents.sendInputEvent({
type: 'mouseDown',
button: 'right',
x: 43,
y: 42
})
const contextMenuParams: Electron.ContextMenuParams = (await contextMenuPromise)[1]
expect(contextMenuParams.misspelledWord).to.eq('')
expect(contextMenuParams.dictionarySuggestions).to.have.lengthOf(0)
})
ifit(process.platform !== 'win32')('should detect incorrectly spelled words as incorrect', async () => {
await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautifulllll asd asd"')
await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()')
const contextMenuPromise = emittedOnce(w.webContents, 'context-menu')
// Wait for spellchecker to load
await new Promise(resolve => setTimeout(resolve, 500))
w.webContents.sendInputEvent({
type: 'mouseDown',
button: 'right',
x: 43,
y: 42
})
const contextMenuParams: Electron.ContextMenuParams = (await contextMenuPromise)[1]
expect(contextMenuParams.misspelledWord).to.eq('Beautifulllll')
expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1)
})
})