ClsiStateManagerTests.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /* eslint-disable
  2. node/handle-callback-err,
  3. max-len,
  4. no-return-assign,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS101: Remove unnecessary use of Array.from
  12. * DS102: Remove unnecessary code created because of implicit returns
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. const sinon = require('sinon')
  16. const { expect } = require('chai')
  17. const modulePath = '../../../../app/src/Features/Compile/ClsiStateManager.js'
  18. const SandboxedModule = require('sandboxed-module')
  19. describe('ClsiStateManager', function () {
  20. beforeEach(function () {
  21. this.ClsiStateManager = SandboxedModule.require(modulePath, {
  22. requires: {
  23. 'settings-sharelatex': (this.settings = {}),
  24. '../Project/ProjectEntityHandler': (this.ProjectEntityHandler = {}),
  25. },
  26. })
  27. this.project = 'project'
  28. this.options = { draft: true, isAutoCompile: false }
  29. return (this.callback = sinon.stub())
  30. })
  31. describe('computeHash', function () {
  32. beforeEach(function (done) {
  33. this.docs = [
  34. { path: '/main.tex', doc: { _id: 'doc-id-1' } },
  35. { path: '/folder/sub.tex', doc: { _id: 'doc-id-2' } },
  36. ]
  37. this.files = [
  38. {
  39. path: '/figure.pdf',
  40. file: { _id: 'file-id-1', rev: 123, created: 'aaaaaa' },
  41. },
  42. {
  43. path: '/folder/fig2.pdf',
  44. file: { _id: 'file-id-2', rev: 456, created: 'bbbbbb' },
  45. },
  46. ]
  47. this.ProjectEntityHandler.getAllEntitiesFromProject = sinon
  48. .stub()
  49. .callsArgWith(1, null, this.docs, this.files)
  50. return this.ClsiStateManager.computeHash(
  51. this.project,
  52. this.options,
  53. (err, hash) => {
  54. this.hash0 = hash
  55. return done()
  56. }
  57. )
  58. })
  59. describe('with a sample project', function () {
  60. beforeEach(function () {
  61. return this.ClsiStateManager.computeHash(
  62. this.project,
  63. this.options,
  64. this.callback
  65. )
  66. })
  67. it('should call the callback with a hash value', function () {
  68. return this.callback
  69. .calledWith(null, '21b1ab73aa3892bec452baf8ffa0956179e1880f')
  70. .should.equal(true)
  71. })
  72. })
  73. describe('when the files and docs are in a different order', function () {
  74. beforeEach(function () {
  75. ;[this.docs[0], this.docs[1]] = Array.from([this.docs[1], this.docs[0]])
  76. ;[this.files[0], this.files[1]] = Array.from([
  77. this.files[1],
  78. this.files[0],
  79. ])
  80. return this.ClsiStateManager.computeHash(
  81. this.project,
  82. this.options,
  83. this.callback
  84. )
  85. })
  86. it('should call the callback with the same hash value', function () {
  87. return this.callback.calledWith(null, this.hash0).should.equal(true)
  88. })
  89. })
  90. describe('when a doc is renamed', function () {
  91. beforeEach(function (done) {
  92. this.docs[0].path = '/new.tex'
  93. return this.ClsiStateManager.computeHash(
  94. this.project,
  95. this.options,
  96. (err, hash) => {
  97. this.hash1 = hash
  98. return done()
  99. }
  100. )
  101. })
  102. it('should call the callback with a different hash value', function () {
  103. return this.callback
  104. .neverCalledWith(null, this.hash0)
  105. .should.equal(true)
  106. })
  107. })
  108. describe('when a file is renamed', function () {
  109. beforeEach(function (done) {
  110. this.files[0].path = '/newfigure.pdf'
  111. return this.ClsiStateManager.computeHash(
  112. this.project,
  113. this.options,
  114. (err, hash) => {
  115. this.hash1 = hash
  116. return done()
  117. }
  118. )
  119. })
  120. it('should call the callback with a different hash value', function () {
  121. return this.callback
  122. .neverCalledWith(null, this.hash0)
  123. .should.equal(true)
  124. })
  125. })
  126. describe('when a doc is added', function () {
  127. beforeEach(function (done) {
  128. this.docs.push({ path: '/newdoc.tex', doc: { _id: 'newdoc-id' } })
  129. return this.ClsiStateManager.computeHash(
  130. this.project,
  131. this.options,
  132. (err, hash) => {
  133. this.hash1 = hash
  134. return done()
  135. }
  136. )
  137. })
  138. it('should call the callback with a different hash value', function () {
  139. return this.callback
  140. .neverCalledWith(null, this.hash0)
  141. .should.equal(true)
  142. })
  143. })
  144. describe('when a file is added', function () {
  145. beforeEach(function (done) {
  146. this.files.push({
  147. path: '/newfile.tex',
  148. file: { _id: 'newfile-id', rev: 123 },
  149. })
  150. return this.ClsiStateManager.computeHash(
  151. this.project,
  152. this.options,
  153. (err, hash) => {
  154. this.hash1 = hash
  155. return done()
  156. }
  157. )
  158. })
  159. it('should call the callback with a different hash value', function () {
  160. return this.callback
  161. .neverCalledWith(null, this.hash0)
  162. .should.equal(true)
  163. })
  164. })
  165. describe('when a doc is removed', function () {
  166. beforeEach(function (done) {
  167. this.docs.pop()
  168. return this.ClsiStateManager.computeHash(
  169. this.project,
  170. this.options,
  171. (err, hash) => {
  172. this.hash1 = hash
  173. return done()
  174. }
  175. )
  176. })
  177. it('should call the callback with a different hash value', function () {
  178. return this.callback
  179. .neverCalledWith(null, this.hash0)
  180. .should.equal(true)
  181. })
  182. })
  183. describe('when a file is removed', function () {
  184. beforeEach(function (done) {
  185. this.files.pop()
  186. return this.ClsiStateManager.computeHash(
  187. this.project,
  188. this.options,
  189. (err, hash) => {
  190. this.hash1 = hash
  191. return done()
  192. }
  193. )
  194. })
  195. it('should call the callback with a different hash value', function () {
  196. return this.callback
  197. .neverCalledWith(null, this.hash0)
  198. .should.equal(true)
  199. })
  200. })
  201. describe("when a file's revision is updated", function () {
  202. beforeEach(function (done) {
  203. this.files[0].file.rev++
  204. return this.ClsiStateManager.computeHash(
  205. this.project,
  206. this.options,
  207. (err, hash) => {
  208. this.hash1 = hash
  209. return done()
  210. }
  211. )
  212. })
  213. it('should call the callback with a different hash value', function () {
  214. return this.callback
  215. .neverCalledWith(null, this.hash0)
  216. .should.equal(true)
  217. })
  218. })
  219. describe("when a file's date is updated", function () {
  220. beforeEach(function (done) {
  221. this.files[0].file.created = 'zzzzzz'
  222. return this.ClsiStateManager.computeHash(
  223. this.project,
  224. this.options,
  225. (err, hash) => {
  226. this.hash1 = hash
  227. return done()
  228. }
  229. )
  230. })
  231. it('should call the callback with a different hash value', function () {
  232. return this.callback
  233. .neverCalledWith(null, this.hash0)
  234. .should.equal(true)
  235. })
  236. })
  237. describe('when the compile options are changed', function () {
  238. beforeEach(function (done) {
  239. this.options.draft = !this.options.draft
  240. return this.ClsiStateManager.computeHash(
  241. this.project,
  242. this.options,
  243. (err, hash) => {
  244. this.hash1 = hash
  245. return done()
  246. }
  247. )
  248. })
  249. it('should call the callback with a different hash value', function () {
  250. return this.callback
  251. .neverCalledWith(null, this.hash0)
  252. .should.equal(true)
  253. })
  254. })
  255. describe('when the isAutoCompile option is changed', function () {
  256. beforeEach(function () {
  257. this.options.isAutoCompile = !this.options.isAutoCompile
  258. return this.ClsiStateManager.computeHash(
  259. this.project,
  260. this.options,
  261. this.callback
  262. )
  263. })
  264. it('should call the callback with the same hash value', function () {
  265. return this.callback.calledWith(null, this.hash0).should.equal(true)
  266. })
  267. })
  268. })
  269. })