Skip to content

Commit

Permalink
[DTRA] Maryia/WEBREL-2551/hotfix: restore logic of redirecting back t…
Browse files Browse the repository at this point in the history
…o other pages by using history.replaceState for DTrader URL (deriv-com#13921)

* fix: use history.replaceState to keep routing history

* test: packages/shared/src/utils/contract/__tests__/trade-url-params-config.spec.ts
  • Loading branch information
maryia-deriv committed Feb 29, 2024
1 parent fce7122 commit 8b57c94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,36 @@ describe('setTradeURLParams', () => {
});

it('should set interval query param into URL based on the received granularity value', async () => {
const spyHistoryPushState = jest.spyOn(window.history, 'pushState');
const spyHistoryReplaceState = jest.spyOn(window.history, 'replaceState');
setTradeURLParams({
granularity: 0,
});
expect(spyHistoryPushState).toBeCalledWith(null, '', `/?interval=${oneTickInterval}`);
expect(spyHistoryReplaceState).toBeCalledWith({}, document.title, `/?interval=${oneTickInterval}`);
});
it('should set chart_type query param into URL based on the received chart_type value', async () => {
const spyHistoryPushState = jest.spyOn(window.history, 'pushState');
const spyHistoryReplaceState = jest.spyOn(window.history, 'replaceState');
setTradeURLParams({
chartType: areaChartType.value,
});
expect(spyHistoryPushState).toBeCalledWith(null, '', `/?chart_type=${areaChartType.text}`);
expect(spyHistoryReplaceState).toBeCalledWith({}, document.title, `/?chart_type=${areaChartType.text}`);
});
it('should set symbol query param into URL based on the received symbol value', async () => {
const spyHistoryPushState = jest.spyOn(window.history, 'pushState');
const spyHistoryReplaceState = jest.spyOn(window.history, 'replaceState');
setTradeURLParams({
symbol,
});
expect(spyHistoryPushState).toBeCalledWith(null, '', `/?symbol=${symbol}`);
expect(spyHistoryReplaceState).toBeCalledWith({}, document.title, `/?symbol=${symbol}`);
});
it('should set trade_type query param into URL based on the received contract_type value', async () => {
const spyHistoryPushState = jest.spyOn(window.history, 'pushState');
const spyHistoryReplaceState = jest.spyOn(window.history, 'replaceState');
setTradeURLParams({
contractType: TRADE_TYPES.ACCUMULATOR,
});
expect(spyHistoryPushState).toBeCalledWith(null, '', `/?trade_type=${TRADE_TYPES.ACCUMULATOR}`);
expect(spyHistoryReplaceState).toBeCalledWith({}, document.title, `/?trade_type=${TRADE_TYPES.ACCUMULATOR}`);
});
it('should not set any query params into URL when called with empty object', async () => {
const spyHistoryPushState = jest.spyOn(window.history, 'pushState');
const spyHistoryReplaceState = jest.spyOn(window.history, 'replaceState');
setTradeURLParams({});
expect(spyHistoryPushState).not.toBeCalled();
expect(spyHistoryReplaceState).not.toBeCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ export const setTradeURLParams = ({ contractType, symbol, chartType, granularity
contractType && searchParams.set(TRADE_URL_PARAMS.TRADE_TYPE, contractType);
if (searchParams.toString()) {
const newQuery = `${window.location.pathname}?${searchParams.toString()}`;
window.history.pushState(null, '', newQuery);
window.history.replaceState({}, document.title, newQuery);
}
};

0 comments on commit 8b57c94

Please sign in to comment.