Skip to content

Commit

Permalink
[Devansh] Fix alternative sheets behvaiour for sheetId query param
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-sharma-tw committed Sep 6, 2023
1 parent 50e87f9 commit 6a9088e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
8 changes: 1 addition & 7 deletions spec/util/urlUtils-spec.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
})

Expand Down
9 changes: 5 additions & 4 deletions src/util/urlUtils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6a9088e

Please sign in to comment.