| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- /* eslint-disable
- handle-callback-err,
- max-len,
- no-return-assign,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS101: Remove unnecessary use of Array.from
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- const sinon = require('sinon')
- const chai = require('chai')
- const should = chai.should()
- const { expect } = chai
- const modulePath = '../../../../app/src/Features/Compile/ClsiStateManager.js'
- const SandboxedModule = require('sandboxed-module')
- describe('ClsiStateManager', function() {
- beforeEach(function() {
- this.ClsiStateManager = SandboxedModule.require(modulePath, {
- globals: {
- console: console
- },
- requires: {
- 'settings-sharelatex': (this.settings = {}),
- '../Project/ProjectEntityHandler': (this.ProjectEntityHandler = {}),
- 'logger-sharelatex': (this.logger = {
- log: sinon.stub(),
- error: sinon.stub(),
- warn: sinon.stub()
- })
- }
- })
- this.project = 'project'
- this.options = { draft: true, isAutoCompile: false }
- return (this.callback = sinon.stub())
- })
- describe('computeHash', function() {
- beforeEach(function(done) {
- this.docs = [
- { path: '/main.tex', doc: { _id: 'doc-id-1' } },
- { path: '/folder/sub.tex', doc: { _id: 'doc-id-2' } }
- ]
- this.files = [
- {
- path: '/figure.pdf',
- file: { _id: 'file-id-1', rev: 123, created: 'aaaaaa' }
- },
- {
- path: '/folder/fig2.pdf',
- file: { _id: 'file-id-2', rev: 456, created: 'bbbbbb' }
- }
- ]
- this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
- .stub()
- .callsArgWith(1, null, this.docs, this.files)
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash0 = hash
- return done()
- }
- )
- })
- describe('with a sample project', function() {
- beforeEach(function() {
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- this.callback
- )
- })
- it('should call the callback with a hash value', function() {
- return this.callback
- .calledWith(null, '21b1ab73aa3892bec452baf8ffa0956179e1880f')
- .should.equal(true)
- })
- })
- describe('when the files and docs are in a different order', function() {
- beforeEach(function() {
- ;[this.docs[0], this.docs[1]] = Array.from([this.docs[1], this.docs[0]])
- ;[this.files[0], this.files[1]] = Array.from([
- this.files[1],
- this.files[0]
- ])
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- this.callback
- )
- })
- it('should call the callback with the same hash value', function() {
- return this.callback.calledWith(null, this.hash0).should.equal(true)
- })
- })
- describe('when a doc is renamed', function() {
- beforeEach(function(done) {
- this.docs[0].path = '/new.tex'
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when a file is renamed', function() {
- beforeEach(function(done) {
- this.files[0].path = '/newfigure.pdf'
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when a doc is added', function() {
- beforeEach(function(done) {
- this.docs.push({ path: '/newdoc.tex', doc: { _id: 'newdoc-id' } })
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when a file is added', function() {
- beforeEach(function(done) {
- this.files.push({
- path: '/newfile.tex',
- file: { _id: 'newfile-id', rev: 123 }
- })
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when a doc is removed', function() {
- beforeEach(function(done) {
- this.docs.pop()
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when a file is removed', function() {
- beforeEach(function(done) {
- this.files.pop()
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe("when a file's revision is updated", function() {
- beforeEach(function(done) {
- this.files[0].file.rev++
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe("when a file's date is updated", function() {
- beforeEach(function(done) {
- this.files[0].file.created = 'zzzzzz'
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when the compile options are changed', function() {
- beforeEach(function(done) {
- this.options.draft = !this.options.draft
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- (err, hash) => {
- this.hash1 = hash
- return done()
- }
- )
- })
- it('should call the callback with a different hash value', function() {
- return this.callback
- .neverCalledWith(null, this.hash0)
- .should.equal(true)
- })
- })
- describe('when the isAutoCompile option is changed', function() {
- beforeEach(function() {
- this.options.isAutoCompile = !this.options.isAutoCompile
- return this.ClsiStateManager.computeHash(
- this.project,
- this.options,
- this.callback
- )
- })
- it('should call the callback with the same hash value', function() {
- return this.callback.calledWith(null, this.hash0).should.equal(true)
- })
- })
- })
- })
|