url-helper.test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { expect } from 'chai'
  2. import sinon from 'sinon'
  3. import { buildUrlWithDetachRole } from '../../../../frontend/js/shared/utils/url-helper'
  4. describe('url-helper', function () {
  5. let locationStub
  6. describe('buildUrlWithDetachRole', function () {
  7. beforeEach(function () {
  8. locationStub = sinon.stub(window, 'location')
  9. })
  10. afterEach(function () {
  11. locationStub.restore()
  12. })
  13. describe('without mode', function () {
  14. it('removes trailing slash', function () {
  15. locationStub.value('https://www.ovelreaf.com/project/1abc/')
  16. expect(buildUrlWithDetachRole().href).to.equal(
  17. 'https://www.ovelreaf.com/project/1abc'
  18. )
  19. })
  20. it('clears the mode from the current URL', function () {
  21. locationStub.value('https://www.ovelreaf.com/project/2abc/detached')
  22. expect(buildUrlWithDetachRole().href).to.equal(
  23. 'https://www.ovelreaf.com/project/2abc'
  24. )
  25. locationStub.value('https://www.ovelreaf.com/project/2abc/detacher/')
  26. expect(buildUrlWithDetachRole().href).to.equal(
  27. 'https://www.ovelreaf.com/project/2abc'
  28. )
  29. })
  30. })
  31. describe('with mode', function () {
  32. it('handles with trailing slash', function () {
  33. locationStub.value('https://www.ovelreaf.com/project/3abc/')
  34. expect(buildUrlWithDetachRole('detacher').href).to.equal(
  35. 'https://www.ovelreaf.com/project/3abc/detacher'
  36. )
  37. })
  38. it('handles without trailing slash', function () {
  39. locationStub.value('https://www.ovelreaf.com/project/4abc')
  40. expect(buildUrlWithDetachRole('detached').href).to.equal(
  41. 'https://www.ovelreaf.com/project/4abc/detached'
  42. )
  43. })
  44. })
  45. })
  46. })