2020-04-08 14:13:33 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { mockTracking, triggerEvent } from 'helpers/tracking_helper';
|
|
|
|
import Component from '~/sidebar/components/assignees/assignee_title.vue';
|
|
|
|
|
|
|
|
describe('AssigneeTitle component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (props) => {
|
2020-04-08 14:13:33 +05:30
|
|
|
return shallowMount(Component, {
|
|
|
|
propsData: {
|
|
|
|
numberOfAssignees: 0,
|
|
|
|
editable: false,
|
2021-01-03 14:25:43 +05:30
|
|
|
changing: false,
|
2020-04-08 14:13:33 +05:30
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('assignee title', () => {
|
|
|
|
it('renders assignee', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 1,
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$el.innerText.trim()).toEqual('Assignee');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders 2 assignees', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 2,
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$el.innerText.trim()).toEqual('2 Assignees');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('gutter toggle', () => {
|
|
|
|
it('does not show toggle by default', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 2,
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$el.querySelector('.gutter-toggle')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows toggle when showToggle is true', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 2,
|
|
|
|
editable: false,
|
|
|
|
showToggle: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$el.querySelector('.gutter-toggle')).toEqual(expect.any(Object));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('when changing is false', () => {
|
|
|
|
it('renders "Edit"', () => {
|
|
|
|
wrapper = createComponent({ editable: true });
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-test-id="edit-link"]').text()).toEqual('Edit');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when changing is true', () => {
|
|
|
|
it('renders "Edit"', () => {
|
|
|
|
wrapper = createComponent({ editable: true, changing: true });
|
|
|
|
|
|
|
|
expect(wrapper.find('[data-test-id="edit-link"]').text()).toEqual('Apply');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it('does not render spinner by default', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 0,
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(false);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders spinner when loading', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
loading: true,
|
|
|
|
numberOfAssignees: 0,
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render edit link when not editable', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 0,
|
|
|
|
editable: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$el.querySelector('.edit-link')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders edit link when editable', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 0,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$el.querySelector('.edit-link')).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tracks the event when edit is clicked', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
numberOfAssignees: 0,
|
|
|
|
editable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const spy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
|
|
|
triggerEvent('.js-sidebar-dropdown-toggle');
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
|
|
|
|
label: 'right_sidebar',
|
|
|
|
property: 'assignee',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|