url-helper.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { expect } from 'chai'
  2. import { cleanURL } from '@/shared/utils/url-helper'
  3. describe('url-helper', function () {
  4. describe('cleanURL', function () {
  5. describe('without mode', function () {
  6. it('removes trailing slash', function () {
  7. const url = new URL('https://www.ovelreaf.com/project/1abc/')
  8. expect(cleanURL(url).href).to.equal(
  9. 'https://www.ovelreaf.com/project/1abc'
  10. )
  11. })
  12. it('clears the mode from the detached URL', function () {
  13. const url = new URL('https://www.ovelreaf.com/project/2abc/detached')
  14. expect(cleanURL(url).href).to.equal(
  15. 'https://www.ovelreaf.com/project/2abc'
  16. )
  17. })
  18. it('clears the mode from the detacher URL', function () {
  19. const url = new URL('https://www.ovelreaf.com/project/2abc/detacher/')
  20. expect(cleanURL(url).href).to.equal(
  21. 'https://www.ovelreaf.com/project/2abc'
  22. )
  23. })
  24. })
  25. describe('with mode', function () {
  26. it('handles with trailing slash', function () {
  27. const url = new URL('https://www.ovelreaf.com/project/3abc/')
  28. expect(cleanURL(url, 'detacher').href).to.equal(
  29. 'https://www.ovelreaf.com/project/3abc/detacher'
  30. )
  31. })
  32. it('handles without trailing slash', function () {
  33. const url = new URL('https://www.ovelreaf.com/project/4abc')
  34. expect(cleanURL(url, 'detached').href).to.equal(
  35. 'https://www.ovelreaf.com/project/4abc/detached'
  36. )
  37. })
  38. })
  39. })
  40. })