diff options
author | Phil Hughes <me@iamphill.com> | 2018-06-28 18:56:58 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-06-29 11:29:31 +0300 |
commit | 47fe2a5248d4b391084908f685bcc42ee3e8d24d (patch) | |
tree | a0d537fdfb52540d94df0da7e4746d91e2bc385a /spec | |
parent | d4fce4dc2f50b7cf8e0de009384f313f07b0156a (diff) |
more specs!
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/ide/stores/actions/merge_request_spec.js | 267 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions/tree_spec.js | 34 |
2 files changed, 232 insertions, 69 deletions
diff --git a/spec/javascripts/ide/stores/actions/merge_request_spec.js b/spec/javascripts/ide/stores/actions/merge_request_spec.js index b4ec4a0b173..c99ccc70c6a 100644 --- a/spec/javascripts/ide/stores/actions/merge_request_spec.js +++ b/spec/javascripts/ide/stores/actions/merge_request_spec.js @@ -1,110 +1,239 @@ +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; import store from '~/ide/stores'; +import { + getMergeRequestData, + getMergeRequestChanges, + getMergeRequestVersions, +} from '~/ide/stores/actions/merge_request'; import service from '~/ide/services'; import { resetStore } from '../../helpers'; describe('IDE store merge request actions', () => { + let mock; + beforeEach(() => { + mock = new MockAdapter(axios); + store.state.projects.abcproject = { mergeRequests: {}, }; }); afterEach(() => { + mock.restore(); resetStore(store); }); describe('getMergeRequestData', () => { - beforeEach(() => { - spyOn(service, 'getProjectMergeRequestData').and.returnValue( - Promise.resolve({ data: { title: 'mergerequest' } }), - ); + describe('success', () => { + beforeEach(() => { + spyOn(service, 'getProjectMergeRequestData').and.callThrough(); + + mock + .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/) + .reply(200, { title: 'mergerequest' }); + }); + + it('calls getProjectMergeRequestData service method', done => { + store + .dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) + .then(() => { + expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1); + + done(); + }) + .catch(done.fail); + }); + + it('sets the Merge Request Object', done => { + store + .dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) + .then(() => { + expect(store.state.projects.abcproject.mergeRequests['1'].title).toBe('mergerequest'); + expect(store.state.currentMergeRequestId).toBe(1); + + done(); + }) + .catch(done.fail); + }); }); - it('calls getProjectMergeRequestData service method', done => { - store - .dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) - .then(() => { - expect(service.getProjectMergeRequestData).toHaveBeenCalledWith('abcproject', 1); - - done(); - }) - .catch(done.fail); - }); - - it('sets the Merge Request Object', done => { - store - .dispatch('getMergeRequestData', { projectId: 'abcproject', mergeRequestId: 1 }) - .then(() => { - expect(store.state.projects.abcproject.mergeRequests['1'].title).toBe('mergerequest'); - expect(store.state.currentMergeRequestId).toBe(1); - - done(); - }) - .catch(done.fail); + describe('error', () => { + beforeEach(() => { + mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/).networkError(); + }); + + it('dispatches error action', done => { + const dispatch = jasmine.createSpy('dispatch'); + + getMergeRequestData( + { + commit() {}, + dispatch, + state: store.state, + }, + { projectId: 'abcproject', mergeRequestId: 1 }, + ) + .then(done.fail) + .catch(() => { + expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { + text: 'An error occured whilst loading the merge request.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: { + projectId: 'abcproject', + mergeRequestId: 1, + force: false, + }, + }); + + done(); + }); + }); }); }); describe('getMergeRequestChanges', () => { beforeEach(() => { - spyOn(service, 'getProjectMergeRequestChanges').and.returnValue( - Promise.resolve({ data: { title: 'mergerequest' } }), - ); - store.state.projects.abcproject.mergeRequests['1'] = { changes: [] }; }); - it('calls getProjectMergeRequestChanges service method', done => { - store - .dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 }) - .then(() => { - expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith('abcproject', 1); - - done(); - }) - .catch(done.fail); + describe('success', () => { + beforeEach(() => { + spyOn(service, 'getProjectMergeRequestChanges').and.callThrough(); + + mock + .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/) + .reply(200, { title: 'mergerequest' }); + }); + + it('calls getProjectMergeRequestChanges service method', done => { + store + .dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 }) + .then(() => { + expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith('abcproject', 1); + + done(); + }) + .catch(done.fail); + }); + + it('sets the Merge Request Changes Object', done => { + store + .dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 }) + .then(() => { + expect(store.state.projects.abcproject.mergeRequests['1'].changes.title).toBe( + 'mergerequest', + ); + done(); + }) + .catch(done.fail); + }); }); - it('sets the Merge Request Changes Object', done => { - store - .dispatch('getMergeRequestChanges', { projectId: 'abcproject', mergeRequestId: 1 }) - .then(() => { - expect(store.state.projects.abcproject.mergeRequests['1'].changes.title).toBe( - 'mergerequest', - ); - done(); - }) - .catch(done.fail); + describe('error', () => { + beforeEach(() => { + mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/).networkError(); + }); + + it('dispatches error action', done => { + const dispatch = jasmine.createSpy('dispatch'); + + getMergeRequestChanges( + { + commit() {}, + dispatch, + state: store.state, + }, + { projectId: 'abcproject', mergeRequestId: 1 }, + ) + .then(done.fail) + .catch(() => { + expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { + text: 'An error occured whilst loading the merge request changes.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: { + projectId: 'abcproject', + mergeRequestId: 1, + force: false, + }, + }); + + done(); + }); + }); }); }); describe('getMergeRequestVersions', () => { beforeEach(() => { - spyOn(service, 'getProjectMergeRequestVersions').and.returnValue( - Promise.resolve({ data: [{ id: 789 }] }), - ); - store.state.projects.abcproject.mergeRequests['1'] = { versions: [] }; }); - it('calls getProjectMergeRequestVersions service method', done => { - store - .dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 }) - .then(() => { - expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith('abcproject', 1); - - done(); - }) - .catch(done.fail); + describe('success', () => { + beforeEach(() => { + mock + .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/) + .reply(200, [{ id: 789 }]); + spyOn(service, 'getProjectMergeRequestVersions').and.callThrough(); + }); + + it('calls getProjectMergeRequestVersions service method', done => { + store + .dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 }) + .then(() => { + expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith('abcproject', 1); + + done(); + }) + .catch(done.fail); + }); + + it('sets the Merge Request Versions Object', done => { + store + .dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 }) + .then(() => { + expect(store.state.projects.abcproject.mergeRequests['1'].versions.length).toBe(1); + done(); + }) + .catch(done.fail); + }); }); - it('sets the Merge Request Versions Object', done => { - store - .dispatch('getMergeRequestVersions', { projectId: 'abcproject', mergeRequestId: 1 }) - .then(() => { - expect(store.state.projects.abcproject.mergeRequests['1'].versions.length).toBe(1); - done(); - }) - .catch(done.fail); + describe('error', () => { + beforeEach(() => { + mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/).networkError(); + }); + + it('dispatches error action', done => { + const dispatch = jasmine.createSpy('dispatch'); + + getMergeRequestVersions( + { + commit() {}, + dispatch, + state: store.state, + }, + { projectId: 'abcproject', mergeRequestId: 1 }, + ) + .then(done.fail) + .catch(() => { + expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { + text: 'An error occured whilst loading the merge request version data.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: { + projectId: 'abcproject', + mergeRequestId: 1, + force: false, + }, + }); + + done(); + }); + }); }); }); }); diff --git a/spec/javascripts/ide/stores/actions/tree_spec.js b/spec/javascripts/ide/stores/actions/tree_spec.js index 3ef2a2da880..6860e6cdb91 100644 --- a/spec/javascripts/ide/stores/actions/tree_spec.js +++ b/spec/javascripts/ide/stores/actions/tree_spec.js @@ -116,6 +116,40 @@ describe('Multi-file store tree actions', () => { done(); }); }); + + it('dispatches error action', done => { + const dispatch = jasmine.createSpy('dispatchSpy'); + + store.state.projects = { + 'abc/def': { + web_url: `${gl.TEST_HOST}/files`, + }, + }; + + mock.onGet(/(.*)/).replyOnce(500); + + getFiles( + { + commit() {}, + dispatch, + state: store.state, + }, + { + projectId: 'abc/def', + branchId: 'master-testing', + }, + ) + .then(done.fail) + .catch(() => { + expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { + text: 'An error occured whilst loading all the files.', + action: jasmine.any(Function), + actionText: 'Please try again', + actionPayload: { projectId: 'abc/def', branchId: 'master-testing' }, + }); + done(); + }); + }); }); }); |