Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/notes')
-rw-r--r--spec/frontend/notes/components/__snapshots__/notes_app_spec.js.snap4
-rw-r--r--spec/frontend/notes/components/note_actions_spec.js74
-rw-r--r--spec/frontend/notes/components/note_header_spec.js2
-rw-r--r--spec/frontend/notes/mixins/discussion_navigation_spec.js2
-rw-r--r--spec/frontend/notes/stores/getters_spec.js22
5 files changed, 98 insertions, 6 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 =
diff --git a/spec/frontend/notes/mixins/discussion_navigation_spec.js b/spec/frontend/notes/mixins/discussion_navigation_spec.js
index 45625d0a23f..81e4ed3ebe7 100644
--- a/spec/frontend/notes/mixins/discussion_navigation_spec.js
+++ b/spec/frontend/notes/mixins/discussion_navigation_spec.js
@@ -34,7 +34,7 @@ describe('Discussion navigation mixin', () => {
beforeEach(() => {
setHTMLFixture(
- `<div class="notes">
+ `<div class="tab-pane notes">
${[...'abcde']
.map(
(id) =>
diff --git a/spec/frontend/notes/stores/getters_spec.js b/spec/frontend/notes/stores/getters_spec.js
index e03fa854e54..1514602d424 100644
--- a/spec/frontend/notes/stores/getters_spec.js
+++ b/spec/frontend/notes/stores/getters_spec.js
@@ -1,5 +1,5 @@
import discussionWithTwoUnresolvedNotes from 'test_fixtures/merge_requests/resolved_diff_discussion.json';
-import { DESC, ASC } from '~/notes/constants';
+import { DESC, ASC, NOTEABLE_TYPE_MAPPING } from '~/notes/constants';
import * as getters from '~/notes/stores/getters';
import {
notesDataMock,
@@ -536,4 +536,24 @@ describe('Getters Notes Store', () => {
expect(getters.sortDirection(state)).toBe(DESC);
});
});
+
+ describe('canUserAddIncidentTimelineEvents', () => {
+ it.each`
+ userData | noteableData | expected
+ ${{ can_add_timeline_events: true }} | ${{ type: NOTEABLE_TYPE_MAPPING.Incident }} | ${true}
+ ${{ can_add_timeline_events: true }} | ${{ type: NOTEABLE_TYPE_MAPPING.Issue }} | ${false}
+ ${null} | ${{ type: NOTEABLE_TYPE_MAPPING.Incident }} | ${false}
+ ${{ can_add_timeline_events: false }} | ${{ type: NOTEABLE_TYPE_MAPPING.Incident }} | ${false}
+ `(
+ 'with userData=$userData and noteableData=$noteableData, expected=$expected',
+ ({ userData, noteableData, expected }) => {
+ Object.assign(state, {
+ userData,
+ noteableData,
+ });
+
+ expect(getters.canUserAddIncidentTimelineEvents(state)).toBe(expected);
+ },
+ );
+ });
});