diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 3ad60caf0..f71a972a7 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -214,7 +214,7 @@ jobs: name: bundle - run: yarn link - name: Install dependencies - uses: cypress-io/github-action@v1 + uses: cypress-io/github-action@v2 with: # just perform install runTests: false @@ -235,7 +235,7 @@ jobs: POSTGRES_DATABASE: adminbro_e2e_development - run: node bin/setup-db.js working-directory: packages/admin-bro-e2e - - uses: cypress-io/github-action@v1 + - uses: cypress-io/github-action@v2 with: install: false working-directory: packages/admin-bro-e2e diff --git a/src/frontend/components/actions/utils/append-force-refresh.spec.ts b/src/frontend/components/actions/utils/append-force-refresh.spec.ts new file mode 100644 index 000000000..6532d60b8 --- /dev/null +++ b/src/frontend/components/actions/utils/append-force-refresh.spec.ts @@ -0,0 +1,53 @@ +import { expect } from 'chai' + +import { appendForceRefresh } from './append-force-refresh' + +describe('appendForceRefresh', () => { + it('should add ?refresh=true to url if url has no search params', () => { + const oldUrl = '/resources/Test' + + const newUrl = appendForceRefresh(oldUrl) + + expect(newUrl).to.equal('/resources/Test?refresh=true') + }) + + it('should add &refresh=true to url if url already has search params', () => { + const oldUrl = '/resources/Test?param=test' + + const newUrl = appendForceRefresh(oldUrl) + + expect(newUrl).to.equal('/resources/Test?param=test&refresh=true') + }) + + it('should add &refresh=true to url if url already has search params but custom search is passed', () => { + const oldUrl = '/resources/Test?param=test' + + const newUrl = appendForceRefresh(oldUrl, 'other_param=test2') + + expect(newUrl).to.equal('/resources/Test?other_param=test2&refresh=true') + }) + + it('should add ?refresh=true to url if url is a full url with no search params', () => { + const oldUrl = 'http://example.com/resources/Test' + + const newUrl = appendForceRefresh(oldUrl) + + expect(newUrl).to.equal('http://example.com/resources/Test?refresh=true') + }) + + it('should add &refresh=true to url if url is a full url with search params', () => { + const oldUrl = 'http://example.com/resources/Test?param=test' + + const newUrl = appendForceRefresh(oldUrl) + + expect(newUrl).to.equal('http://example.com/resources/Test?param=test&refresh=true') + }) + + it('should add &refresh=true to url if url is a full url with search params but custom search is passed', () => { + const oldUrl = 'http://example.com/resources/Test?param=test' + + const newUrl = appendForceRefresh(oldUrl, 'other_param=test2') + + expect(newUrl).to.equal('http://example.com/resources/Test?other_param=test2&refresh=true') + }) +}) diff --git a/src/frontend/components/actions/utils/append-force-refresh.ts b/src/frontend/components/actions/utils/append-force-refresh.ts index 01c3ffd88..da2be916e 100644 --- a/src/frontend/components/actions/utils/append-force-refresh.ts +++ b/src/frontend/components/actions/utils/append-force-refresh.ts @@ -9,12 +9,21 @@ export const REFRESH_KEY = 'refresh' * @private */ export const appendForceRefresh = (url: string, search?: string): string => { - const urlObject = new URL(url) - const oldParams = search ?? urlObject.search ?? window.location.search + const searchParamsIdx = url.lastIndexOf('?') + const urlSearchParams = searchParamsIdx !== -1 + ? url.substring(searchParamsIdx + 1) + : null + + const oldParams = search ?? urlSearchParams ?? window.location.search const newParams = new URLSearchParams(oldParams) newParams.set(REFRESH_KEY, 'true') - return `${urlObject.origin}${urlObject.pathname}?${newParams.toString()}` + + const newUrl = searchParamsIdx !== -1 + ? url.substring(0, searchParamsIdx) + : url + + return `${newUrl}?${newParams.toString()}` } export const hasForceRefresh = (search: string): boolean => {