diff --git a/spec/util/urlUtils-spec.js b/spec/util/urlUtils-spec.js index 2e4cf37a7..f5737f589 100644 --- a/spec/util/urlUtils-spec.js +++ b/spec/util/urlUtils-spec.js @@ -1,12 +1,9 @@ const { constructSheetUrl, getDocumentOrSheetId, getSheetName } = require('../../src/util/urlUtils') -const config = require('../../src/config') const queryParams = require('../../src/util/queryParamProcessor') -jest.mock('../../src/config') jest.mock('../../src/util/queryParamProcessor') describe('Url Utils', () => { it('should construct the sheet url', () => { - config.mockReturnValue({ featureToggles: { UIRefresh2022: true } }) queryParams.mockReturnValue({ documentId: 'documentId' }) delete window.location window.location = Object.create(window) @@ -15,12 +12,10 @@ describe('Url Utils', () => { const sheetUrl = constructSheetUrl('radar') expect(sheetUrl).toStrictEqual('https://thoughtworks.com/radar?documentId=documentId&sheetName=radar') - expect(config).toHaveBeenCalledTimes(1) expect(queryParams).toHaveBeenCalledTimes(1) }) - it('should construct the sheet url for old view', () => { - config.mockReturnValue({ featureToggles: { UIRefresh2022: false } }) + it('should construct the sheet url if sheetId is used', () => { queryParams.mockReturnValue({ sheetId: 'sheetId' }) delete window.location window.location = Object.create(window) @@ -29,7 +24,6 @@ describe('Url Utils', () => { const sheetUrl = constructSheetUrl('radar') expect(sheetUrl).toStrictEqual('https://thoughtworks.com/radar?sheetId=sheetId&sheetName=radar') - expect(config).toHaveBeenCalledTimes(1) expect(queryParams).toHaveBeenCalledTimes(1) }) diff --git a/src/util/urlUtils.js b/src/util/urlUtils.js index dd2d6cfa4..cb46d2267 100644 --- a/src/util/urlUtils.js +++ b/src/util/urlUtils.js @@ -1,13 +1,14 @@ const QueryParams = require('../util/queryParamProcessor') -const config = require('../config') + function constructSheetUrl(sheetName) { const noParamsUrl = window.location.href.substring(0, window.location.href.indexOf(window.location.search)) const queryParams = QueryParams(window.location.search.substring(1)) const sheetUrl = noParamsUrl + - (config().featureToggles.UIRefresh2022 - ? '?documentId=' + queryParams.documentId - : '?sheetId=' + queryParams.sheetId) + + '?' + + ((queryParams.documentId && `documentId=${encodeURIComponent(queryParams.documentId)}`) || + (queryParams.sheetId && `sheetId=${encodeURIComponent(queryParams.sheetId)}`) || + '') + '&sheetName=' + encodeURIComponent(sheetName) return sheetUrl