2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2022-01-26 12:08:38 +05:30
|
|
|
import titleComponent from '~/issues/show/components/title.vue';
|
|
|
|
import eventHub from '~/issues/show/event_hub';
|
|
|
|
import Store from '~/issues/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
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('updates page title when changing titleHtml', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const spy = jest.spyOn(vm, 'setPageTitle');
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.titleHtml = 'test';
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('animates title changes', async () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.titleHtml = 'test';
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.title').classList).toContain('issue-realtime-pre-pulse');
|
|
|
|
jest.runAllTimers();
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(vm.$el.querySelector('.title').classList).toContain('issue-realtime-trigger-pulse');
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('updates page title after changing title', async () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
vm.titleHtml = 'changed';
|
|
|
|
vm.titleText = 'changed';
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should trigger open.form event when clicked', async () => {
|
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;
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
vm.$el.querySelector('.btn-edit').click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('open.form');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|