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:
parent
0ea1985ec4
commit
4323b6d618
2 changed files with 61 additions and 0 deletions
5
spec-main/fixtures/chromium/spellchecker.html
Normal file
5
spec-main/fixtures/chromium/spellchecker.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<textarea style="font-size: 40px; width: 100%; height: 100%"></textarea>
|
||||
</body>
|
||||
</html>
|
56
spec-main/spellchecker-spec.ts
Normal file
56
spec-main/spellchecker-spec.ts
Normal 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)
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue