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

103 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-07-31 22:56:46 +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';
2019-07-31 22:56:46 +05:30
import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue';
import NoteableDiscussion from '~/notes/components/noteable_discussion.vue';
import DiscussionNotes from '~/notes/components/discussion_notes.vue';
import Icon from '~/vue_shared/components/icon.vue';
2018-12-13 13:39:08 +05:30
import { createStore } from '~/mr_notes/stores';
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
2019-07-31 22:56:46 +05:30
const createComponent = props => {
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);
expect(diffNotesToggle.find(Icon).exists()).toBe(true);
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);
expect(
noteableDiscussion
.find('.badge-pill')
.text()
.trim(),
).toBe('1');
2018-11-08 19:23:39 +05:30
});
});
});