diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/frontend/notes/components | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/frontend/notes/components')
3 files changed, 76 insertions, 4 deletions
diff --git a/spec/frontend/notes/components/__snapshots__/notes_app_spec.js.snap b/spec/frontend/notes/components/__snapshots__/notes_app_spec.js.snap index bc29903d4bf..a4611149432 100644 --- a/spec/frontend/notes/components/__snapshots__/notes_app_spec.js.snap +++ b/spec/frontend/notes/components/__snapshots__/notes_app_spec.js.snap @@ -2,7 +2,7 @@ exports[`note_app when sort direction is asc shows skeleton notes after the loaded discussions 1`] = ` "<ul id=\\"notes-list\\" class=\\"notes main-notes-list timeline\\"> - <noteable-discussion-stub discussion=\\"[object Object]\\" renderdifffile=\\"true\\" helppagepath=\\"\\" isoverviewtab=\\"true\\"></noteable-discussion-stub> + <noteable-discussion-stub discussion=\\"[object Object]\\" renderdifffile=\\"true\\" helppagepath=\\"\\" isoverviewtab=\\"true\\" shouldscrolltonote=\\"true\\"></noteable-discussion-stub> <skeleton-loading-container-stub class=\\"note-skeleton\\"></skeleton-loading-container-stub> <!----> </ul>" @@ -11,7 +11,7 @@ exports[`note_app when sort direction is asc shows skeleton notes after the load exports[`note_app when sort direction is desc shows skeleton notes before the loaded discussions 1`] = ` "<ul id=\\"notes-list\\" class=\\"notes main-notes-list timeline\\"> <skeleton-loading-container-stub class=\\"note-skeleton\\"></skeleton-loading-container-stub> - <noteable-discussion-stub discussion=\\"[object Object]\\" renderdifffile=\\"true\\" helppagepath=\\"\\" isoverviewtab=\\"true\\"></noteable-discussion-stub> + <noteable-discussion-stub discussion=\\"[object Object]\\" renderdifffile=\\"true\\" helppagepath=\\"\\" isoverviewtab=\\"true\\" shouldscrolltonote=\\"true\\"></noteable-discussion-stub> <!----> </ul>" `; diff --git a/spec/frontend/notes/components/note_actions_spec.js b/spec/frontend/notes/components/note_actions_spec.js index cbe11c20798..c7420ca9c48 100644 --- a/spec/frontend/notes/components/note_actions_spec.js +++ b/spec/frontend/notes/components/note_actions_spec.js @@ -5,6 +5,8 @@ import { TEST_HOST } from 'spec/test_constants'; import axios from '~/lib/utils/axios_utils'; import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants'; import noteActions from '~/notes/components/note_actions.vue'; +import { NOTEABLE_TYPE_MAPPING } from '~/notes/constants'; +import TimelineEventButton from '~/notes/components/note_actions/timeline_event_button.vue'; import createStore from '~/notes/stores'; import UserAccessRoleBadge from '~/vue_shared/components/user_access_role_badge.vue'; import { userDataMock } from '../mock_data'; @@ -18,6 +20,23 @@ describe('noteActions', () => { const findUserAccessRoleBadge = (idx) => wrapper.findAllComponents(UserAccessRoleBadge).at(idx); const findUserAccessRoleBadgeText = (idx) => findUserAccessRoleBadge(idx).text().trim(); + const findTimelineButton = () => wrapper.findComponent(TimelineEventButton); + + const setupStoreForIncidentTimelineEvents = ({ + userCanAdd, + noteableType, + isPromotionInProgress = true, + }) => { + store.dispatch('setUserData', { + ...userDataMock, + can_add_timeline_events: userCanAdd, + }); + store.state.noteableData = { + ...store.state.noteableData, + type: noteableType, + }; + store.state.isPromoteCommentToTimelineEventInProgress = isPromotionInProgress; + }; const mountNoteActions = (propsData, computed) => { return mount(noteActions, { @@ -238,7 +257,8 @@ describe('noteActions', () => { describe('user is not logged in', () => { beforeEach(() => { - store.dispatch('setUserData', {}); + // userData can be null https://gitlab.com/gitlab-org/gitlab/-/issues/379375 + store.dispatch('setUserData', null); wrapper = mountNoteActions({ ...props, canDelete: false, @@ -301,4 +321,56 @@ describe('noteActions', () => { expect(resolveButton.attributes('title')).toBe('Thread stays unresolved'); }); }); + + describe('timeline event button', () => { + // why: We are working with an integrated store, so let's imply the getter is used + describe.each` + desc | userCanAdd | noteableType | exists + ${'default'} | ${true} | ${NOTEABLE_TYPE_MAPPING.Incident} | ${true} + ${'when cannot add incident timeline event'} | ${false} | ${NOTEABLE_TYPE_MAPPING.Incident} | ${false} + ${'when is not incident'} | ${true} | ${NOTEABLE_TYPE_MAPPING.MergeRequest} | ${false} + `('$desc', ({ userCanAdd, noteableType, exists }) => { + beforeEach(() => { + setupStoreForIncidentTimelineEvents({ + userCanAdd, + noteableType, + }); + + wrapper = mountNoteActions({ ...props }); + }); + + it(`handles rendering of timeline button (exists=${exists})`, () => { + expect(findTimelineButton().exists()).toBe(exists); + }); + }); + + describe('default', () => { + beforeEach(() => { + setupStoreForIncidentTimelineEvents({ + userCanAdd: true, + noteableType: NOTEABLE_TYPE_MAPPING.Incident, + }); + + wrapper = mountNoteActions({ ...props }); + }); + + it('should render timeline-event-button', () => { + expect(findTimelineButton().props()).toEqual({ + noteId: props.noteId, + isPromotionInProgress: true, + }); + }); + + it('when timeline-event-button emits click-promote-comment-to-event, dispatches action', () => { + jest.spyOn(store, 'dispatch').mockImplementation(); + + expect(store.dispatch).not.toHaveBeenCalled(); + + findTimelineButton().vm.$emit('click-promote-comment-to-event'); + + expect(store.dispatch).toHaveBeenCalledTimes(1); + expect(store.dispatch).toHaveBeenCalledWith('promoteCommentToTimelineEvent'); + }); + }); + }); }); diff --git a/spec/frontend/notes/components/note_header_spec.js b/spec/frontend/notes/components/note_header_spec.js index b870cda2a24..56c22b09e1b 100644 --- a/spec/frontend/notes/components/note_header_spec.js +++ b/spec/frontend/notes/components/note_header_spec.js @@ -18,7 +18,7 @@ describe('NoteHeader component', () => { const findActionText = () => wrapper.findComponent({ ref: 'actionText' }); const findTimestampLink = () => wrapper.findComponent({ ref: 'noteTimestampLink' }); const findTimestamp = () => wrapper.findComponent({ ref: 'noteTimestamp' }); - const findInternalNoteIndicator = () => wrapper.findByTestId('internalNoteIndicator'); + const findInternalNoteIndicator = () => wrapper.findByTestId('internal-note-indicator'); const findSpinner = () => wrapper.findComponent({ ref: 'spinner' }); const statusHtml = |