debian-mirror-gitlab/spec/javascripts/sidebar/assignee_title_spec.js

124 lines
3.1 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2018-05-09 12:01:36 +05:30
import AssigneeTitle from '~/sidebar/components/assignees/assignee_title.vue';
2019-12-21 20:55:43 +05:30
import { mockTracking, triggerEvent } from 'spec/helpers/tracking_helper';
2017-08-17 22:00:37 +05:30
describe('AssigneeTitle component', () => {
let component;
let AssigneeTitleComponent;
beforeEach(() => {
AssigneeTitleComponent = Vue.extend(AssigneeTitle);
});
describe('assignee title', () => {
it('renders assignee', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 1,
editable: false,
},
}).$mount();
expect(component.$el.innerText.trim()).toEqual('Assignee');
});
it('renders 2 assignees', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 2,
editable: false,
},
}).$mount();
expect(component.$el.innerText.trim()).toEqual('2 Assignees');
});
});
2017-09-10 17:25:29 +05:30
describe('gutter toggle', () => {
it('does not show toggle by default', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 2,
editable: false,
},
}).$mount();
expect(component.$el.querySelector('.gutter-toggle')).toBeNull();
});
it('shows toggle when showToggle is true', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 2,
editable: false,
showToggle: true,
},
}).$mount();
expect(component.$el.querySelector('.gutter-toggle')).toEqual(jasmine.any(Object));
});
});
2017-08-17 22:00:37 +05:30
it('does not render spinner by default', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 0,
editable: false,
},
}).$mount();
expect(component.$el.querySelector('.fa')).toBeNull();
});
it('renders spinner when loading', () => {
component = new AssigneeTitleComponent({
propsData: {
loading: true,
numberOfAssignees: 0,
editable: false,
},
}).$mount();
expect(component.$el.querySelector('.fa')).not.toBeNull();
});
it('does not render edit link when not editable', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 0,
editable: false,
},
}).$mount();
expect(component.$el.querySelector('.edit-link')).toBeNull();
});
it('renders edit link when editable', () => {
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 0,
editable: true,
},
}).$mount();
expect(component.$el.querySelector('.edit-link')).not.toBeNull();
});
2019-12-04 20:38:33 +05:30
2019-12-21 20:55:43 +05:30
it('tracks the event when edit is clicked', () => {
2019-12-04 20:38:33 +05:30
component = new AssigneeTitleComponent({
propsData: {
numberOfAssignees: 0,
editable: true,
},
}).$mount();
2019-12-21 20:55:43 +05:30
const spy = mockTracking('_category_', component.$el, spyOn);
triggerEvent('.js-sidebar-dropdown-toggle');
expect(spy).toHaveBeenCalledWith('_category_', 'click_edit_button', {
label: 'right_sidebar',
property: 'assignee',
});
2019-12-04 20:38:33 +05:30
});
2017-08-17 22:00:37 +05:30
});