diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-03 21:10:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-03 21:10:18 +0300 |
commit | 9be457ffc1727f6a942a68c16e47ca0bcaa2f64a (patch) | |
tree | 5c006f5e268f88603a69da3c1c3056030b0afca7 /spec/frontend | |
parent | 388e0fbbd00e04a10e3ac1084945aa18a781c40c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/lib/utils/url_utility_spec.js | 10 | ||||
-rw-r--r-- | spec/frontend/notes/mock_data.js | 4 | ||||
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 63 |
3 files changed, 77 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js index f35b25fdf04..450eeefd898 100644 --- a/spec/frontend/lib/utils/url_utility_spec.js +++ b/spec/frontend/lib/utils/url_utility_spec.js @@ -421,6 +421,16 @@ describe('URL utility', () => { window.location = originalLocation; }); + it.each` + inputQuery | expectedQuery + ${'?scope=all&state=merged'} | ${'?scope=all&state=merged'} + ${'?'} | ${'?'} + `('handles query string: $inputQuery', ({ inputQuery, expectedQuery }) => { + window.location.href = mockUrl; + urlUtils.visitUrl(inputQuery); + expect(window.location.assign).toHaveBeenCalledWith(`${mockUrl}${expectedQuery}`); + }); + it('does not navigate to unsafe urls', () => { // eslint-disable-next-line no-script-url const url = 'javascript:alert(document.domain)'; diff --git a/spec/frontend/notes/mock_data.js b/spec/frontend/notes/mock_data.js index 94549c4a73b..b291eba61f5 100644 --- a/spec/frontend/notes/mock_data.js +++ b/spec/frontend/notes/mock_data.js @@ -15,6 +15,10 @@ export const notesDataMock = { closePath: '/twitter/flight/issues/9.json?issue%5Bstate_event%5D=close', reopenPath: '/twitter/flight/issues/9.json?issue%5Bstate_event%5D=reopen', canAwardEmoji: true, + noteableType: 'issue', + noteableId: 1, + projectId: 2, + groupId: null, }; export const userDataMock = { diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 50df63d06af..0205f606297 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -2,6 +2,7 @@ import AxiosMockAdapter from 'axios-mock-adapter'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'spec/test_constants'; +import actionCable from '~/actioncable_consumer'; import Api from '~/api'; import { createAlert } from '~/alert'; import toast from '~/vue_shared/plugins/global_toast'; @@ -44,6 +45,15 @@ jest.mock('~/alert', () => ({ jest.mock('~/vue_shared/plugins/global_toast'); +jest.mock('@rails/actioncable', () => { + const mockConsumer = { + subscriptions: { create: jest.fn().mockReturnValue({ unsubscribe: jest.fn() }) }, + }; + return { + createConsumer: jest.fn().mockReturnValue(mockConsumer), + }; +}); + describe('Actions Notes Store', () => { let commit; let dispatch; @@ -251,6 +261,59 @@ describe('Actions Notes Store', () => { }); }); + describe('initPolling', () => { + afterEach(() => { + gon.features = {}; + }); + + it('creates the Action Cable subscription', () => { + gon.features = { actionCableNotes: true }; + + store.dispatch('setNotesData', notesDataMock); + store.dispatch('initPolling'); + + expect(actionCable.subscriptions.create).toHaveBeenCalledTimes(1); + expect(actionCable.subscriptions.create).toHaveBeenCalledWith( + { + channel: 'Noteable::NotesChannel', + project_id: store.state.notesData.projectId, + group_id: store.state.notesData.groupId, + noteable_type: store.state.notesData.noteableType, + noteable_id: store.state.notesData.noteableId, + }, + expect.any(Object), + ); + }); + }); + + describe('fetchUpdatedNotes', () => { + const response = { notes: [], last_fetched_at: '123456' }; + const successMock = () => + axiosMock.onGet(notesDataMock.notesPath).reply(HTTP_STATUS_OK, response); + const failureMock = () => + axiosMock.onGet(notesDataMock.notesPath).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR); + + beforeEach(() => { + return store.dispatch('setNotesData', notesDataMock); + }); + + it('calls the endpoint and stores last fetched state', async () => { + successMock(); + + await store.dispatch('fetchUpdatedNotes'); + + expect(store.state.lastFetchedAt).toBe('123456'); + }); + + it('shows an alert when fetching fails', async () => { + failureMock(); + + await store.dispatch('fetchUpdatedNotes'); + + expect(createAlert).toHaveBeenCalledTimes(1); + }); + }); + describe('poll', () => { const pollInterval = 6000; const pollResponse = { notes: [], last_fetched_at: '123456' }; |