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