2017-05-10 10:05:58 -04:00
|
|
|
import Vue from 'vue';
|
2017-05-12 07:54:10 -04:00
|
|
|
import Store from '~/issue_show/stores';
|
2017-05-10 10:05:58 -04:00
|
|
|
import titleComponent from '~/issue_show/components/title.vue';
|
2017-10-17 13:04:33 -04:00
|
|
|
import eventHub from '~/issue_show/event_hub';
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
describe('Title component', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const Component = Vue.extend(titleComponent);
|
2017-05-15 10:34:01 -04:00
|
|
|
const store = new Store({
|
|
|
|
titleHtml: '',
|
|
|
|
descriptionHtml: '',
|
|
|
|
issuableRef: '',
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
vm = new Component({
|
|
|
|
propsData: {
|
|
|
|
issuableRef: '#1',
|
|
|
|
titleHtml: 'Testing <img />',
|
|
|
|
titleText: 'Testing',
|
2017-05-12 07:54:10 -04:00
|
|
|
showForm: false,
|
2017-05-15 10:34:01 -04:00
|
|
|
formState: store.formState,
|
2017-05-10 10:05:58 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders title HTML', () => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(vm.$el.querySelector('.title').innerHTML.trim()).toBe('Testing <img>');
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('updates page title when changing titleHtml', done => {
|
2017-05-10 10:05:58 -04:00
|
|
|
spyOn(vm, 'setPageTitle');
|
|
|
|
vm.titleHtml = 'test';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(vm.setPageTitle).toHaveBeenCalled();
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('animates title changes', done => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.titleHtml = 'test';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
2017-10-17 13:04:33 -04:00
|
|
|
vm.$el.querySelector('.title').classList.contains('issue-realtime-pre-pulse'),
|
2017-05-10 10:05:58 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
2017-10-17 13:04:33 -04:00
|
|
|
vm.$el.querySelector('.title').classList.contains('issue-realtime-trigger-pulse'),
|
2017-05-10 10:05:58 -04:00
|
|
|
).toBeTruthy();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-30 16:28:31 -04:00
|
|
|
it('updates page title after changing title', done => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.titleHtml = 'changed';
|
|
|
|
vm.titleText = 'changed';
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2018-10-30 16:28:31 -04:00
|
|
|
expect(document.querySelector('title').textContent.trim()).toContain('changed');
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-10-17 13:04:33 -04:00
|
|
|
|
|
|
|
describe('inline edit button', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(eventHub, '$emit');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show by default', () => {
|
2017-11-28 14:07:25 -05:00
|
|
|
expect(vm.$el.querySelector('.btn-edit')).toBeNull();
|
2017-10-17 13:04:33 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show if canUpdate is false', () => {
|
|
|
|
vm.showInlineEditButton = true;
|
|
|
|
vm.canUpdate = false;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-28 14:07:25 -05:00
|
|
|
expect(vm.$el.querySelector('.btn-edit')).toBeNull();
|
2017-10-17 13:04:33 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show if showInlineEditButton and canUpdate', () => {
|
|
|
|
vm.showInlineEditButton = true;
|
|
|
|
vm.canUpdate = true;
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-11-28 14:07:25 -05:00
|
|
|
expect(vm.$el.querySelector('.btn-edit')).toBeDefined();
|
2017-10-17 13:04:33 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger open.form event when clicked', () => {
|
|
|
|
vm.showInlineEditButton = true;
|
|
|
|
vm.canUpdate = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
2017-11-28 14:07:25 -05:00
|
|
|
vm.$el.querySelector('.btn-edit').click();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-10-17 13:04:33 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('open.form');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|