Commit f00c6db8 authored by Fatih Acet's avatar Fatih Acet

Add new spec for updateStoreState method

parent 4e40d72a
...@@ -212,9 +212,8 @@ export default { ...@@ -212,9 +212,8 @@ export default {
} }
return undefined; return undefined;
}, },
updateStoreState() { updateStoreState() {
this.service return this.service
.getData() .getData()
.then(res => res.data) .then(res => res.data)
.then(data => { .then(data => {
...@@ -252,12 +251,9 @@ export default { ...@@ -252,12 +251,9 @@ export default {
if (window.location.pathname !== data.web_url) { if (window.location.pathname !== data.web_url) {
visitUrl(data.web_url); visitUrl(data.web_url);
} }
return this.service.getData();
}) })
.then(res => res.data) .then(this.updateStoreState)
.then(data => { .then(() => {
this.store.updateState(data);
eventHub.$emit('close.form'); eventHub.$emit('close.form');
}) })
.catch(error => { .catch(error => {
......
...@@ -140,6 +140,7 @@ describe('Issuable output', () => { ...@@ -140,6 +140,7 @@ describe('Issuable output', () => {
describe('updateIssuable', () => { describe('updateIssuable', () => {
it('fetches new data after update', done => { it('fetches new data after update', done => {
spyOn(vm, 'updateStoreState').and.callThrough();
spyOn(vm.service, 'getData').and.callThrough(); spyOn(vm.service, 'getData').and.callThrough();
spyOn(vm.service, 'updateIssuable').and.callFake( spyOn(vm.service, 'updateIssuable').and.callFake(
() => () =>
...@@ -155,6 +156,7 @@ describe('Issuable output', () => { ...@@ -155,6 +156,7 @@ describe('Issuable output', () => {
vm.updateIssuable() vm.updateIssuable()
.then(() => { .then(() => {
expect(vm.updateStoreState).toHaveBeenCalled();
expect(vm.service.getData).toHaveBeenCalled(); expect(vm.service.getData).toHaveBeenCalled();
}) })
.then(done) .then(done)
...@@ -452,4 +454,20 @@ describe('Issuable output', () => { ...@@ -452,4 +454,20 @@ describe('Issuable output', () => {
expect(vm.$el.querySelector('.title-container .note-action-button')).toBeDefined(); expect(vm.$el.querySelector('.title-container .note-action-button')).toBeDefined();
}); });
}); });
describe('updateStoreState', () => {
it('should make a request and update the state of the store', done => {
const data = { foo: 1 };
spyOn(vm.store, 'updateState');
spyOn(vm.service, 'getData').and.returnValue(Promise.resolve({ data }));
vm.updateStoreState()
.then(() => {
expect(vm.service.getData).toHaveBeenCalled();
expect(vm.store.updateState).toHaveBeenCalledWith(data);
})
.then(done)
.catch(done.fail);
});
});
}); });
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