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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2019-09-30 21:07:59 +05:30
import DiffGutterAvatars from '~/diffs/components/diff_gutter_avatars.vue';
2022-10-11 01:57:18 +05:30
import { HIDE_COMMENTS } from '~/diffs/i18n';
2019-09-30 21:07:59 +05:30
import discussionsMockData from '../mock_data/diff_discussions';
2020-05-24 23:13:21 +05:30
const getDiscussionsMockData = () => [{ ...discussionsMockData }];
2019-09-30 21:07:59 +05:30
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-04-04 11:22:00 +05:30
it('should emit toggleDiscussions event on button click', async () => {
2019-09-30 21:07:59 +05:30
findCollapseButton().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2022-10-11 01:57:18 +05:30
expect(wrapper.emitted().toggleLineDiscussions).toBeDefined();
});
it('renders the proper title and aria-label', () => {
expect(findCollapseButton().attributes('title')).toBe(HIDE_COMMENTS);
expect(findCollapseButton().attributes('aria-label')).toBe(HIDE_COMMENTS);
2019-09-30 21:07:59 +05:30
});
});
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-04-04 11:22:00 +05:30
it('should emit toggleDiscussions event on avatars click', async () => {
2021-03-08 18:12:59 +05:30
findUserAvatars().at(0).trigger('click');
2019-09-30 21:07:59 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2022-10-11 01:57:18 +05:30
expect(wrapper.emitted().toggleLineDiscussions).toBeDefined();
2019-09-30 21:07:59 +05:30
});
2022-04-04 11:22:00 +05:30
it('should emit toggleDiscussions event on more count text click', async () => {
2019-09-30 21:07:59 +05:30
findMoreCount().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2022-10-11 01:57:18 +05:30
expect(wrapper.emitted().toggleLineDiscussions).toBeDefined();
2019-09-30 21:07:59 +05:30
});
});
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-07-28 23:09:34 +05:30
expect(wrapper.vm.getTooltipText(note)).toEqual('Fatih Acet: comment 2 is rea…');
2019-09-30 21:07:59 +05:30
});
});
});