debian-mirror-gitlab/spec/frontend/diffs/components/diff_discussions_spec.js

98 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mount, createLocalVue } 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';
2019-07-31 22:56:46 +05:30
const localVue = createLocalVue();
2018-11-08 19:23:39 +05:30
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();
wrapper = mount(localVue.extend(DiffDiscussions), {
store,
propsData: {
discussions: getDiscussionsMockData(),
...props,
},
localVue,
});
};
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();
2019-07-31 22:56:46 +05:30
expect(wrapper.find(NoteableDiscussion).exists()).toBe(true);
expect(wrapper.find(DiscussionNotes).exists()).toBe(true);
expect(wrapper.find(DiscussionNotes).findAll(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);
2020-11-24 15:15:51 +05:30
expect(diffNotesToggle.find(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(
2020-04-22 19:07:51 +05:30
expect.arrayContaining(['btn-transparent', 'badge', 'badge-pill']),
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
2019-07-31 22:56:46 +05:30
expect(wrapper.find(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 });
const noteableDiscussion = wrapper.find(NoteableDiscussion);
expect(noteableDiscussion.find('.badge-pill').exists()).toBe(true);
2021-03-08 18:12:59 +05:30
expect(noteableDiscussion.find('.badge-pill').text().trim()).toBe('1');
2018-11-08 19:23:39 +05:30
});
});
});