|
1 |
| -import { BrowserWindow } from 'electron' |
| 1 | +import { BrowserWindow, Session, session } from 'electron' |
2 | 2 |
|
3 | 3 | import { expect } from 'chai'
|
4 | 4 | import * as path from 'path'
|
@@ -53,4 +53,70 @@ describe('spellchecker', () => {
|
53 | 53 | expect(contextMenuParams.misspelledWord).to.eq('Beautifulllll')
|
54 | 54 | expect(contextMenuParams.dictionarySuggestions).to.have.length.of.at.least(1)
|
55 | 55 | })
|
| 56 | + |
| 57 | + describe('custom dictionary word list API', () => { |
| 58 | + let ses: Session |
| 59 | + |
| 60 | + beforeEach(async () => { |
| 61 | + // ensure a new session runs on each test run |
| 62 | + ses = session.fromPartition(`persist:customdictionary-test-${Date.now()}`) |
| 63 | + }) |
| 64 | + |
| 65 | + afterEach(async () => { |
| 66 | + if (ses) { |
| 67 | + await ses.clearStorageData() |
| 68 | + ses.destroy() |
| 69 | + } |
| 70 | + }) |
| 71 | + |
| 72 | + describe('ses.listWordsFromSpellCheckerDictionary', () => { |
| 73 | + it('should successfully list words in custom dictionary', async () => { |
| 74 | + const words = ['foo', 'bar', 'baz'] |
| 75 | + const results = words.map(word => ses.addWordToSpellCheckerDictionary(word)) |
| 76 | + expect(results).to.eql([true, true, true]) |
| 77 | + |
| 78 | + const wordList = await ses.listWordsInSpellCheckerDictionary() |
| 79 | + expect(wordList).to.have.deep.members(words) |
| 80 | + }) |
| 81 | + |
| 82 | + it('should return an empty array if no words are added', async () => { |
| 83 | + const wordList = await ses.listWordsInSpellCheckerDictionary() |
| 84 | + expect(wordList).to.have.length(0) |
| 85 | + }) |
| 86 | + }) |
| 87 | + |
| 88 | + describe('ses.addWordToSpellCheckerDictionary', () => { |
| 89 | + it('should successfully add word to custom dictionary', async () => { |
| 90 | + const result = ses.addWordToSpellCheckerDictionary('foobar') |
| 91 | + expect(result).to.equal(true) |
| 92 | + const wordList = await ses.listWordsInSpellCheckerDictionary() |
| 93 | + expect(wordList).to.eql(['foobar']) |
| 94 | + }) |
| 95 | + |
| 96 | + it('should fail for an empty string', async () => { |
| 97 | + const result = ses.addWordToSpellCheckerDictionary('') |
| 98 | + expect(result).to.equal(false) |
| 99 | + const wordList = await ses.listWordsInSpellCheckerDictionary |
| 100 | + expect(wordList).to.have.length(0) |
| 101 | + }) |
| 102 | + }) |
| 103 | + |
| 104 | + describe('ses.removeWordFromSpellCheckerDictionary', () => { |
| 105 | + it('should successfully remove words to custom dictionary', async () => { |
| 106 | + const result1 = ses.addWordToSpellCheckerDictionary('foobar') |
| 107 | + expect(result1).to.equal(true) |
| 108 | + const wordList1 = await ses.listWordsInSpellCheckerDictionary() |
| 109 | + expect(wordList1).to.eql(['foobar']) |
| 110 | + const result2 = ses.removeWordFromSpellCheckerDictionary('foobar') |
| 111 | + expect(result2).to.equal(true) |
| 112 | + const wordList2 = await ses.listWordsInSpellCheckerDictionary() |
| 113 | + expect(wordList2).to.have.length(0) |
| 114 | + }) |
| 115 | + |
| 116 | + it('should fail for words not in custom dictionary', () => { |
| 117 | + const result2 = ses.removeWordFromSpellCheckerDictionary('foobar') |
| 118 | + expect(result2).to.equal(false) |
| 119 | + }) |
| 120 | + }) |
| 121 | + }) |
56 | 122 | })
|
0 commit comments