mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-08 15:42:34 +00:00
remove js tests
This commit is contained in:
parent
35254be989
commit
536e014600
4 changed files with 1 additions and 419 deletions
1
services/spelling/.gitignore
vendored
1
services/spelling/.gitignore
vendored
|
@ -4,3 +4,4 @@ app/js/*
|
|||
app.js
|
||||
test/UnitTests/js/*
|
||||
node_modules/*
|
||||
test/unit/js/
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
(function() {
|
||||
var chai, should, sinon;
|
||||
|
||||
sinon = require('sinon');
|
||||
|
||||
chai = require('chai');
|
||||
|
||||
should = chai.should();
|
||||
|
||||
describe("ASpell", function() {
|
||||
beforeEach(function() {
|
||||
return this.ASpell = require("../../../app/js/ASpell");
|
||||
});
|
||||
describe("a correctly spelled word", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.ASpell.checkWords("en", ["word"], (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should not correct the word", function() {
|
||||
return this.result.length.should.equal(0);
|
||||
});
|
||||
});
|
||||
describe("a misspelled word", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.ASpell.checkWords("en", ["bussines"], (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should correct the word", function() {
|
||||
this.result.length.should.equal(1);
|
||||
return this.result[0].suggestions.indexOf("business").should.not.equal(-1);
|
||||
});
|
||||
});
|
||||
describe("multiple words", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.ASpell.checkWords("en", ["bussines", "word", "neccesary"], (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should correct the incorrect words", function() {
|
||||
this.result[0].index.should.equal(0);
|
||||
this.result[0].suggestions.indexOf("business").should.not.equal(-1);
|
||||
this.result[1].index.should.equal(2);
|
||||
return this.result[1].suggestions.indexOf("necessary").should.not.equal(-1);
|
||||
});
|
||||
});
|
||||
describe("without a valid language", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.ASpell.checkWords("notALang", ["banana"], (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.error = error;
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return an error", function() {
|
||||
return should.exist(this.error);
|
||||
});
|
||||
});
|
||||
describe("when there are no suggestions", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.ASpell.checkWords("en", ["asdkfjalkdjfadhfkajsdhfashdfjhadflkjadhflajsd"], (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.error = error;
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return a blank array", function() {
|
||||
this.result.length.should.equal(1);
|
||||
return this.result[0].suggestions.should.deep.equal([]);
|
||||
});
|
||||
});
|
||||
return describe("when the request times out", function() {
|
||||
beforeEach(function(done) {
|
||||
var i, words;
|
||||
words = (function() {
|
||||
var _i, _results;
|
||||
_results = [];
|
||||
for (i = _i = 0; _i <= 1000000; i = ++_i) {
|
||||
_results.push("abcdefg");
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
this.ASpell.ASPELL_TIMEOUT = 100;
|
||||
this.start = new Date();
|
||||
return this.ASpell.checkWords("en", words, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return in reasonable time", function(done) {
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
|
@ -1,99 +0,0 @@
|
|||
(function() {
|
||||
var SandboxedModule, chai, expect, modulePath, sinon;
|
||||
|
||||
sinon = require('sinon');
|
||||
|
||||
chai = require('chai');
|
||||
|
||||
expect = chai.expect;
|
||||
|
||||
SandboxedModule = require('sandboxed-module');
|
||||
|
||||
modulePath = require('path').join(__dirname, '../../../app/js/LearnedWordsManager');
|
||||
|
||||
describe("LearnedWordsManager", function() {
|
||||
beforeEach(function() {
|
||||
this.token = "a6b3cd919ge";
|
||||
this.callback = sinon.stub();
|
||||
this.db = {
|
||||
spellingPreferences: {
|
||||
update: sinon.stub().callsArg(3)
|
||||
}
|
||||
};
|
||||
return this.LearnedWordsManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
"./DB": this.db
|
||||
}
|
||||
});
|
||||
});
|
||||
describe("learnWord", function() {
|
||||
beforeEach(function() {
|
||||
this.word = "instanton";
|
||||
return this.LearnedWordsManager.learnWord(this.token, this.word, this.callback);
|
||||
});
|
||||
it("should insert the word in the word list in the database", function() {
|
||||
return expect(this.db.spellingPreferences.update.calledWith({
|
||||
token: this.token
|
||||
}, {
|
||||
$push: {
|
||||
learnedWords: this.word
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
})).to.equal(true);
|
||||
});
|
||||
return it("should call the callback", function() {
|
||||
return expect(this.callback.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
return describe("getLearnedWords", function() {
|
||||
beforeEach(function() {
|
||||
this.wordList = ["apples", "bananas", "pears"];
|
||||
this.db.spellingPreferences.findOne = (function(_this) {
|
||||
return function(conditions, callback) {
|
||||
return callback(null, {
|
||||
learnedWords: _this.wordList
|
||||
});
|
||||
};
|
||||
})(this);
|
||||
sinon.spy(this.db.spellingPreferences, "findOne");
|
||||
return this.LearnedWordsManager.getLearnedWords(this.token, this.callback);
|
||||
});
|
||||
it("should get the word list for the given user", function() {
|
||||
return expect(this.db.spellingPreferences.findOne.calledWith({
|
||||
token: this.token
|
||||
})).to.equal(true);
|
||||
});
|
||||
return it("should return the word list in the callback", function() {
|
||||
return expect(this.callback.calledWith(null, this.wordList)).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
describe "caching the result", ->
|
||||
it 'should use the cache first if it is primed', (done)->
|
||||
@wordList = ["apples", "bananas", "pears"]
|
||||
@cache.get.callsArgWith(1, null, learnedWords: @wordList)
|
||||
@db.spellingPreferences.findOne = sinon.stub()
|
||||
@LearnedWordsManager.getLearnedWords @token, (err, spellings)=>
|
||||
@db.spellingPreferences.find.called.should.equal false
|
||||
@wordList.should.equal spellings
|
||||
done()
|
||||
|
||||
it 'should set the cache after hitting the db', (done)->
|
||||
@wordList = ["apples", "bananas", "pears"]
|
||||
@cache.get.callsArgWith(1)
|
||||
@db.spellingPreferences.findOne = sinon.stub().callsArgWith(1, null, learnedWords: @wordList)
|
||||
@LearnedWordsManager.getLearnedWords @token, (err, spellings)=>
|
||||
@cache.set.calledWith(@token, learnedWords:@wordList).should.equal true
|
||||
done()
|
||||
|
||||
it 'should break cache when update is called', (done)->
|
||||
@word = "instanton"
|
||||
@LearnedWordsManager.learnWord @token, @word, =>
|
||||
@cache.break.calledWith(@token).should.equal true
|
||||
done()
|
||||
*/
|
||||
});
|
||||
|
||||
}).call(this);
|
|
@ -1,208 +0,0 @@
|
|||
(function() {
|
||||
var SandboxedModule, chai, expect, modulePath, sinon;
|
||||
|
||||
sinon = require('sinon');
|
||||
|
||||
chai = require('chai');
|
||||
|
||||
expect = chai.expect;
|
||||
|
||||
chai.should();
|
||||
|
||||
SandboxedModule = require('sandboxed-module');
|
||||
|
||||
modulePath = require('path').join(__dirname, '../../../app/js/SpellingAPIManager');
|
||||
|
||||
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)
|
||||
};
|
||||
return this.SpellingAPIManager = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
"./ASpell": this.ASpell,
|
||||
"./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.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);
|
||||
this.ASpell.checkWords = (function(_this) {
|
||||
return function(lang, word, callback) {
|
||||
return callback(null, _this.misspellings);
|
||||
};
|
||||
})(this);
|
||||
return sinon.spy(this.ASpell, "checkWords");
|
||||
});
|
||||
describe("with sensible JSON", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.runRequest(this.token, {
|
||||
words: this.allWords
|
||||
}, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return the words that are spelled incorrectly and not learned", function() {
|
||||
return expect(this.result.misspellings).to.deep.equal(this.misspellingsWithoutLearnedWords);
|
||||
});
|
||||
});
|
||||
describe("with a missing words array", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.runRequest(this.token, {}, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.error = error;
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return an error", function() {
|
||||
return expect(this.error).to.deep.equal(new Error("malformed JSON"));
|
||||
});
|
||||
});
|
||||
describe("with a missing token", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.runRequest(null, {
|
||||
words: this.allWords
|
||||
}, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.error = error;
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should spell check without using any learned words", function() {
|
||||
return this.LearnedWordsManager.getLearnedWords.called.should.equal(false);
|
||||
});
|
||||
});
|
||||
describe("without a language", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.runRequest(this.token, {
|
||||
words: this.allWords
|
||||
}, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should use en as the default", function() {
|
||||
return this.ASpell.checkWords.calledWith("en").should.equal(true);
|
||||
});
|
||||
});
|
||||
describe("with a language", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.runRequest(this.token, {
|
||||
words: this.allWords,
|
||||
language: this.language = "fr"
|
||||
}, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should use the language", function() {
|
||||
return this.ASpell.checkWords.calledWith(this.language).should.equal(true);
|
||||
});
|
||||
});
|
||||
return describe("with a very large collection of words", function() {
|
||||
beforeEach(function(done) {
|
||||
var i;
|
||||
this.manyWords = (function() {
|
||||
var _i, _results;
|
||||
_results = [];
|
||||
for (i = _i = 1; _i <= 100000; i = ++_i) {
|
||||
_results.push("word");
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return this.SpellingAPIManager.runRequest(this.token, {
|
||||
words: this.manyWords
|
||||
}, (function(_this) {
|
||||
return function(error, result) {
|
||||
_this.result = result;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should truncate to 10,000 words", function() {
|
||||
return this.ASpell.checkWords.calledWith(sinon.match.any, this.manyWords.slice(0, 10000)).should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
return describe("learnWord", function() {
|
||||
describe("without a token", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.learnWord(null, {
|
||||
word: "banana"
|
||||
}, (function(_this) {
|
||||
return function(error) {
|
||||
_this.error = error;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return an error", function() {
|
||||
return expect(this.error).to.deep.equal(new Error("malformed JSON"));
|
||||
});
|
||||
});
|
||||
describe("without a word", function() {
|
||||
beforeEach(function(done) {
|
||||
return this.SpellingAPIManager.learnWord(this.token, {}, (function(_this) {
|
||||
return function(error) {
|
||||
_this.error = error;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should return an error", function() {
|
||||
return expect(this.error).to.deep.equal(new Error("no token provided"));
|
||||
});
|
||||
});
|
||||
return describe("with a word and a token", function() {
|
||||
beforeEach(function(done) {
|
||||
this.word = "banana";
|
||||
return this.SpellingAPIManager.learnWord(this.token, {
|
||||
word: this.word
|
||||
}, (function(_this) {
|
||||
return function(error) {
|
||||
_this.error = error;
|
||||
return done();
|
||||
};
|
||||
})(this));
|
||||
});
|
||||
return it("should call LearnedWordsManager.learnWord", function() {
|
||||
return this.LearnedWordsManager.learnWord.calledWith(this.token, this.word).should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
Loading…
Add table
Reference in a new issue