|
| 1 | +import { BrowserWindow } from 'electron' |
| 2 | + |
| 3 | +import { expect } from 'chai' |
| 4 | +import * as path from 'path' |
| 5 | +import { closeWindow } from './window-helpers' |
| 6 | +import { emittedOnce } from './events-helpers' |
| 7 | +import { ifit } from './spec-helpers' |
| 8 | + |
| 9 | +describe('spellchecker', () => { |
| 10 | + let w: BrowserWindow |
| 11 | + |
| 12 | + beforeEach(async () => { |
| 13 | + w = new BrowserWindow({ |
| 14 | + show: false |
| 15 | + }) |
| 16 | + await w.loadFile(path.resolve(__dirname, './fixtures/chromium/spellchecker.html')) |
| 17 | + }) |
| 18 | + |
| 19 | + afterEach(async () => { |
| 20 | + await closeWindow(w) |
| 21 | + }) |
| 22 | + |
| 23 | + ifit(process.platform !== 'win32')('should detect correctly spelled words as correct', async () => { |
| 24 | + await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautiful and lovely"') |
| 25 | + await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()') |
| 26 | + const contextMenuPromise = emittedOnce(w.webContents, 'context-menu') |
| 27 | + // Wait for spellchecker to load |
| 28 | + await new Promise(resolve => setTimeout(resolve, 500)) |
| 29 | + w.webContents.sendInputEvent({ |
| 30 | + type: 'mouseDown', |
| 31 | + button: 'right', |
| 32 | + x: 43, |
| 33 | + y: 42 |
| 34 | + }) |
| 35 | + const contextMenuParams: Electron.ContextMenuParams = (await contextMenuPromise)[1] |
| 36 | + expect(contextMenuParams.misspelledWord).to.eq('') |
| 37 | + expect(contextMenuParams.dictionarySuggestions).to.have.lengthOf(0) |
| 38 | + }) |
| 39 | + |
| 40 | + ifit(process.platform !== 'win32')('should detect incorrectly spelled words as incorrect', async () => { |
| 41 | + await w.webContents.executeJavaScript('document.body.querySelector("textarea").value = "Beautifulllll asd asd"') |
| 42 | + await w.webContents.executeJavaScript('document.body.querySelector("textarea").focus()') |
| 43 | + const contextMenuPromise = emittedOnce(w.webContents, 'context-menu') |
| 44 | + // Wait for spellchecker to load |
| 45 | + await new Promise(resolve => setTimeout(resolve, 500)) |
| 46 | + w.webContents.sendInputEvent({ |
| 47 | + type: 'mouseDown', |
| 48 | + button: 'right', |
| 49 | + x: 43, |
| 50 | + y: 42 |
| 51 | + }) |
| 52 | + const contextMenuParams: Electron.ContextMenuParams = (await contextMenuPromise)[1] |
| 53 | + expect(contextMenuParams.misspelledWord).to.eq('Beautifulllll') |
| 54 | + expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1) |
| 55 | + }) |
| 56 | +}) |
0 commit comments