summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-03-30 21:21:18 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-04-03 10:40:30 +0100
commit76b2fa3eeb5f4f8b5ccd70e7307b10e30383c065 (patch)
tree1e60ca1a8be13feda194cece631e5677602e8eb3 /spec/javascripts/lib
parente7e9307219d1c81427f95444b36471c519dc06c2 (diff)
downloadgitlab-ce-76b2fa3eeb5f4f8b5ccd70e7307b10e30383c065.tar.gz
Fixes method not replacing URL parameters correctly
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r--spec/javascripts/lib/utils/common_utils_spec.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js
index 7cf39d37181..5c63e5024f5 100644
--- a/spec/javascripts/lib/utils/common_utils_spec.js
+++ b/spec/javascripts/lib/utils/common_utils_spec.js
@@ -261,5 +261,40 @@ require('~/lib/utils/common_utils');
});
}, 10000);
});
+
+ describe('gl.utils.setParamInURL', () => {
+ it('should return the parameter', () => {
+ expect(gl.utils.setParamInURL('page', 156)).toBe('?page=156');
+ expect(gl.utils.setParamInURL('page', '156')).toBe('?page=156');
+ });
+
+ it('should update the existing parameter when its a number', () => {
+ window.history.pushState({}, null, '?page=15');
+
+ expect(gl.utils.setParamInURL('page', 16)).toBe('?page=16');
+ expect(gl.utils.setParamInURL('page', '16')).toBe('?page=16');
+ expect(gl.utils.setParamInURL('page', true)).toBe('?page=true');
+ });
+
+ it('should update the existing parameter when its a string', () => {
+ window.history.pushState({}, null, '?scope=all');
+
+ expect(gl.utils.setParamInURL('scope', 'finished')).toBe('?scope=finished');
+ });
+
+ it('should update the existing parameter when more than one parameter exists', () => {
+ window.history.pushState({}, null, '?scope=all&page=15');
+
+ expect(gl.utils.setParamInURL('scope', 'finished')).toBe('?scope=finished&page=15');
+ });
+
+ it('should add a new parameter to the end of the existing ones', () => {
+ window.history.pushState({}, null, '?scope=all');
+
+ expect(gl.utils.setParamInURL('page', 16)).toBe('?scope=all&page=16');
+ expect(gl.utils.setParamInURL('page', '16')).toBe('?scope=all&page=16');
+ expect(gl.utils.setParamInURL('page', true)).toBe('?scope=all&page=true');
+ });
+ });
});
})();