Keybuilder.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { beforeEach, describe, expect, it, vi } from 'vitest'
  2. const modulePath = '../../../app/js/KeyBuilder.js'
  3. describe('KeybuilderTests', function () {
  4. let KeyBuilder
  5. const key = 'wombat/potato'
  6. beforeEach(async function () {
  7. vi.doMock('@overleaf/settings', () => ({
  8. default: {},
  9. }))
  10. KeyBuilder = (await import(modulePath)).default
  11. })
  12. describe('cachedKey', function () {
  13. it('should add the format to the key', function () {
  14. const opts = { format: 'png' }
  15. const newKey = KeyBuilder.addCachingToKey(key, opts)
  16. expect(newKey).to.equal(`${key}-converted-cache/format-png`)
  17. })
  18. it('should add the style to the key', function () {
  19. const opts = { style: 'thumbnail' }
  20. const newKey = KeyBuilder.addCachingToKey(key, opts)
  21. expect(newKey).to.equal(`${key}-converted-cache/style-thumbnail`)
  22. })
  23. it('should add format first, then style', function () {
  24. const opts = {
  25. style: 'thumbnail',
  26. format: 'png',
  27. }
  28. const newKey = KeyBuilder.addCachingToKey(key, opts)
  29. expect(newKey).to.equal(
  30. `${key}-converted-cache/format-png-style-thumbnail`
  31. )
  32. })
  33. })
  34. })