Commit 6243c04e authored by Fatih Acet's avatar Fatih Acet

Fix failing specs and lint errors.

parent 10649c49
...@@ -214,10 +214,16 @@ export default { ...@@ -214,10 +214,16 @@ export default {
}, },
updateStoreState() { updateStoreState() {
this.service.getData() this.service
.getData()
.then(res => res.data) .then(res => res.data)
.then(data => { .then(data => {
this.store.updateState(data); this.store.updateState(data);
})
.catch(() => {
const errMsg = `Error updating ${this.issuableType}`;
window.Flash(errMsg);
}); });
}, },
......
...@@ -39,6 +39,7 @@ export default { ...@@ -39,6 +39,7 @@ export default {
lockVersion: { lockVersion: {
type: Number, type: Number,
required: false, required: false,
default: 0,
}, },
}, },
data() { data() {
...@@ -89,8 +90,10 @@ export default { ...@@ -89,8 +90,10 @@ export default {
} }
}, },
taskListUpdateError({ errors, data }) { taskListUpdateError() {
createFlash('Someone edited this issue at the same time you did and we updated the issue description.'); createFlash(
'Someone edited this issue at the same time you did and we updated the issue description.',
);
this.$emit('taskListUpdateFailed'); this.$emit('taskListUpdateFailed');
}, },
......
...@@ -10,15 +10,17 @@ export default class TaskList { ...@@ -10,15 +10,17 @@ export default class TaskList {
this.fieldName = options.fieldName; this.fieldName = options.fieldName;
this.lockVersion = options.lockVersion; this.lockVersion = options.lockVersion;
this.onSuccess = options.onSuccess || (() => {}); this.onSuccess = options.onSuccess || (() => {});
this.onError = options.onError || function showFlash(e) { this.onError =
let errorMessages = ''; options.onError ||
function showFlash(e) {
let errorMessages = '';
if (e.response.data && typeof e.response.data === 'object') { if (e.response.data && typeof e.response.data === 'object') {
errorMessages = e.response.data.errors.join(' '); errorMessages = e.response.data.errors.join(' ');
} }
return new Flash(errorMessages || 'Update failed', 'alert'); return new Flash(errorMessages || 'Update failed', 'alert');
}; };
this.init(); this.init();
} }
...@@ -56,8 +58,8 @@ export default class TaskList { ...@@ -56,8 +58,8 @@ export default class TaskList {
[this.fieldName]: $target.val(), [this.fieldName]: $target.val(),
lock_version: this.lockVersion, lock_version: this.lockVersion,
update_task: { update_task: {
index: index, index,
checked: checked, checked,
line_number: lineNumber, line_number: lineNumber,
line_source: lineSource, line_source: lineSource,
}, },
......
...@@ -123,7 +123,10 @@ describe('Description component', () => { ...@@ -123,7 +123,10 @@ describe('Description component', () => {
fieldName: 'description', fieldName: 'description',
selector: '.detail-page-description', selector: '.detail-page-description',
onSuccess: jasmine.any(Function), onSuccess: jasmine.any(Function),
onError: jasmine.any(Function),
lockVersion: 0,
}); });
done(); done();
}); });
}); });
......
...@@ -41,15 +41,28 @@ describe('MergeRequest', function() { ...@@ -41,15 +41,28 @@ describe('MergeRequest', function() {
}); });
it('submits an ajax request on tasklist:changed', done => { it('submits an ajax request on tasklist:changed', done => {
$('.js-task-list-field').trigger('tasklist:changed'); const lineNumber = 8;
const lineSource = '- [ ] item 8';
const index = 3;
const checked = true;
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
setTimeout(() => { setTimeout(() => {
expect(axios.patch).toHaveBeenCalledWith( expect(axios.patch).toHaveBeenCalledWith(
`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, `${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`,
{ {
merge_request: { description: '- [ ] Task List Item' }, merge_request: {
description: '- [ ] Task List Item',
lock_version: undefined,
update_task: { line_number: lineNumber, line_source: lineSource, index, checked },
},
}, },
); );
done(); done();
}); });
}); });
......
...@@ -89,10 +89,25 @@ describe('Notes', function() { ...@@ -89,10 +89,25 @@ describe('Notes', function() {
}); });
it('submits an ajax request on tasklist:changed', function(done) { it('submits an ajax request on tasklist:changed', function(done) {
$('.js-task-list-container').trigger('tasklist:changed'); const lineNumber = 8;
const lineSource = '- [ ] item 8';
const index = 3;
const checked = true;
$('.js-task-list-container').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
setTimeout(() => { setTimeout(() => {
expect(axios.patch).toHaveBeenCalled(); expect(axios.patch).toHaveBeenCalledWith(undefined, {
note: {
note: '',
lock_version: undefined,
update_task: { index, checked, line_number: lineNumber, line_source: lineSource },
},
});
done(); done();
}); });
}); });
......
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