2022-01-24 10:11:33 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-12-06 19:14:07 -05:00
|
|
|
import titleComponent from '~/issues/show/components/title.vue';
|
|
|
|
import eventHub from '~/issues/show/event_hub';
|
|
|
|
import Store from '~/issues/show/stores';
|
2017-05-10 10:05:58 -04:00
|
|
|
|
|
|
|
describe('Title component', () => {
|
|
|
|
let vm;
|
|
|
|
beforeEach(() => {
|
2022-05-13 08:08:49 -04:00
|
|
|
setHTMLFixture(`<title />`);
|
2020-05-06 11:09:42 -04:00
|
|
|
|
2017-05-10 10:05:58 -04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2022-05-13 08:08:49 -04:00
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2017-05-10 10:05:58 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('updates page title when changing titleHtml', async () => {
|
2020-05-06 11:09:42 -04:00
|
|
|
const spy = jest.spyOn(vm, 'setPageTitle');
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.titleHtml = 'test';
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('animates title changes', async () => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.titleHtml = 'test';
|
2022-01-24 10:11:33 -05:00
|
|
|
|
|
|
|
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-05-10 10:05:58 -04:00
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('updates page title after changing title', async () => {
|
2017-05-10 10:05:58 -04:00
|
|
|
vm.titleHtml = 'changed';
|
|
|
|
vm.titleText = 'changed';
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(document.querySelector('title').textContent.trim()).toContain('changed');
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
2017-10-17 13:04:33 -04:00
|
|
|
|
|
|
|
describe('inline edit button', () => {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('should trigger open.form event when clicked', async () => {
|
2020-05-06 11:09:42 -04:00
|
|
|
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
|
2017-10-17 13:04:33 -04:00
|
|
|
vm.showInlineEditButton = true;
|
|
|
|
vm.canUpdate = true;
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
await nextTick();
|
|
|
|
vm.$el.querySelector('.btn-edit').click();
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('open.form');
|
2017-10-17 13:04:33 -04:00
|
|
|
});
|
|
|
|
});
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|