diff options
Diffstat (limited to 'spec/javascripts/lib/utils/common_utils_spec.js')
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index 71b26a315af..28151c7e658 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -29,24 +29,46 @@ describe('common_utils', () => { }); }); - describe('getUrlParamsArray', () => { - it('should return params array', () => { - expect(commonUtils.getUrlParamsArray() instanceof Array).toBe(true); + describe('urlParamsToArray', () => { + it('returns empty array for empty querystring', () => { + expect(commonUtils.urlParamsToArray('')).toEqual([]); + }); + + it('should decode params', () => { + expect( + commonUtils.urlParamsToArray('?label_name%5B%5D=test')[0], + ).toBe('label_name[]=test'); }); it('should remove the question mark from the search params', () => { - const paramsArray = commonUtils.getUrlParamsArray(); + const paramsArray = commonUtils.urlParamsToArray('?test=thing'); expect(paramsArray[0][0] !== '?').toBe(true); }); + }); - it('should decode params', () => { - window.history.pushState('', '', '?label_name%5B%5D=test'); + describe('urlParamsToObject', () => { + it('parses path for label with trailing +', () => { + expect( + commonUtils.urlParamsToObject('label_name[]=label%2B', {}), + ).toEqual({ + label_name: ['label+'], + }); + }); + it('parses path for milestone with trailing +', () => { expect( - commonUtils.getUrlParamsArray()[0], - ).toBe('label_name[]=test'); + commonUtils.urlParamsToObject('milestone_title=A%2B', {}), + ).toEqual({ + milestone_title: 'A+', + }); + }); - window.history.pushState('', '', '?'); + it('parses path for search terms with spaces', () => { + expect( + commonUtils.urlParamsToObject('search=two+words', {}), + ).toEqual({ + search: 'two words', + }); }); }); @@ -403,6 +425,7 @@ describe('common_utils', () => { afterEach(() => { document.body.removeChild(document.getElementById('favicon')); }); + it('should set page favicon to provided favicon', () => { const faviconPath = '//custom_favicon'; commonUtils.setFavicon(faviconPath); @@ -479,17 +502,14 @@ describe('common_utils', () => { }); it('should reset favicon in case of error', (done) => { - mock.onGet(BUILD_URL).networkError(); + mock.onGet(BUILD_URL).replyOnce(500); commonUtils.setCiStatusFavicon(BUILD_URL) - .then(() => { + .catch(() => { const favicon = document.getElementById('favicon'); expect(favicon.getAttribute('href')).toEqual(faviconDataUrl); done(); - }) - // Error is already caught in catch() block of setCiStatusFavicon, - // It won't throw another error for us to catch - .catch(done.fail); + }); }); it('should set page favicon to CI status favicon based on provided status', (done) => { |