Commit 9c85c6fe authored by Bryce Johnson's avatar Bryce Johnson

Add approvals store spec.

parent 6c154002
//= require jquery
//= require vue
//= require vue-resource
//= require merge_request_widget/approvals/stores/approvals_store
$.rails = {
csrfToken() {},
};
(() => {
// store constructor reference, to overwrite ApprovalStore singleton
gl.ApprovalsConstructor = gl.ApprovalsStore;
// stand in for promise returned by api calls
const mockThenable = {
then() {
return {
catch() {},
};
},
catch() {},
};
const mockRootStore = {
data: {},
dataset: {
endpoint: 'gitlab/myendpoint/',
},
assignToData(key, val) {
return { key, val };
},
};
describe('Approvals Store', function () {
beforeEach(function () {
this.rootStore = mockRootStore;
this.approvalsStore = new gl.ApprovalsConstructor(this.rootStore);
});
it('should define all needed approval api calls', function () {
expect(this.approvalsStore.fetch).toBeDefined();
expect(this.approvalsStore.approve).toBeDefined();
expect(this.approvalsStore.unapprove).toBeDefined();
});
it('should only init the store once', function () {
spyOn(this.approvalsStore, 'fetch').and.callFake(() => mockThenable);
this.approvalsStore.initStoreOnce();
this.approvalsStore.initStoreOnce();
this.approvalsStore.initStoreOnce();
expect(this.approvalsStore.fetch.calls.count()).toBe(1);
});
it('should be able to write to the rootStore', function () {
const dataToStore = { myMockData: 'string' };
spyOn(this.rootStore, 'assignToData');
this.approvalsStore.assignToRootStore(dataToStore);
expect(this.rootStore.assignToData).toHaveBeenCalled();
expect(this.rootStore.assignToData).toHaveBeenCalledWith('approvals', dataToStore);
});
});
})(window.gl || (window.gl = {}));
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