Commit 45eabf92 authored by Fatih Acet's avatar Fatih Acet

Accept lockVersion as a prop and add to store

parent 8bcd508b
......@@ -130,6 +130,10 @@ export default {
required: false,
default: true,
},
lockVersion: {
type: Number,
required: true,
},
},
data() {
const store = new Store({
......@@ -141,6 +145,7 @@ export default {
updatedByName: this.updatedByName,
updatedByPath: this.updatedByPath,
taskStatus: this.initialTaskStatus,
lock_version: this.lockVersion,
});
return {
......@@ -214,6 +219,7 @@ export default {
this.store.setFormState({
title: this.state.titleText,
description: this.state.descriptionText,
lock_version: this.state.lock_version,
lockedWarningVisible: false,
updateLoading: false,
});
......
......@@ -6,6 +6,7 @@ export default class Store {
description: '',
lockedWarningVisible: false,
updateLoading: false,
lock_version: 0,
};
}
......@@ -22,6 +23,7 @@ export default class Store {
this.state.updatedAt = data.updated_at;
this.state.updatedByName = data.updated_by_name;
this.state.updatedByPath = data.updated_by_path;
this.state.lock_version = data.lock_version;
}
stateShouldUpdate(data) {
......
......@@ -190,6 +190,7 @@ describe IssuablesHelper do
markdownDocsPath: '/help/user/markdown',
markdownVersion: CacheMarkdownField::CACHE_COMMONMARK_VERSION,
issuableTemplates: [],
lockVersion: issue.lock_version,
projectPath: @project.path,
projectNamespace: @project.namespace.path,
initialTitleHtml: issue.title,
......
......@@ -43,6 +43,7 @@ describe('Issuable output', () => {
initialTitleText: '',
initialDescriptionHtml: 'test',
initialDescriptionText: 'test',
lockVersion: 1,
markdownPreviewPath: '/',
markdownDocsPath: '/',
projectNamespace: '/',
......@@ -78,6 +79,7 @@ describe('Issuable output', () => {
expect(formatText(editedText.innerText)).toMatch(/Edited[\s\S]+?by Some User/);
expect(editedText.querySelector('.author-link').href).toMatch(/\/some_user$/);
expect(editedText.querySelector('time')).toBeTruthy();
expect(vm.state.lock_version).toEqual(1);
})
.then(() => {
vm.poll.makeRequest();
......@@ -95,6 +97,7 @@ describe('Issuable output', () => {
expect(editedText.querySelector('.author-link').href).toMatch(/\/other_user$/);
expect(editedText.querySelector('time')).toBeTruthy();
expect(vm.state.lock_version).toEqual(2);
})
.then(done)
.catch(done.fail);
......@@ -255,15 +258,10 @@ describe('Issuable output', () => {
describe('error when updating', () => {
beforeEach(() => {
spyOn(window, 'Flash').and.callThrough();
spyOn(vm.service, 'updateIssuable').and.callFake(
() =>
new Promise((resolve, reject) => {
reject();
}),
);
});
it('closes form on error', done => {
spyOn(vm.service, 'updateIssuable').and.callFake(() => Promise.resolve());
vm.updateIssuable();
setTimeout(() => {
......@@ -276,6 +274,7 @@ describe('Issuable output', () => {
});
it('returns the correct error message for issuableType', done => {
spyOn(vm.service, 'updateIssuable').and.callFake(() => Promise.reject());
vm.issuableType = 'merge request';
Vue.nextTick(() => {
......@@ -290,6 +289,20 @@ describe('Issuable output', () => {
});
});
});
it('shows error mesage from backend if exists', done => {
const msg = 'Custom error message from backend';
spyOn(vm.service, 'updateIssuable').and.callFake(() =>
Promise.reject({ response: { data: { errors: msg } } }), // eslint-disable-line prefer-promise-reject-errors
);
vm.updateIssuable();
setTimeout(() => {
expect(window.Flash).toHaveBeenCalledWith(msg);
done();
});
});
});
});
......@@ -420,6 +433,7 @@ describe('Issuable output', () => {
.then(vm.$nextTick)
.then(() => {
expect(vm.formState.lockedWarningVisible).toEqual(true);
expect(vm.formState.lock_version).toEqual(1);
expect(vm.$el.querySelector('.alert')).not.toBeNull();
})
.then(done)
......
......@@ -8,6 +8,7 @@ export default {
updated_at: '2015-05-15T12:31:04.428Z',
updated_by_name: 'Some User',
updated_by_path: '/some_user',
lock_version: 1,
},
secondRequest: {
title: '<p>2</p>',
......@@ -18,5 +19,6 @@ export default {
updated_at: '2016-05-15T12:31:04.428Z',
updated_by_name: 'Other User',
updated_by_path: '/other_user',
lock_version: 2,
},
};
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