summaryrefslogtreecommitdiff
path: root/spec/frontend/lib/utils/url_utility_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/lib/utils/url_utility_spec.js')
-rw-r--r--spec/frontend/lib/utils/url_utility_spec.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index e12cd8b0e37..8a04e93e88c 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -798,15 +798,29 @@ describe('URL utility', () => {
);
});
- it('handles arrays properly', () => {
+ it('adds parameters from arrays', () => {
const url = 'https://gitlab.com/test';
- expect(urlUtils.setUrlParams({ label_name: ['foo', 'bar'] }, url)).toEqual(
- 'https://gitlab.com/test?label_name=foo&label_name=bar',
+ expect(urlUtils.setUrlParams({ labels: ['foo', 'bar'] }, url)).toEqual(
+ 'https://gitlab.com/test?labels=foo&labels=bar',
);
});
- it('handles arrays properly when railsArraySyntax=true', () => {
+ it('removes parameters from empty arrays', () => {
+ const url = 'https://gitlab.com/test?labels=foo&labels=bar';
+
+ expect(urlUtils.setUrlParams({ labels: [] }, url)).toEqual('https://gitlab.com/test');
+ });
+
+ it('removes parameters from empty arrays while keeping other parameters', () => {
+ const url = 'https://gitlab.com/test?labels=foo&labels=bar&unrelated=unrelated';
+
+ expect(urlUtils.setUrlParams({ labels: [] }, url)).toEqual(
+ 'https://gitlab.com/test?unrelated=unrelated',
+ );
+ });
+
+ it('adds parameters from arrays when railsArraySyntax=true', () => {
const url = 'https://gitlab.com/test';
expect(urlUtils.setUrlParams({ labels: ['foo', 'bar'] }, url, false, true)).toEqual(
@@ -814,6 +828,14 @@ describe('URL utility', () => {
);
});
+ it('removes parameters from empty arrays when railsArraySyntax=true', () => {
+ const url = 'https://gitlab.com/test?labels%5B%5D=foo&labels%5B%5D=bar';
+
+ expect(urlUtils.setUrlParams({ labels: [] }, url, false, true)).toEqual(
+ 'https://gitlab.com/test',
+ );
+ });
+
it('decodes URI when decodeURI=true', () => {
const url = 'https://gitlab.com/test';