summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-06-10 07:31:49 +0000
committerPhil Hughes <me@iamphill.com>2019-06-10 07:31:49 +0000
commite3072811475dcd563911a78fce85263b693d3fd6 (patch)
treeb174b929b0ebbc69c837e0b60392245d74334f1d /spec
parent3017d2a52a3da5dc8e701f442b6d7c65c19cc054 (diff)
parent908829089c2f739af47e58bac11c51bd423bb2d1 (diff)
downloadgitlab-ce-e3072811475dcd563911a78fce85263b693d3fd6.tar.gz
Merge branch 'ce-5276-3-update-ide-diff-and-mirror-modules' into 'master'
[CE for Part 3] Update IDE file mirror service (ce utils) See merge request gitlab-org/gitlab-ce!29360
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/lib/utils/url_utility_spec.js44
1 files changed, 38 insertions, 6 deletions
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index eca240c9c18..c771984a137 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -1,5 +1,12 @@
import * as urlUtils from '~/lib/utils/url_utility';
+const setWindowLocation = value => {
+ Object.defineProperty(window, 'location', {
+ writable: true,
+ value,
+ });
+};
+
describe('URL utility', () => {
describe('webIDEUrl', () => {
afterEach(() => {
@@ -110,12 +117,9 @@ describe('URL utility', () => {
describe('getBaseURL', () => {
beforeEach(() => {
- global.window = Object.create(window);
- Object.defineProperty(window, 'location', {
- value: {
- host: 'gitlab.com',
- protocol: 'https:',
- },
+ setWindowLocation({
+ protocol: 'https:',
+ host: 'gitlab.com',
});
});
@@ -191,4 +195,32 @@ describe('URL utility', () => {
});
});
});
+
+ describe('getWebSocketProtocol', () => {
+ it.each`
+ protocol | expectation
+ ${'http:'} | ${'ws:'}
+ ${'https:'} | ${'wss:'}
+ `('returns "$expectation" with "$protocol" protocol', ({ protocol, expectation }) => {
+ setWindowLocation({
+ protocol,
+ host: 'example.com',
+ });
+
+ expect(urlUtils.getWebSocketProtocol()).toEqual(expectation);
+ });
+ });
+
+ describe('getWebSocketUrl', () => {
+ it('joins location host to path', () => {
+ setWindowLocation({
+ protocol: 'http:',
+ host: 'example.com',
+ });
+
+ const path = '/lorem/ipsum?a=bc';
+
+ expect(urlUtils.getWebSocketUrl(path)).toEqual('ws://example.com/lorem/ipsum?a=bc');
+ });
+ });
});