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]
|
|
|
|
|
|
|
|
describe "walkTree", ->
|
|
|
|
it "correctly walks a DOM tree and surrounds mispelled words", ->
|
|
|
|
dom = document.createElement('div')
|
|
|
|
dom.innerHTML = initialHTML
|
2015-11-28 03:49:24 +08:00
|
|
|
SpellcheckComposerExtension.walkTree(dom)
|
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:
|
|
|
|
add: jasmine.createSpy('add')
|
|
|
|
|
2015-11-28 03:49:24 +08:00
|
|
|
SpellcheckComposerExtension.finalizeSessionBeforeSending(session)
|
2015-09-03 04:20:01 +08:00
|
|
|
expect(session.changes.add).toHaveBeenCalledWith(body: initialHTML)
|
|
|
|
|
2015-11-28 03:49:24 +08:00
|
|
|
module.exports = SpellcheckComposerExtension
|