2020-01-08 07:07:59 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-01-25 07:14:14 -05:00
|
|
|
import { nextTick } from 'vue';
|
2019-07-03 04:26:57 -04:00
|
|
|
import DiffGutterAvatars from '~/diffs/components/diff_gutter_avatars.vue';
|
|
|
|
import discussionsMockData from '../mock_data/diff_discussions';
|
|
|
|
|
2020-05-07 17:09:26 -04:00
|
|
|
const getDiscussionsMockData = () => [{ ...discussionsMockData }];
|
2019-07-03 04:26:57 -04:00
|
|
|
|
|
|
|
describe('DiffGutterAvatars', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findCollapseButton = () => wrapper.find('.diff-notes-collapse');
|
|
|
|
const findMoreCount = () => wrapper.find('.diff-comments-more-count');
|
|
|
|
const findUserAvatars = () => wrapper.findAll('.diff-comment-avatar');
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapper = shallowMount(DiffGutterAvatars, {
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when expanded', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
discussions: getDiscussionsMockData(),
|
|
|
|
discussionsExpanded: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a collapse button when discussions are expanded', () => {
|
|
|
|
expect(findCollapseButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('should emit toggleDiscussions event on button click', async () => {
|
2019-07-03 04:26:57 -04:00
|
|
|
findCollapseButton().trigger('click');
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy();
|
2019-07-03 04:26:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when collapsed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
discussions: getDiscussionsMockData(),
|
|
|
|
discussionsExpanded: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders user avatars and moreCount text', () => {
|
|
|
|
expect(findUserAvatars().exists()).toBe(true);
|
|
|
|
expect(findMoreCount().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correct amount of user avatars', () => {
|
|
|
|
expect(findUserAvatars().length).toBe(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correct moreCount number', () => {
|
|
|
|
expect(findMoreCount().text()).toBe('+2');
|
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('should emit toggleDiscussions event on avatars click', async () => {
|
2020-12-23 07:10:26 -05:00
|
|
|
findUserAvatars().at(0).trigger('click');
|
2019-07-03 04:26:57 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy();
|
2019-07-03 04:26:57 -04:00
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('should emit toggleDiscussions event on more count text click', async () => {
|
2019-07-03 04:26:57 -04:00
|
|
|
findMoreCount().trigger('click');
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy();
|
2019-07-03 04:26:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an empty more count string if there are no discussions', () => {
|
|
|
|
createComponent({
|
|
|
|
discussions: [],
|
|
|
|
discussionsExpanded: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findMoreCount().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tooltip text', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
discussions: getDiscussionsMockData(),
|
|
|
|
discussionsExpanded: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns original comment if it is shorter than max length', () => {
|
|
|
|
const note = wrapper.vm.discussions[0].notes[0];
|
|
|
|
|
|
|
|
expect(wrapper.vm.getTooltipText(note)).toEqual('Administrator: comment 1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns truncated version of comment if it is longer than max length', () => {
|
|
|
|
const note = wrapper.vm.discussions[0].notes[1];
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
expect(wrapper.vm.getTooltipText(note)).toEqual('Fatih Acet: comment 2 is rea…');
|
2019-07-03 04:26:57 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|