Mailspring/internal_packages/composer-spellcheck/spec/spellcheck-composer-extension-spec.coffee

40 lines
1.5 KiB
CoffeeScript
Raw Normal View History

SpellcheckComposerExtension = require '../lib/spellcheck-composer-extension'
fs = require 'fs'
_ = require 'underscore'
initialHTML = fs.readFileSync(__dirname + '/fixtures/california-with-misspellings-before.html').toString()
expectedHTML = fs.readFileSync(__dirname + '/fixtures/california-with-misspellings-after.html').toString()
describe "SpellcheckComposerExtension", ->
beforeEach ->
# Avoid differences between node-spellcheck on different platforms
spellings = JSON.parse(fs.readFileSync(__dirname + '/fixtures/california-spelling-lookup.json'))
spyOn(SpellcheckComposerExtension, 'isMisspelled').andCallFake (word) ->
spellings[word]
2016-01-13 11:11:47 +08:00
describe "update", ->
it "correctly walks a DOM tree and surrounds mispelled words", ->
dom = document.createElement('div')
dom.innerHTML = initialHTML
editor =
rootNode: dom
whilePreservingSelection: (cb) -> cb()
2016-01-13 11:11:47 +08:00
SpellcheckComposerExtension.update(editor)
expect(dom.innerHTML).toEqual(expectedHTML)
describe "finalizeSessionBeforeSending", ->
it "removes the annotations it inserted", ->
session =
draft: ->
body: expectedHTML
changes:
add: jasmine.createSpy('add').andReturn Promise.resolve()
waitsForPromise ->
2015-12-31 07:08:33 +08:00
SpellcheckComposerExtension.finalizeSessionBeforeSending({session}).then ->
expect(session.changes.add).toHaveBeenCalledWith(body: initialHTML)
module.exports = SpellcheckComposerExtension