-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13035 from vojtechszocs/add-plugin-script-cache-b…
…uster OCPBUGS-3495: Add cacheBuster query string when requesting plugin entry scripts
- Loading branch information
Showing
4 changed files
with
75 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 46 additions & 8 deletions
54
frontend/packages/console-dynamic-plugin-sdk/src/utils/__tests__/url.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,56 @@ | ||
import * as _ from 'lodash'; | ||
import { resolveURL } from '../url'; | ||
|
||
describe('resolveURL', () => { | ||
const getDocumentOrigin = () => 'https://example:1234'; | ||
const getDocumentOrigin = jest.fn(() => 'https://example:1234'); | ||
|
||
it('uses the base URL as-is if it has the protocol', () => { | ||
expect(resolveURL('http://test', 'foo', getDocumentOrigin)).toBe('http://test/foo'); | ||
expect(resolveURL('http://test/', 'foo', getDocumentOrigin)).toBe('http://test/foo'); | ||
expect(resolveURL('http://test/foo', 'bar', getDocumentOrigin)).toBe('http://test/bar'); | ||
expect(resolveURL('http://test/foo/', 'bar', getDocumentOrigin)).toBe('http://test/foo/bar'); | ||
expect(resolveURL('http://test', 'foobar', _.identity, getDocumentOrigin)).toBe( | ||
'http://test/foobar', | ||
); | ||
expect(resolveURL('http://test/', 'foobar', _.identity, getDocumentOrigin)).toBe( | ||
'http://test/foobar', | ||
); | ||
expect(resolveURL('http://test/foo', 'bar', _.identity, getDocumentOrigin)).toBe( | ||
'http://test/bar', | ||
); | ||
expect(resolveURL('http://test/foo/', 'bar', _.identity, getDocumentOrigin)).toBe( | ||
'http://test/foo/bar', | ||
); | ||
|
||
expect(getDocumentOrigin).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("makes the base URL relative to document origin if it's missing the protocol", () => { | ||
expect(resolveURL('/', 'foo', getDocumentOrigin)).toBe('https://example:1234/foo'); | ||
expect(resolveURL('/foo', 'bar', getDocumentOrigin)).toBe('https://example:1234/bar'); | ||
expect(resolveURL('/foo/', 'bar', getDocumentOrigin)).toBe('https://example:1234/foo/bar'); | ||
expect(resolveURL('/', 'foobar', _.identity, getDocumentOrigin)).toBe( | ||
'https://example:1234/foobar', | ||
); | ||
expect(resolveURL('/foo', 'bar', _.identity, getDocumentOrigin)).toBe( | ||
'https://example:1234/bar', | ||
); | ||
expect(resolveURL('/foo/', 'bar', _.identity, getDocumentOrigin)).toBe( | ||
'https://example:1234/foo/bar', | ||
); | ||
|
||
expect(getDocumentOrigin).toHaveBeenCalledTimes(3); | ||
}); | ||
|
||
it('calls the URL processing callback before returning the URL string', () => { | ||
const processURL = jest.fn((url: URL) => { | ||
const newURL = new URL(url); | ||
|
||
newURL.protocol = 'http'; | ||
newURL.hostname = 'custom-host'; | ||
newURL.port = '8080'; | ||
newURL.search = '?test=true'; | ||
|
||
return newURL; | ||
}); | ||
|
||
expect(resolveURL('/', 'foobar', processURL, getDocumentOrigin)).toBe( | ||
'http://custom-host:8080/foobar?test=true', | ||
); | ||
|
||
expect(processURL).toHaveBeenCalledWith(new URL('https://example:1234/foobar')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters