FileConverterTests.coffee 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. assert = require("chai").assert
  2. sinon = require('sinon')
  3. chai = require('chai')
  4. should = chai.should()
  5. expect = chai.expect
  6. modulePath = "../../../app/js/FileConverter.js"
  7. SandboxedModule = require('sandboxed-module')
  8. describe "FileConverter", ->
  9. beforeEach ->
  10. @easyimage =
  11. convert:sinon.stub()
  12. exec: sinon.stub()
  13. @converter = SandboxedModule.require modulePath, requires:
  14. "easyimage":@easyimage
  15. "logger-sharelatex":
  16. log:->
  17. err:->
  18. @sourcePath = "/this/path/here.eps"
  19. @format = "png"
  20. @error = "Error"
  21. describe "convert", ->
  22. it "should convert the source to the requested format", (done)->
  23. @easyimage.convert.callsArgWith(1)
  24. @converter.convert @sourcePath, @format, (err)=>
  25. args = @easyimage.convert.args[0][0]
  26. args.src.should.equal @sourcePath+"[0]"
  27. args.dst.should.equal "#{@sourcePath}.#{@format}"
  28. done()
  29. it "should return the dest path", (done)->
  30. @easyimage.convert.callsArgWith(1)
  31. @converter.convert @sourcePath, @format, (err, destPath)=>
  32. destPath.should.equal "#{@sourcePath}.#{@format}"
  33. done()
  34. it "should return the error from convert", (done)->
  35. @easyimage.convert.callsArgWith(1, @error)
  36. @converter.convert @sourcePath, @format, (err)=>
  37. err.should.equal @error
  38. done()
  39. it "should not accapt an non aproved format", (done)->
  40. @easyimage.convert.callsArgWith(1)
  41. @converter.convert @sourcePath, "ahhhhh", (err)=>
  42. expect(err).to.exist
  43. done()
  44. describe "thumbnail", ->
  45. it "should call easy image resize with args", (done)->
  46. @easyimage.exec.callsArgWith(1)
  47. @converter.thumbnail @sourcePath, (err)=>
  48. args = @easyimage.exec.args[0][0]
  49. args.indexOf(@sourcePath).should.not.equal -1
  50. done()
  51. it "should compress the png", ()->
  52. describe "preview", ->
  53. it "should call easy image resize with args", (done)->
  54. @easyimage.exec.callsArgWith(1)
  55. @converter.preview @sourcePath, (err)=>
  56. args = @easyimage.exec.args[0][0]
  57. args.indexOf(@sourcePath).should.not.equal -1
  58. done()