diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/notes/stores/actions_spec.js | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/notes/stores/actions_spec.js')
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 85 |
1 files changed, 79 insertions, 6 deletions
diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 909a4a797ae..6b8d0790669 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -1,7 +1,7 @@ import { TEST_HOST } from 'spec/test_constants'; import AxiosMockAdapter from 'axios-mock-adapter'; import Api from '~/api'; -import Flash from '~/flash'; +import { deprecatedCreateFlash as Flash } from '~/flash'; import * as actions from '~/notes/stores/actions'; import * as mutationTypes from '~/notes/stores/mutation_types'; import * as notesConstants from '~/notes/constants'; @@ -19,7 +19,9 @@ import { } from '../mock_data'; import axios from '~/lib/utils/axios_utils'; import * as utils from '~/notes/stores/utils'; -import updateIssueConfidentialMutation from '~/sidebar/components/confidential/queries/update_issue_confidential.mutation.graphql'; +import updateIssueConfidentialMutation from '~/sidebar/components/confidential/mutations/update_issue_confidential.mutation.graphql'; +import updateMergeRequestLockMutation from '~/sidebar/components/lock/mutations/update_merge_request_lock.mutation.graphql'; +import updateIssueLockMutation from '~/sidebar/components/lock/mutations/update_issue_lock.mutation.graphql'; const TEST_ERROR_MESSAGE = 'Test error message'; jest.mock('~/flash'); @@ -1219,7 +1221,7 @@ describe('Actions Notes Store', () => { }); }); - describe('updateConfidentialityOnIssue', () => { + describe('updateConfidentialityOnIssuable', () => { state = { noteableData: { confidential: false } }; const iid = '1'; const projectPath = 'full/path'; @@ -1234,13 +1236,13 @@ describe('Actions Notes Store', () => { }); it('calls gqClient mutation one time', () => { - actions.updateConfidentialityOnIssue({ commit: () => {}, state, getters }, actionArgs); + actions.updateConfidentialityOnIssuable({ commit: () => {}, state, getters }, actionArgs); expect(utils.gqClient.mutate).toHaveBeenCalledTimes(1); }); it('calls gqClient mutation with the correct values', () => { - actions.updateConfidentialityOnIssue({ commit: () => {}, state, getters }, actionArgs); + actions.updateConfidentialityOnIssuable({ commit: () => {}, state, getters }, actionArgs); expect(utils.gqClient.mutate).toHaveBeenCalledWith({ mutation: updateIssueConfidentialMutation, @@ -1253,7 +1255,7 @@ describe('Actions Notes Store', () => { const commitSpy = jest.fn(); return actions - .updateConfidentialityOnIssue({ commit: commitSpy, state, getters }, actionArgs) + .updateConfidentialityOnIssuable({ commit: commitSpy, state, getters }, actionArgs) .then(() => { expect(commitSpy).toHaveBeenCalledWith( mutationTypes.SET_ISSUE_CONFIDENTIAL, @@ -1263,4 +1265,75 @@ describe('Actions Notes Store', () => { }); }); }); + + describe.each` + issuableType + ${'issue'} | ${'merge_request'} + `('updateLockedAttribute for issuableType=$issuableType', ({ issuableType }) => { + // Payload for mutation query + state = { noteableData: { discussion_locked: false } }; + const targetType = issuableType; + const getters = { getNoteableData: { iid: '1', targetType } }; + + // Target state after mutation + const locked = true; + const actionArgs = { fullPath: 'full/path', locked }; + const input = { iid: '1', projectPath: 'full/path', locked: true }; + + // Helper functions + const targetMutation = () => { + return targetType === 'issue' ? updateIssueLockMutation : updateMergeRequestLockMutation; + }; + + const mockResolvedValue = () => { + return targetType === 'issue' + ? { data: { issueSetLocked: { issue: { discussionLocked: locked } } } } + : { data: { mergeRequestSetLocked: { mergeRequest: { discussionLocked: locked } } } }; + }; + + beforeEach(() => { + jest.spyOn(utils.gqClient, 'mutate').mockResolvedValue(mockResolvedValue()); + }); + + it('calls gqClient mutation one time', () => { + actions.updateLockedAttribute({ commit: () => {}, state, getters }, actionArgs); + + expect(utils.gqClient.mutate).toHaveBeenCalledTimes(1); + }); + + it('calls gqClient mutation with the correct values', () => { + actions.updateLockedAttribute({ commit: () => {}, state, getters }, actionArgs); + + expect(utils.gqClient.mutate).toHaveBeenCalledWith({ + mutation: targetMutation(), + variables: { input }, + }); + }); + + describe('on success of mutation', () => { + it('calls commit with the correct values', () => { + const commitSpy = jest.fn(); + + return actions + .updateLockedAttribute({ commit: commitSpy, state, getters }, actionArgs) + .then(() => { + expect(commitSpy).toHaveBeenCalledWith(mutationTypes.SET_ISSUABLE_LOCK, locked); + }); + }); + }); + }); + + describe('updateDiscussionPosition', () => { + it('update the assignees state', done => { + const updatedPosition = { discussionId: 1, position: { test: true } }; + testAction( + actions.updateDiscussionPosition, + updatedPosition, + { state: { discussions: [] } }, + [{ type: mutationTypes.UPDATE_DISCUSSION_POSITION, payload: updatedPosition }], + [], + done, + ); + }); + }); }); |