debian-mirror-gitlab/spec/frontend/issue_show/components/title_spec.js

96 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import titleComponent from '~/issue_show/components/title.vue';
2018-03-17 18:26:18 +05:30
import eventHub from '~/issue_show/event_hub';
2021-03-11 19:13:27 +05:30
import Store from '~/issue_show/stores';
2017-09-10 17:25:29 +05:30
describe('Title component', () => {
let vm;
beforeEach(() => {
2020-05-24 23:13:21 +05:30
setFixtures(`<title />`);
2017-09-10 17:25:29 +05:30
const Component = Vue.extend(titleComponent);
const store = new Store({
titleHtml: '',
descriptionHtml: '',
issuableRef: '',
});
vm = new Component({
propsData: {
issuableRef: '#1',
titleHtml: 'Testing <img />',
titleText: 'Testing',
showForm: false,
formState: store.formState,
},
}).$mount();
});
it('renders title HTML', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.title').innerHTML.trim()).toBe('Testing <img>');
2017-09-10 17:25:29 +05:30
});
2020-05-24 23:13:21 +05:30
it('updates page title when changing titleHtml', () => {
const spy = jest.spyOn(vm, 'setPageTitle');
2017-09-10 17:25:29 +05:30
vm.titleHtml = 'test';
2020-05-24 23:13:21 +05:30
return vm.$nextTick().then(() => {
expect(spy).toHaveBeenCalled();
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('animates title changes', () => {
2017-09-10 17:25:29 +05:30
vm.titleHtml = 'test';
2020-05-24 23:13:21 +05:30
return vm
.$nextTick()
.then(() => {
expect(vm.$el.querySelector('.title').classList).toContain('issue-realtime-pre-pulse');
jest.runAllTimers();
return vm.$nextTick();
})
.then(() => {
expect(vm.$el.querySelector('.title').classList).toContain('issue-realtime-trigger-pulse');
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('updates page title after changing title', () => {
2017-09-10 17:25:29 +05:30
vm.titleHtml = 'changed';
vm.titleText = 'changed';
2020-05-24 23:13:21 +05:30
return vm.$nextTick().then(() => {
2018-12-13 13:39:08 +05:30
expect(document.querySelector('title').textContent.trim()).toContain('changed');
2017-09-10 17:25:29 +05:30
});
});
2018-03-17 18:26:18 +05:30
describe('inline edit button', () => {
it('should not show by default', () => {
expect(vm.$el.querySelector('.btn-edit')).toBeNull();
});
it('should not show if canUpdate is false', () => {
vm.showInlineEditButton = true;
vm.canUpdate = false;
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.$el.querySelector('.btn-edit')).toBeNull();
});
it('should show if showInlineEditButton and canUpdate', () => {
vm.showInlineEditButton = true;
vm.canUpdate = true;
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(vm.$el.querySelector('.btn-edit')).toBeDefined();
});
it('should trigger open.form event when clicked', () => {
2020-05-24 23:13:21 +05:30
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
vm.showInlineEditButton = true;
vm.canUpdate = true;
Vue.nextTick(() => {
vm.$el.querySelector('.btn-edit').click();
2018-12-13 13:39:08 +05:30
2018-03-17 18:26:18 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('open.form');
});
});
});
2017-09-10 17:25:29 +05:30
});