2014-08-15 07:13:35 -04:00
|
|
|
sinon = require 'sinon'
|
|
|
|
chai = require 'chai'
|
|
|
|
should = chai.should()
|
2015-03-03 09:25:54 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require("chai").assert
|
2014-08-15 07:13:35 -04:00
|
|
|
|
|
|
|
describe "ASpell", ->
|
|
|
|
beforeEach ->
|
2015-03-03 09:25:54 -05:00
|
|
|
@ASpell = SandboxedModule.require "../../../app/js/ASpell", requires:{}
|
2014-08-15 07:13:35 -04:00
|
|
|
|
|
|
|
describe "a correctly spelled word", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ASpell.checkWords "en", ["word"], (error, @result) => done()
|
|
|
|
|
|
|
|
it "should not correct the word", ->
|
|
|
|
@result.length.should.equal 0
|
|
|
|
|
|
|
|
describe "a misspelled word", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ASpell.checkWords "en", ["bussines"], (error, @result) => done()
|
|
|
|
|
|
|
|
it "should correct the word", ->
|
|
|
|
@result.length.should.equal 1
|
|
|
|
@result[0].suggestions.indexOf("business").should.not.equal -1
|
|
|
|
|
|
|
|
describe "multiple words", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ASpell.checkWords "en", ["bussines", "word", "neccesary"], (error, @result) => done()
|
|
|
|
|
|
|
|
it "should correct the incorrect words", ->
|
|
|
|
@result[0].index.should.equal 0
|
|
|
|
@result[0].suggestions.indexOf("business").should.not.equal -1
|
|
|
|
@result[1].index.should.equal 2
|
|
|
|
@result[1].suggestions.indexOf("necessary").should.not.equal -1
|
|
|
|
|
|
|
|
describe "without a valid language", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ASpell.checkWords "notALang", ["banana"], (@error, @result) => done()
|
|
|
|
|
|
|
|
it "should return an error", ->
|
|
|
|
should.exist @error
|
|
|
|
|
|
|
|
describe "when there are no suggestions", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ASpell.checkWords "en", ["asdkfjalkdjfadhfkajsdhfashdfjhadflkjadhflajsd"], (@error, @result) => done()
|
|
|
|
|
|
|
|
it "should return a blank array", ->
|
|
|
|
@result.length.should.equal 1
|
2015-03-03 09:25:54 -05:00
|
|
|
assert.deepEqual @result[0].suggestions, []
|
2014-08-15 07:13:35 -04:00
|
|
|
|
|
|
|
describe "when the request times out", ->
|
|
|
|
beforeEach (done) ->
|
2015-03-03 09:25:54 -05:00
|
|
|
words = ("abcdefg" for i in [0..1000])
|
2015-03-04 11:44:13 -05:00
|
|
|
@ASpell.ASPELL_TIMEOUT = 1
|
|
|
|
@start = Date.now()
|
2014-08-15 07:13:35 -04:00
|
|
|
@ASpell.checkWords "en", words, (error, @result) => done()
|
|
|
|
|
|
|
|
it "should return in reasonable time", (done) ->
|
2015-03-04 11:44:13 -05:00
|
|
|
delta = Date.now()-@start
|
|
|
|
delta.should.be.below(@ASpell.ASPELL_TIMEOUT + 10)
|
2014-08-15 07:13:35 -04:00
|
|
|
done()
|