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

133 lines
3.5 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', () => {
2021-11-18 22:05:49 +05:30
let wrapper;
2019-02-15 15:39:39 +05:30
function createComponent(suggestion = {}) {
2021-11-18 22:05:49 +05:30
wrapper = shallowMount(Suggestion, {
2019-02-15 15:39:39 +05:30
propsData: {
suggestion: {
...mockData(),
...suggestion,
},
},
});
}
2021-11-18 22:05:49 +05:30
const findLink = () => wrapper.findComponent(GlLink);
const findAuthorLink = () => wrapper.findAll(GlLink).at(1);
const findIcon = () => wrapper.findComponent(GlIcon);
const findTooltip = () => wrapper.findComponent(GlTooltip);
const findUserAvatar = () => wrapper.findComponent(UserAvatarImage);
2019-02-15 15:39:39 +05:30
afterEach(() => {
2021-11-18 22:05:49 +05:30
wrapper.destroy();
2019-02-15 15:39:39 +05:30
});
it('renders title', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(wrapper.text()).toContain('Test issue');
2019-02-15 15:39:39 +05:30
});
it('renders issue link', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(findLink().attributes('href')).toBe(`${TEST_HOST}/test/issue/1`);
2019-02-15 15:39:39 +05:30
});
it('renders IID', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(wrapper.text()).toContain('#1');
2019-02-15 15:39:39 +05:30
});
describe('opened state', () => {
it('renders icon', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(findIcon().props('name')).toBe('issue-open-m');
expect(findIcon().attributes('class')).toMatch('gl-text-green-500');
2019-02-15 15:39:39 +05:30
});
it('renders created timeago', () => {
createComponent({
closedAt: '',
});
2021-11-18 22:05:49 +05:30
expect(findTooltip().text()).toContain('Opened');
expect(findTooltip().text()).toContain('3 days ago');
2019-02-15 15:39:39 +05:30
});
});
describe('closed state', () => {
it('renders icon', () => {
createComponent({
state: 'closed',
});
2021-11-18 22:05:49 +05:30
expect(findIcon().props('name')).toBe('issue-close');
expect(findIcon().attributes('class')).toMatch('gl-text-blue-500');
2019-02-15 15:39:39 +05:30
});
it('renders closed timeago', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(findTooltip().text()).toContain('Opened');
expect(findTooltip().text()).toContain('1 day ago');
2019-02-15 15:39:39 +05:30
});
});
describe('author', () => {
it('renders author info', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(findAuthorLink().text()).toContain('Author Name');
expect(findAuthorLink().text()).toContain('@author.username');
2019-02-15 15:39:39 +05:30
});
it('renders author image', () => {
createComponent();
2021-11-18 22:05:49 +05:30
expect(findUserAvatar().props('imgSrc')).toBe(`${TEST_HOST}/avatar`);
2019-02-15 15:39:39 +05:30
});
});
describe('counts', () => {
it('renders upvotes count', () => {
createComponent();
2021-11-18 22:05:49 +05:30
const count = wrapper.findAll('.suggestion-counts span').at(0);
2019-02-15 15:39:39 +05:30
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();
2021-11-18 22:05:49 +05:30
const count = wrapper.findAll('.suggestion-counts span').at(1);
2019-02-15 15:39:39 +05:30
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,
});
2021-11-18 22:05:49 +05:30
expect(findIcon().props('name')).toBe('eye-slash');
expect(findIcon().attributes('class')).toMatch('gl-text-orange-500');
expect(findIcon().attributes('title')).toBe('Confidential');
2019-02-15 15:39:39 +05:30
});
});
});