diff options
Diffstat (limited to 'spec/frontend/lib/utils/url_utility_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/url_utility_spec.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js index e304ec70dc7..3a846bbda06 100644 --- a/spec/frontend/lib/utils/url_utility_spec.js +++ b/spec/frontend/lib/utils/url_utility_spec.js @@ -1,8 +1,20 @@ import setWindowLocation from 'helpers/set_window_location_helper'; import { TEST_HOST } from 'helpers/test_constants'; import * as urlUtils from '~/lib/utils/url_utility'; +import { setGlobalAlerts } from '~/lib/utils/global_alerts'; import { safeUrls, unsafeUrls } from './mock_data'; +jest.mock('~/lib/utils/global_alerts', () => ({ + getGlobalAlerts: jest.fn().mockImplementation(() => [ + { + id: 'foo', + message: 'Foo', + variant: 'success', + }, + ]), + setGlobalAlerts: jest.fn(), +})); + const shas = { valid: [ 'ad9be38573f9ee4c4daec22673478c2dd1d81cd8', @@ -482,6 +494,48 @@ describe('URL utility', () => { }); }); + describe('visitUrlWithAlerts', () => { + let originalLocation; + + beforeAll(() => { + originalLocation = window.location; + + Object.defineProperty(window, 'location', { + writable: true, + value: { + assign: jest.fn(), + protocol: 'http:', + host: TEST_HOST, + }, + }); + }); + + afterAll(() => { + window.location = originalLocation; + }); + + it('sets alerts and then visits url', () => { + const url = '/foo/bar'; + const alert = { + id: 'bar', + message: 'Bar', + variant: 'danger', + }; + + urlUtils.visitUrlWithAlerts(url, [alert]); + + expect(setGlobalAlerts).toHaveBeenCalledWith([ + { + id: 'foo', + message: 'Foo', + variant: 'success', + }, + alert, + ]); + expect(window.location.assign).toHaveBeenCalledWith(url); + }); + }); + describe('updateHistory', () => { const state = { key: 'prop' }; const title = 'TITLE'; |