Commit d2e5313a authored by Eric Eastwood's avatar Eric Eastwood

Switch issue_show to Axios

parent b7da615c
...@@ -172,8 +172,8 @@ export default { ...@@ -172,8 +172,8 @@ export default {
}, },
updateIssuable() { updateIssuable() {
this.service.updateIssuable(this.store.formState) return this.service.updateIssuable(this.store.formState)
.then(res => res.json()) .then(res => res.data)
.then(data => this.checkForSpam(data)) .then(data => this.checkForSpam(data))
.then((data) => { .then((data) => {
if (location.pathname !== data.web_url) { if (location.pathname !== data.web_url) {
...@@ -182,7 +182,7 @@ export default { ...@@ -182,7 +182,7 @@ export default {
return this.service.getData(); return this.service.getData();
}) })
.then(res => res.json()) .then(res => res.data)
.then((data) => { .then((data) => {
this.store.updateState(data); this.store.updateState(data);
eventHub.$emit('close.form'); eventHub.$emit('close.form');
...@@ -207,7 +207,7 @@ export default { ...@@ -207,7 +207,7 @@ export default {
deleteIssuable() { deleteIssuable() {
this.service.deleteIssuable() this.service.deleteIssuable()
.then(res => res.json()) .then(res => res.data)
.then((data) => { .then((data) => {
// Stop the poll so we don't get 404's with the issuable not existing // Stop the poll so we don't get 404's with the issuable not existing
this.poll.stop(); this.poll.stop();
...@@ -225,7 +225,7 @@ export default { ...@@ -225,7 +225,7 @@ export default {
this.poll = new Poll({ this.poll = new Poll({
resource: this.service, resource: this.service,
method: 'getData', method: 'getData',
successCallback: res => res.json().then(data => this.store.updateState(data)), successCallback: res => this.store.updateState(res.data),
errorCallback(err) { errorCallback(err) {
throw new Error(err); throw new Error(err);
}, },
......
import Vue from 'vue'; import axios from '../../lib/utils/axios_utils';
import VueResource from 'vue-resource';
Vue.use(VueResource);
export default class Service { export default class Service {
constructor(endpoint) { constructor(endpoint) {
this.endpoint = endpoint; this.endpoint = `${endpoint}.json`;
this.realtimeEndpoint = `${endpoint}/realtime_changes`;
this.resource = Vue.resource(`${this.endpoint}.json`, {}, {
realtimeChanges: {
method: 'GET',
url: `${this.endpoint}/realtime_changes`,
},
});
} }
getData() { getData() {
return this.resource.realtimeChanges(); return axios.get(this.realtimeEndpoint);
} }
deleteIssuable() { deleteIssuable() {
return this.resource.delete(); return axios.delete(this.endpoint);
} }
updateIssuable(data) { updateIssuable(data) {
return this.resource.update(data); return axios.put(this.endpoint, data);
} }
} }
...@@ -232,7 +232,7 @@ export const nodeMatchesSelector = (node, selector) => { ...@@ -232,7 +232,7 @@ export const nodeMatchesSelector = (node, selector) => {
export const normalizeHeaders = (headers) => { export const normalizeHeaders = (headers) => {
const upperCaseHeaders = {}; const upperCaseHeaders = {};
Object.keys(headers).forEach((e) => { Object.keys(headers || {}).forEach((e) => {
upperCaseHeaders[e.toUpperCase()] = headers[e]; upperCaseHeaders[e.toUpperCase()] = headers[e];
}); });
......
import Vue from 'vue'; import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import '~/render_math'; import '~/render_math';
import '~/render_gfm'; import '~/render_gfm';
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
...@@ -11,26 +13,29 @@ function formatText(text) { ...@@ -11,26 +13,29 @@ function formatText(text) {
return text.trim().replace(/\s\s+/g, ' '); return text.trim().replace(/\s\s+/g, ' ');
} }
const REALTIME_REQUEST_STACK = [
issueShowData.initialRequest,
issueShowData.secondRequest,
];
describe('Issuable output', () => { describe('Issuable output', () => {
let requestData = issueShowData.initialRequest; let mock;
let realtimeRequestCount = 0;
let vm;
document.body.innerHTML = '<span id="task_status"></span>'; document.body.innerHTML = '<span id="task_status"></span>';
const interceptor = (request, next) => {
next(request.respondWith(JSON.stringify(requestData), {
status: 200,
}));
};
let vm;
beforeEach((done) => { beforeEach((done) => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
const IssuableDescriptionComponent = Vue.extend(issuableApp); const IssuableDescriptionComponent = Vue.extend(issuableApp);
requestData = issueShowData.initialRequest; mock = new MockAdapter(axios);
Vue.http.interceptors.push(interceptor); mock.onGet('/gitlab-org/gitlab-shell/issues/9/realtime_changes/realtime_changes').reply(() => {
const res = Promise.resolve([200, REALTIME_REQUEST_STACK[realtimeRequestCount]]);
realtimeRequestCount += 1;
return res;
});
vm = new IssuableDescriptionComponent({ vm = new IssuableDescriptionComponent({
propsData: { propsData: {
...@@ -54,10 +59,10 @@ describe('Issuable output', () => { ...@@ -54,10 +59,10 @@ describe('Issuable output', () => {
}); });
afterEach(() => { afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor); mock.reset();
realtimeRequestCount = 0;
vm.poll.stop(); vm.poll.stop();
vm.$destroy(); vm.$destroy();
}); });
...@@ -77,7 +82,6 @@ describe('Issuable output', () => { ...@@ -77,7 +82,6 @@ describe('Issuable output', () => {
expect(editedText.querySelector('time')).toBeTruthy(); expect(editedText.querySelector('time')).toBeTruthy();
}) })
.then(() => { .then(() => {
requestData = issueShowData.secondRequest;
vm.poll.makeRequest(); vm.poll.makeRequest();
}) })
.then(() => new Promise(resolve => setTimeout(resolve))) .then(() => new Promise(resolve => setTimeout(resolve)))
...@@ -141,24 +145,19 @@ describe('Issuable output', () => { ...@@ -141,24 +145,19 @@ describe('Issuable output', () => {
spyOn(vm.service, 'getData').and.callThrough(); spyOn(vm.service, 'getData').and.callThrough();
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
json() { data: {
return { confidential: false,
confidential: false, web_url: location.pathname,
web_url: location.pathname,
};
}, },
}); });
})); }));
vm.updateIssuable(); vm.updateIssuable()
.then(() => {
setTimeout(() => { expect(vm.service.getData).toHaveBeenCalled();
expect( })
vm.service.getData, .then(done)
).toHaveBeenCalled(); .catch(done.fail);
done();
});
}); });
it('correctly updates issuable data', (done) => { it('correctly updates issuable data', (done) => {
...@@ -166,29 +165,22 @@ describe('Issuable output', () => { ...@@ -166,29 +165,22 @@ describe('Issuable output', () => {
resolve(); resolve();
})); }));
vm.updateIssuable(); vm.updateIssuable()
.then(() => {
setTimeout(() => { expect(vm.service.updateIssuable).toHaveBeenCalledWith(vm.formState);
expect( expect(eventHub.$emit).toHaveBeenCalledWith('close.form');
vm.service.updateIssuable, })
).toHaveBeenCalledWith(vm.formState); .then(done)
expect( .catch(done.fail);
eventHub.$emit,
).toHaveBeenCalledWith('close.form');
done();
});
}); });
it('does not redirect if issue has not moved', (done) => { it('does not redirect if issue has not moved', (done) => {
spyOn(urlUtils, 'visitUrl'); spyOn(urlUtils, 'visitUrl');
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
json() { data: {
return { web_url: location.pathname,
web_url: location.pathname, confidential: vm.isConfidential,
confidential: vm.isConfidential,
};
}, },
}); });
})); }));
...@@ -208,11 +200,9 @@ describe('Issuable output', () => { ...@@ -208,11 +200,9 @@ describe('Issuable output', () => {
spyOn(urlUtils, 'visitUrl'); spyOn(urlUtils, 'visitUrl');
spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'updateIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
json() { data: {
return { web_url: '/testing-issue-move',
web_url: '/testing-issue-move', confidential: vm.isConfidential,
confidential: vm.isConfidential,
};
}, },
}); });
})); }));
...@@ -283,10 +273,8 @@ describe('Issuable output', () => { ...@@ -283,10 +273,8 @@ describe('Issuable output', () => {
let modal; let modal;
const promise = new Promise((resolve) => { const promise = new Promise((resolve) => {
resolve({ resolve({
json() { data: {
return { recaptcha_html: '<div class="g-recaptcha">recaptcha_html</div>',
recaptcha_html: '<div class="g-recaptcha">recaptcha_html</div>',
};
}, },
}); });
}); });
...@@ -323,8 +311,8 @@ describe('Issuable output', () => { ...@@ -323,8 +311,8 @@ describe('Issuable output', () => {
spyOn(urlUtils, 'visitUrl'); spyOn(urlUtils, 'visitUrl');
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
json() { data: {
return { web_url: '/test' }; web_url: '/test',
}, },
}); });
})); }));
...@@ -345,8 +333,8 @@ describe('Issuable output', () => { ...@@ -345,8 +333,8 @@ describe('Issuable output', () => {
spyOn(vm.poll, 'stop').and.callThrough(); spyOn(vm.poll, 'stop').and.callThrough();
spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => { spyOn(vm.service, 'deleteIssuable').and.callFake(() => new Promise((resolve) => {
resolve({ resolve({
json() { data: {
return { web_url: '/test' }; web_url: '/test',
}, },
}); });
})); }));
...@@ -385,22 +373,21 @@ describe('Issuable output', () => { ...@@ -385,22 +373,21 @@ describe('Issuable output', () => {
describe('open form', () => { describe('open form', () => {
it('shows locked warning if form is open & data is different', (done) => { it('shows locked warning if form is open & data is different', (done) => {
Vue.nextTick() vm.$nextTick()
.then(() => { .then(() => {
vm.openForm(); vm.openForm();
requestData = issueShowData.secondRequest;
vm.poll.makeRequest(); vm.poll.makeRequest();
}) })
.then(() => new Promise(resolve => setTimeout(resolve))) // Wait for the request
.then(vm.$nextTick)
// Wait for the successCallback to update the store state
.then(vm.$nextTick)
// Wait for the new state to flow to the Vue components
.then(vm.$nextTick)
.then(() => { .then(() => {
expect( expect(vm.formState.lockedWarningVisible).toEqual(true);
vm.formState.lockedWarningVisible, expect(vm.$el.querySelector('.alert')).not.toBeNull();
).toBeTruthy();
expect(
vm.$el.querySelector('.alert'),
).not.toBeNull();
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
...@@ -19,14 +19,4 @@ export default { ...@@ -19,14 +19,4 @@ export default {
updated_by_name: 'Other User', updated_by_name: 'Other User',
updated_by_path: '/other_user', updated_by_path: '/other_user',
}, },
issueSpecRequest: {
title: '<p>this is a title</p>',
title_text: 'this is a title',
description: '<li class="task-list-item enabled"><input type="checkbox" class="task-list-item-checkbox">Task List Item</li>',
description_text: '- [ ] Task List Item',
task_status: '0 of 1 completed',
updated_at: '2017-05-15T12:31:04.428Z',
updated_by_name: 'Last User',
updated_by_path: '/last_user',
},
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment