2017-04-05 21:13:06 -04:00
|
|
|
import Vue from 'vue';
|
2017-04-25 12:31:15 -04:00
|
|
|
import '~/render_math';
|
|
|
|
import '~/render_gfm';
|
2017-05-10 10:05:58 -04:00
|
|
|
import issuableApp from '~/issue_show/components/app.vue';
|
2017-05-12 06:23:30 -04:00
|
|
|
import eventHub from '~/issue_show/event_hub';
|
2017-05-10 10:05:58 -04:00
|
|
|
import issueShowData from '../mock_data';
|
2017-04-25 12:31:15 -04:00
|
|
|
|
2017-05-02 17:01:23 -04:00
|
|
|
const issueShowInterceptor = data => (request, next) => {
|
|
|
|
next(request.respondWith(JSON.stringify(data), {
|
2017-04-25 12:31:15 -04:00
|
|
|
status: 200,
|
2017-05-02 17:01:23 -04:00
|
|
|
headers: {
|
2017-05-04 09:24:47 -04:00
|
|
|
'POLL-INTERVAL': 1,
|
2017-05-02 17:01:23 -04:00
|
|
|
},
|
2017-04-25 12:31:15 -04:00
|
|
|
}));
|
|
|
|
};
|
2017-04-05 21:13:06 -04:00
|
|
|
|
2017-05-18 10:50:25 -04:00
|
|
|
describe('Issuable output', () => {
|
2017-05-04 09:24:47 -04:00
|
|
|
document.body.innerHTML = '<span id="task_status"></span>';
|
|
|
|
|
2017-05-10 10:05:58 -04:00
|
|
|
let vm;
|
2017-04-05 21:13:06 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-05-10 10:05:58 -04:00
|
|
|
const IssuableDescriptionComponent = Vue.extend(issuableApp);
|
2017-05-02 17:01:23 -04:00
|
|
|
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.initialRequest));
|
|
|
|
|
2017-05-12 06:23:30 -04:00
|
|
|
spyOn(eventHub, '$emit');
|
|
|
|
|
2017-05-10 10:05:58 -04:00
|
|
|
vm = new IssuableDescriptionComponent({
|
2017-04-05 21:13:06 -04:00
|
|
|
propsData: {
|
2017-05-10 10:05:58 -04:00
|
|
|
canUpdate: true,
|
2017-05-12 06:58:48 -04:00
|
|
|
canDestroy: true,
|
2017-05-17 08:01:24 -04:00
|
|
|
canMove: true,
|
2017-05-13 16:19:49 -04:00
|
|
|
endpoint: '/gitlab-org/gitlab-shell/issues/9/realtime_changes',
|
2017-05-10 10:05:58 -04:00
|
|
|
issuableRef: '#1',
|
|
|
|
initialTitle: '',
|
|
|
|
initialDescriptionHtml: '',
|
|
|
|
initialDescriptionText: '',
|
2017-05-17 08:01:24 -04:00
|
|
|
markdownPreviewUrl: '/',
|
|
|
|
markdownDocs: '/',
|
|
|
|
projectsAutocompleteUrl: '/',
|
2017-05-18 07:44:27 -04:00
|
|
|
isConfidential: false,
|
2017-04-05 21:13:06 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
2017-05-10 10:05:58 -04:00
|
|
|
});
|
2017-04-05 21:13:06 -04:00
|
|
|
|
2017-05-10 10:05:58 -04:00
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, issueShowInterceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a title/description and update title/description on update', (done) => {
|
2017-04-25 12:31:15 -04:00
|
|
|
setTimeout(() => {
|
2017-05-02 17:01:23 -04:00
|
|
|
expect(document.querySelector('title').innerText).toContain('this is a title (#1)');
|
2017-05-10 10:05:58 -04:00
|
|
|
expect(vm.$el.querySelector('.title').innerHTML).toContain('<p>this is a title</p>');
|
|
|
|
expect(vm.$el.querySelector('.wiki').innerHTML).toContain('<p>this is a description!</p>');
|
2017-05-10 13:50:14 -04:00
|
|
|
expect(vm.$el.querySelector('.js-task-list-field').value).toContain('this is a description');
|
2017-04-25 14:48:00 -04:00
|
|
|
|
2017-05-02 17:01:23 -04:00
|
|
|
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.secondRequest));
|
2017-04-25 14:48:00 -04:00
|
|
|
|
2017-05-02 17:01:23 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(document.querySelector('title').innerText).toContain('2 (#1)');
|
2017-05-10 10:05:58 -04:00
|
|
|
expect(vm.$el.querySelector('.title').innerHTML).toContain('<p>2</p>');
|
|
|
|
expect(vm.$el.querySelector('.wiki').innerHTML).toContain('<p>42</p>');
|
2017-05-10 13:50:14 -04:00
|
|
|
expect(vm.$el.querySelector('.js-task-list-field').value).toContain('42');
|
2017-04-25 14:48:00 -04:00
|
|
|
|
2017-05-02 17:01:23 -04:00
|
|
|
done();
|
2017-05-04 09:24:47 -04:00
|
|
|
});
|
|
|
|
});
|
2017-04-05 21:13:06 -04:00
|
|
|
});
|
2017-05-12 06:23:30 -04:00
|
|
|
|
2017-05-12 06:58:48 -04:00
|
|
|
it('shows actions if permissions are correct', (done) => {
|
|
|
|
vm.showForm = true;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.btn'),
|
|
|
|
).not.toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show actions if permissions are incorrect', (done) => {
|
|
|
|
vm.showForm = true;
|
|
|
|
vm.canUpdate = false;
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('.btn'),
|
|
|
|
).toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-18 10:50:25 -04:00
|
|
|
it('does not update formState if form is already open', (done) => {
|
|
|
|
vm.openForm();
|
|
|
|
|
|
|
|
vm.state.titleText = 'testing 123';
|
|
|
|
|
|
|
|
vm.openForm();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(
|
|
|
|
vm.store.formState.title,
|
|
|
|
).not.toBe('testing 123');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-12 06:23:30 -04:00
|
|
|
describe('updateIssuable', () => {
|
2017-05-18 07:44:27 -04:00
|
|
|
it('reloads the page if the confidential status has changed', (done) => {
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
|
|
|
|
resolve({
|
|
|
|
json() {
|
|
|
|
return {
|
|
|
|
confidential: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}));
|
2017-05-17 11:06:17 -04:00
|
|
|
|
2017-05-18 07:44:27 -04:00
|
|
|
vm.updateIssuable();
|
2017-05-17 11:06:17 -04:00
|
|
|
|
2017-05-18 07:44:27 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
gl.utils.visitUrl,
|
|
|
|
).toHaveBeenCalledWith(location.href);
|
2017-05-17 11:06:17 -04:00
|
|
|
|
2017-05-18 07:44:27 -04:00
|
|
|
done();
|
|
|
|
});
|
2017-05-17 11:06:17 -04:00
|
|
|
});
|
|
|
|
|
2017-05-12 06:23:30 -04:00
|
|
|
it('correctly updates issuable data', (done) => {
|
|
|
|
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
|
|
|
|
resolve();
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.updateIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
vm.service.updateIssuable,
|
|
|
|
).toHaveBeenCalledWith(vm.formState);
|
|
|
|
expect(
|
|
|
|
eventHub.$emit,
|
|
|
|
).toHaveBeenCalledWith('close.form');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-17 08:01:24 -04:00
|
|
|
it('does not redirect if issue has not moved', (done) => {
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
|
|
|
|
resolve();
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.updateIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
gl.utils.visitUrl,
|
|
|
|
).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects if issue is moved', (done) => {
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
|
|
|
|
resolve({
|
|
|
|
json() {
|
|
|
|
return {
|
|
|
|
path: '/testing-issue-move',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.updateIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
gl.utils.visitUrl,
|
|
|
|
).toHaveBeenCalledWith('/testing-issue-move');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-12 06:23:30 -04:00
|
|
|
it('closes form on error', (done) => {
|
|
|
|
spyOn(window, 'Flash').and.callThrough();
|
|
|
|
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve, reject) => {
|
|
|
|
reject();
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.updateIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
eventHub.$emit,
|
|
|
|
).toHaveBeenCalledWith('close.form');
|
|
|
|
expect(
|
|
|
|
window.Flash,
|
|
|
|
).toHaveBeenCalledWith('Error updating issue');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteIssuable', () => {
|
|
|
|
it('changes URL when deleted', (done) => {
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => {
|
|
|
|
resolve({
|
2017-05-12 08:04:36 -04:00
|
|
|
json() {
|
|
|
|
return { path: '/test' };
|
|
|
|
},
|
2017-05-12 06:23:30 -04:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.deleteIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
gl.utils.visitUrl,
|
|
|
|
).toHaveBeenCalledWith('/test');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('stops polling when deleteing', (done) => {
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
spyOn(vm.poll, 'stop');
|
|
|
|
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => {
|
|
|
|
resolve({
|
2017-05-12 08:04:36 -04:00
|
|
|
json() {
|
|
|
|
return { path: '/test' };
|
|
|
|
},
|
2017-05-12 06:23:30 -04:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.deleteIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
vm.poll.stop,
|
|
|
|
).toHaveBeenCalledWith();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('closes form on error', (done) => {
|
|
|
|
spyOn(window, 'Flash').and.callThrough();
|
|
|
|
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve, reject) => {
|
|
|
|
reject();
|
|
|
|
}));
|
|
|
|
|
|
|
|
vm.deleteIssuable();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
eventHub.$emit,
|
|
|
|
).toHaveBeenCalledWith('close.form');
|
|
|
|
expect(
|
|
|
|
window.Flash,
|
|
|
|
).toHaveBeenCalledWith('Error deleting issue');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-04-05 21:13:06 -04:00
|
|
|
});
|