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