2020-11-24 15:15:51 +05:30
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2018-11-08 19:23:39 +05:30
|
|
|
import DiffDiscussions from '~/diffs/components/diff_discussions.vue';
|
2018-12-13 13:39:08 +05:30
|
|
|
import { createStore } from '~/mr_notes/stores';
|
2021-03-11 19:13:27 +05:30
|
|
|
import DiscussionNotes from '~/notes/components/discussion_notes.vue';
|
|
|
|
import NoteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
|
|
|
import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue';
|
2018-12-13 13:39:08 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2018-11-08 19:23:39 +05:30
|
|
|
import discussionsMockData from '../mock_data/diff_discussions';
|
|
|
|
|
|
|
|
describe('DiffDiscussions', () => {
|
2019-07-31 22:56:46 +05:30
|
|
|
let store;
|
|
|
|
let wrapper;
|
2020-05-24 23:13:21 +05:30
|
|
|
const getDiscussionsMockData = () => [{ ...discussionsMockData }];
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (props) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
store = createStore();
|
2022-04-04 11:22:00 +05:30
|
|
|
wrapper = mount(DiffDiscussions, {
|
2019-07-31 22:56:46 +05:30
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
discussions: getDiscussionsMockData(),
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2019-07-31 22:56:46 +05:30
|
|
|
wrapper.destroy();
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('should have notes list', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
createComponent();
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(NoteableDiscussion).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(DiscussionNotes).exists()).toBe(true);
|
|
|
|
expect(
|
|
|
|
wrapper.findComponent(DiscussionNotes).findAllComponents(TimelineEntryItem).length,
|
|
|
|
).toBe(discussionsMockData.notes.length);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('image commenting', () => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const findDiffNotesToggle = () => wrapper.find('.js-diff-notes-toggle');
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('renders collapsible discussion button', () => {
|
|
|
|
createComponent({ shouldCollapseDiscussions: true });
|
2019-07-31 22:56:46 +05:30
|
|
|
const diffNotesToggle = findDiffNotesToggle();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(diffNotesToggle.exists()).toBe(true);
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(diffNotesToggle.findComponent(GlIcon).exists()).toBe(true);
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(diffNotesToggle.classes('diff-notes-collapse')).toBe(true);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches toggleDiscussion when clicking collapse button', () => {
|
|
|
|
createComponent({ shouldCollapseDiscussions: true });
|
2020-04-22 19:07:51 +05:30
|
|
|
jest.spyOn(wrapper.vm.$store, 'dispatch').mockImplementation();
|
2019-07-31 22:56:46 +05:30
|
|
|
const diffNotesToggle = findDiffNotesToggle();
|
|
|
|
diffNotesToggle.trigger('click');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('toggleDiscussion', {
|
|
|
|
discussionId: discussionsMockData.id,
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it('renders expand button when discussion is collapsed', () => {
|
|
|
|
const discussions = getDiscussionsMockData();
|
|
|
|
discussions[0].expanded = false;
|
|
|
|
createComponent({ discussions, shouldCollapseDiscussions: true });
|
|
|
|
const diffNotesToggle = findDiffNotesToggle();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(diffNotesToggle.text().trim()).toBe('1');
|
|
|
|
expect(diffNotesToggle.classes()).toEqual(
|
2022-04-04 11:22:00 +05:30
|
|
|
expect.arrayContaining(['js-diff-notes-toggle', 'gl-translate-x-n50', 'design-note-pin']),
|
2019-07-31 22:56:46 +05:30
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it('hides discussion when collapsed', () => {
|
|
|
|
const discussions = getDiscussionsMockData();
|
|
|
|
discussions[0].expanded = false;
|
|
|
|
createComponent({ discussions, shouldCollapseDiscussions: true });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(NoteableDiscussion).isVisible()).toBe(false);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders badge on avatar', () => {
|
2019-07-31 22:56:46 +05:30
|
|
|
createComponent({ renderAvatarBadge: true });
|
2022-10-11 01:57:18 +05:30
|
|
|
const noteableDiscussion = wrapper.findComponent(NoteableDiscussion);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(noteableDiscussion.find('.design-note-pin').exists()).toBe(true);
|
|
|
|
expect(noteableDiscussion.find('.design-note-pin').text().trim()).toBe('1');
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|