|
|
@@ -15,42 +15,22 @@ describe('SpellingAPIManager', function () {
|
|
|
beforeEach(function () {
|
|
|
this.token = 'user-id-123'
|
|
|
this.ASpell = {}
|
|
|
- this.learnedWords = ['lerned']
|
|
|
- this.LearnedWordsManager = {
|
|
|
- getLearnedWords: sinon.stub().callsArgWith(1, null, this.learnedWords),
|
|
|
- learnWord: sinon.stub().callsArg(2),
|
|
|
- unlearnWord: sinon.stub().callsArg(2),
|
|
|
- promises: {
|
|
|
- getLearnedWords: sinon.stub().returns(promiseStub(this.learnedWords)),
|
|
|
- },
|
|
|
- }
|
|
|
-
|
|
|
this.SpellingAPIManager = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
|
'./ASpell': this.ASpell,
|
|
|
'@overleaf/settings': { ignoredMisspellings: ['ShareLaTeX'] },
|
|
|
- './LearnedWordsManager': this.LearnedWordsManager,
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
|
|
|
describe('runRequest', function () {
|
|
|
beforeEach(function () {
|
|
|
- this.nonLearnedWords = [
|
|
|
- 'some',
|
|
|
- 'words',
|
|
|
- 'htat',
|
|
|
- 'are',
|
|
|
- 'speled',
|
|
|
- 'rong',
|
|
|
- 'lerned',
|
|
|
- ]
|
|
|
- this.allWords = this.nonLearnedWords.concat(this.learnedWords)
|
|
|
+ this.nonLearnedWords = ['some', 'words', 'htat', 'are', 'speled', 'rong']
|
|
|
+ this.allWords = this.nonLearnedWords
|
|
|
this.misspellings = [
|
|
|
{ index: 2, suggestions: ['that'] },
|
|
|
{ index: 4, suggestions: ['spelled'] },
|
|
|
{ index: 5, suggestions: ['wrong', 'ring'] },
|
|
|
- { index: 6, suggestions: ['learned'] },
|
|
|
]
|
|
|
this.misspellingsWithoutLearnedWords = this.misspellings.slice(0, 3)
|
|
|
|
|
|
@@ -99,24 +79,6 @@ describe('SpellingAPIManager', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('with a missing token', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.SpellingAPIManager.runRequest(
|
|
|
- null,
|
|
|
- { words: this.allWords },
|
|
|
- (error, result) => {
|
|
|
- this.error = error
|
|
|
- this.result = result
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should spell check without using any learned words', function () {
|
|
|
- this.LearnedWordsManager.getLearnedWords.called.should.equal(false)
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
describe('without a language', function () {
|
|
|
beforeEach(function (done) {
|
|
|
this.SpellingAPIManager.runRequest(
|
|
|
@@ -158,131 +120,5 @@ describe('SpellingAPIManager', function () {
|
|
|
.should.equal(true)
|
|
|
})
|
|
|
})
|
|
|
-
|
|
|
- describe('with words from the whitelist', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.whitelistWord = this.SpellingAPIManager.whitelist[0]
|
|
|
- this.words = ['One', 'Two', this.whitelistWord]
|
|
|
- this.SpellingAPIManager.runRequest(
|
|
|
- this.token,
|
|
|
- { words: this.words },
|
|
|
- (error, result) => {
|
|
|
- if (error) return done(error)
|
|
|
- this.result = result
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should ignore the white-listed word', function () {
|
|
|
- expect(this.result.misspellings.length).to.equal(
|
|
|
- this.misspellings.length - 1
|
|
|
- )
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('learnWord', function () {
|
|
|
- describe('without a token', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.SpellingAPIManager.learnWord(null, { word: 'banana' }, error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should return an error', function () {
|
|
|
- expect(this.error).to.exist
|
|
|
- expect(this.error).to.be.instanceof(Error)
|
|
|
- expect(this.error.message).to.equal('no token provided')
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('without a word', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.SpellingAPIManager.learnWord(this.token, {}, error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should return an error', function () {
|
|
|
- expect(this.error).to.exist
|
|
|
- expect(this.error).to.be.instanceof(Error)
|
|
|
- expect(this.error.message).to.equal('malformed JSON')
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('with a word and a token', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.word = 'banana'
|
|
|
- this.SpellingAPIManager.learnWord(
|
|
|
- this.token,
|
|
|
- { word: this.word },
|
|
|
- error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should call LearnedWordsManager.learnWord', function () {
|
|
|
- this.LearnedWordsManager.learnWord
|
|
|
- .calledWith(this.token, this.word)
|
|
|
- .should.equal(true)
|
|
|
- })
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('unlearnWord', function () {
|
|
|
- describe('without a token', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.SpellingAPIManager.unlearnWord(null, { word: 'banana' }, error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should return an error', function () {
|
|
|
- expect(this.error).to.exist
|
|
|
- expect(this.error).to.be.instanceof(Error)
|
|
|
- expect(this.error.message).to.equal('no token provided')
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('without a word', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.SpellingAPIManager.unlearnWord(this.token, {}, error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- it('should return an error', function () {
|
|
|
- expect(this.error).to.exist
|
|
|
- expect(this.error).to.be.instanceof(Error)
|
|
|
- expect(this.error.message).to.equal('malformed JSON')
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('with a word and a token', function () {
|
|
|
- beforeEach(function (done) {
|
|
|
- this.word = 'banana'
|
|
|
- this.SpellingAPIManager.unlearnWord(
|
|
|
- this.token,
|
|
|
- { word: this.word },
|
|
|
- error => {
|
|
|
- this.error = error
|
|
|
- done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should call LearnedWordsManager.unlearnWord', function () {
|
|
|
- this.LearnedWordsManager.unlearnWord
|
|
|
- .calledWith(this.token, this.word)
|
|
|
- .should.equal(true)
|
|
|
- })
|
|
|
- })
|
|
|
})
|
|
|
})
|