debian-mirror-gitlab/spec/frontend/issuable_suggestions/components/item_spec.js

140 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlTooltip, GlLink, GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2021-03-08 18:12:59 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2019-02-15 15:39:39 +05:30
import Suggestion from '~/issuable_suggestions/components/item.vue';
2021-03-11 19:13:27 +05:30
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
2019-02-15 15:39:39 +05:30
import mockData from '../mock_data';
describe('Issuable suggestions suggestion component', () => {
let vm;
function createComponent(suggestion = {}) {
vm = shallowMount(Suggestion, {
propsData: {
suggestion: {
...mockData(),
...suggestion,
},
},
});
}
afterEach(() => {
vm.destroy();
});
it('renders title', () => {
createComponent();
expect(vm.text()).toContain('Test issue');
});
it('renders issue link', () => {
createComponent();
const link = vm.find(GlLink);
2020-07-28 23:09:34 +05:30
expect(link.attributes('href')).toBe(`${TEST_HOST}/test/issue/1`);
2019-02-15 15:39:39 +05:30
});
it('renders IID', () => {
createComponent();
expect(vm.text()).toContain('#1');
});
describe('opened state', () => {
it('renders icon', () => {
createComponent();
2020-11-24 15:15:51 +05:30
const icon = vm.find(GlIcon);
2019-02-15 15:39:39 +05:30
expect(icon.props('name')).toBe('issue-open-m');
});
it('renders created timeago', () => {
createComponent({
closedAt: '',
});
const tooltip = vm.find(GlTooltip);
expect(tooltip.find('.d-block').text()).toContain('Opened');
expect(tooltip.text()).toContain('3 days ago');
});
});
describe('closed state', () => {
it('renders icon', () => {
createComponent({
state: 'closed',
});
2020-11-24 15:15:51 +05:30
const icon = vm.find(GlIcon);
2019-02-15 15:39:39 +05:30
expect(icon.props('name')).toBe('issue-close');
});
it('renders closed timeago', () => {
createComponent();
const tooltip = vm.find(GlTooltip);
expect(tooltip.find('.d-block').text()).toContain('Opened');
expect(tooltip.text()).toContain('1 day ago');
});
});
describe('author', () => {
it('renders author info', () => {
createComponent();
const link = vm.findAll(GlLink).at(1);
expect(link.text()).toContain('Author Name');
expect(link.text()).toContain('@author.username');
});
it('renders author image', () => {
createComponent();
const image = vm.find(UserAvatarImage);
2020-07-28 23:09:34 +05:30
expect(image.props('imgSrc')).toBe(`${TEST_HOST}/avatar`);
2019-02-15 15:39:39 +05:30
});
});
describe('counts', () => {
it('renders upvotes count', () => {
createComponent();
const count = vm.findAll('.suggestion-counts span').at(0);
expect(count.text()).toContain('1');
2020-11-24 15:15:51 +05:30
expect(count.find(GlIcon).props('name')).toBe('thumb-up');
2019-02-15 15:39:39 +05:30
});
it('renders notes count', () => {
createComponent();
const count = vm.findAll('.suggestion-counts span').at(1);
expect(count.text()).toContain('2');
2020-11-24 15:15:51 +05:30
expect(count.find(GlIcon).props('name')).toBe('comment');
2019-02-15 15:39:39 +05:30
});
});
describe('confidential', () => {
it('renders confidential icon', () => {
createComponent({
confidential: true,
});
2020-11-24 15:15:51 +05:30
const icon = vm.find(GlIcon);
2019-02-15 15:39:39 +05:30
expect(icon.props('name')).toBe('eye-slash');
2020-03-13 15:44:24 +05:30
expect(icon.attributes('title')).toBe('Confidential');
2019-02-15 15:39:39 +05:30
});
});
});