diff options
Diffstat (limited to 'spec/javascripts/lib/utils/common_utils_spec.js')
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index b2b8f64d705..514d6ddeae5 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -42,6 +42,7 @@ describe('common_utils', () => { it('should remove the question mark from the search params', () => { const paramsArray = commonUtils.urlParamsToArray('?test=thing'); + expect(paramsArray[0][0]).not.toBe('?'); }); }); @@ -121,6 +122,7 @@ describe('common_utils', () => { commonUtils.handleLocationHash(); expectGetElementIdToHaveBeenCalledWith('test'); + expect(window.scrollY).toBe(document.getElementById('test').offsetTop); document.getElementById('parent').remove(); @@ -139,6 +141,7 @@ describe('common_utils', () => { expectGetElementIdToHaveBeenCalledWith('test'); expectGetElementIdToHaveBeenCalledWith('user-content-test'); + expect(window.scrollY).toBe(document.getElementById('user-content-test').offsetTop); document.getElementById('parent').remove(); @@ -159,6 +162,7 @@ describe('common_utils', () => { expectGetElementIdToHaveBeenCalledWith('test'); expectGetElementIdToHaveBeenCalledWith('user-content-test'); + expect(window.scrollY).toBe(document.getElementById('user-content-test').offsetTop - 50); expect(window.scrollBy).toHaveBeenCalledWith(0, -50); @@ -222,20 +226,24 @@ describe('common_utils', () => { it('should return valid parameter', () => { const value = commonUtils.getParameterByName('scope'); + expect(commonUtils.getParameterByName('p')).toEqual('2'); expect(value).toBe('all'); }); it('should return invalid parameter', () => { const value = commonUtils.getParameterByName('fakeParameter'); + expect(value).toBe(null); }); it('should return valid paramentes if URL is provided', () => { let value = commonUtils.getParameterByName('foo', 'http://cocteau.twins/?foo=bar'); + expect(value).toBe('bar'); value = commonUtils.getParameterByName('manan', 'http://cocteau.twins/?foo=bar&manan=canchu'); + expect(value).toBe('canchu'); }); }); @@ -395,6 +403,7 @@ describe('common_utils', () => { }) ).catch(done.fail)).then((respBackoff) => { const timeouts = window.setTimeout.calls.allArgs().map(([, timeout]) => timeout); + expect(timeouts).toEqual([2000, 4000]); expect(respBackoff).toBe(expectedResponseValue); done(); @@ -405,6 +414,7 @@ describe('common_utils', () => { commonUtils.backOff(next => next(), 64000) .catch((errBackoffResp) => { const timeouts = window.setTimeout.calls.allArgs().map(([, timeout]) => timeout); + expect(timeouts).toEqual([2000, 4000, 8000, 16000, 32000, 32000]); expect(errBackoffResp instanceof Error).toBe(true); expect(errBackoffResp.message).toBe('BACKOFF_TIMEOUT'); @@ -450,6 +460,7 @@ describe('common_utils', () => { const favicon = document.getElementById('favicon'); favicon.setAttribute('href', 'new/favicon'); commonUtils.resetFavicon(); + expect(document.getElementById('favicon').getAttribute('href')).toEqual('default/favicon'); }); }); @@ -507,6 +518,7 @@ describe('common_utils', () => { commonUtils.setCiStatusFavicon(BUILD_URL) .catch(() => { const favicon = document.getElementById('favicon'); + expect(favicon.getAttribute('href')).toEqual(faviconDataUrl); done(); }); @@ -520,6 +532,7 @@ describe('common_utils', () => { commonUtils.setCiStatusFavicon(BUILD_URL) .then(() => { const favicon = document.getElementById('favicon'); + expect(favicon.getAttribute('href')).toEqual(faviconWithOverlayDataUrl); done(); }) |