diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/frontend/lib/utils/url_utility_spec.js | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/frontend/lib/utils/url_utility_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/url_utility_spec.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js index a13ac3778cf..869ae274a3f 100644 --- a/spec/frontend/lib/utils/url_utility_spec.js +++ b/spec/frontend/lib/utils/url_utility_spec.js @@ -161,6 +161,15 @@ describe('URL utility', () => { ); }); + it('sorts params in alphabetical order with sort option', () => { + expect(mergeUrlParams({ c: 'c', b: 'b', a: 'a' }, 'https://host/path', { sort: true })).toBe( + 'https://host/path?a=a&b=b&c=c', + ); + expect( + mergeUrlParams({ alpha: 'alpha' }, 'https://host/path?op=/&foo=bar', { sort: true }), + ).toBe('https://host/path?alpha=alpha&foo=bar&op=%2F'); + }); + describe('with spread array option', () => { const spreadArrayOptions = { spreadArrays: true }; @@ -616,6 +625,35 @@ describe('URL utility', () => { expect(urlUtils.queryToObject(searchQuery)).toEqual({ one: '1', two: '2' }); }); + + describe('with gatherArrays=false', () => { + it('overwrites values with the same array-key and does not change the key', () => { + const searchQuery = '?one[]=1&one[]=2&two=2&two=3'; + + expect(urlUtils.queryToObject(searchQuery)).toEqual({ 'one[]': '2', two: '3' }); + }); + }); + + describe('with gatherArrays=true', () => { + const options = { gatherArrays: true }; + it('gathers only values with the same array-key and strips `[]` from the key', () => { + const searchQuery = '?one[]=1&one[]=2&two=2&two=3'; + + expect(urlUtils.queryToObject(searchQuery, options)).toEqual({ one: ['1', '2'], two: '3' }); + }); + + it('overwrites values with the same array-key name', () => { + const searchQuery = '?one=1&one[]=2&two=2&two=3'; + + expect(urlUtils.queryToObject(searchQuery, options)).toEqual({ one: ['2'], two: '3' }); + }); + + it('overwrites values with the same key name', () => { + const searchQuery = '?one[]=1&one=2&two=2&two=3'; + + expect(urlUtils.queryToObject(searchQuery, options)).toEqual({ one: '2', two: '3' }); + }); + }); }); describe('objectToQuery', () => { |