diff options
Diffstat (limited to 'spec/frontend/ide/stores/modules')
8 files changed, 271 insertions, 458 deletions
diff --git a/spec/frontend/ide/stores/modules/branches/actions_spec.js b/spec/frontend/ide/stores/modules/branches/actions_spec.js index 135dbc1f746..306330e3ba2 100644 --- a/spec/frontend/ide/stores/modules/branches/actions_spec.js +++ b/spec/frontend/ide/stores/modules/branches/actions_spec.js @@ -42,21 +42,20 @@ describe('IDE branches actions', () => { }); describe('requestBranches', () => { - it('should commit request', (done) => { - testAction( + it('should commit request', () => { + return testAction( requestBranches, null, mockedContext.state, [{ type: types.REQUEST_BRANCHES }], [], - done, ); }); }); describe('receiveBranchesError', () => { - it('should commit error', (done) => { - testAction( + it('should commit error', () => { + return testAction( receiveBranchesError, { search: TEST_SEARCH }, mockedContext.state, @@ -72,20 +71,18 @@ describe('IDE branches actions', () => { }, }, ], - done, ); }); }); describe('receiveBranchesSuccess', () => { - it('should commit received data', (done) => { - testAction( + it('should commit received data', () => { + return testAction( receiveBranchesSuccess, branches, mockedContext.state, [{ type: types.RECEIVE_BRANCHES_SUCCESS, payload: branches }], [], - done, ); }); }); @@ -110,8 +107,8 @@ describe('IDE branches actions', () => { }); }); - it('dispatches success with received data', (done) => { - testAction( + it('dispatches success with received data', () => { + return testAction( fetchBranches, { search: TEST_SEARCH }, mockedState, @@ -121,7 +118,6 @@ describe('IDE branches actions', () => { { type: 'resetBranches' }, { type: 'receiveBranchesSuccess', payload: branches }, ], - done, ); }); }); @@ -131,8 +127,8 @@ describe('IDE branches actions', () => { mock.onGet(/\/api\/v4\/projects\/\d+\/repository\/branches(.*)$/).replyOnce(500); }); - it('dispatches error', (done) => { - testAction( + it('dispatches error', () => { + return testAction( fetchBranches, { search: TEST_SEARCH }, mockedState, @@ -142,20 +138,18 @@ describe('IDE branches actions', () => { { type: 'resetBranches' }, { type: 'receiveBranchesError', payload: { search: TEST_SEARCH } }, ], - done, ); }); }); describe('resetBranches', () => { - it('commits reset', (done) => { - testAction( + it('commits reset', () => { + return testAction( resetBranches, null, mockedContext.state, [{ type: types.RESET_BRANCHES }], [], - done, ); }); }); diff --git a/spec/frontend/ide/stores/modules/clientside/actions_spec.js b/spec/frontend/ide/stores/modules/clientside/actions_spec.js index d2777623b0d..c2b9de192d9 100644 --- a/spec/frontend/ide/stores/modules/clientside/actions_spec.js +++ b/spec/frontend/ide/stores/modules/clientside/actions_spec.js @@ -26,15 +26,13 @@ describe('IDE store module clientside actions', () => { }); describe('pingUsage', () => { - it('posts to usage endpoint', (done) => { + it('posts to usage endpoint', async () => { const usageSpy = jest.fn(() => [200]); mock.onPost(TEST_USAGE_URL).reply(() => usageSpy()); - testAction(actions.pingUsage, PING_USAGE_PREVIEW_KEY, rootGetters, [], [], () => { - expect(usageSpy).toHaveBeenCalled(); - done(); - }); + await testAction(actions.pingUsage, PING_USAGE_PREVIEW_KEY, rootGetters, [], []); + expect(usageSpy).toHaveBeenCalled(); }); }); }); diff --git a/spec/frontend/ide/stores/modules/commit/actions_spec.js b/spec/frontend/ide/stores/modules/commit/actions_spec.js index cb6bb7c1202..d65039e89cc 100644 --- a/spec/frontend/ide/stores/modules/commit/actions_spec.js +++ b/spec/frontend/ide/stores/modules/commit/actions_spec.js @@ -57,40 +57,25 @@ describe('IDE commit module actions', () => { }); describe('updateCommitMessage', () => { - it('updates store with new commit message', (done) => { - store - .dispatch('commit/updateCommitMessage', 'testing') - .then(() => { - expect(store.state.commit.commitMessage).toBe('testing'); - }) - .then(done) - .catch(done.fail); + it('updates store with new commit message', async () => { + await store.dispatch('commit/updateCommitMessage', 'testing'); + expect(store.state.commit.commitMessage).toBe('testing'); }); }); describe('discardDraft', () => { - it('resets commit message to blank', (done) => { + it('resets commit message to blank', async () => { store.state.commit.commitMessage = 'testing'; - store - .dispatch('commit/discardDraft') - .then(() => { - expect(store.state.commit.commitMessage).not.toBe('testing'); - }) - .then(done) - .catch(done.fail); + await store.dispatch('commit/discardDraft'); + expect(store.state.commit.commitMessage).not.toBe('testing'); }); }); describe('updateCommitAction', () => { - it('updates store with new commit action', (done) => { - store - .dispatch('commit/updateCommitAction', '1') - .then(() => { - expect(store.state.commit.commitAction).toBe('1'); - }) - .then(done) - .catch(done.fail); + it('updates store with new commit action', async () => { + await store.dispatch('commit/updateCommitAction', '1'); + expect(store.state.commit.commitAction).toBe('1'); }); }); @@ -139,34 +124,24 @@ describe('IDE commit module actions', () => { }); }); - it('updates commit message with short_id', (done) => { - store - .dispatch('commit/setLastCommitMessage', { short_id: '123' }) - .then(() => { - expect(store.state.lastCommitMsg).toContain( - 'Your changes have been committed. Commit <a href="http://testing/-/commit/123" class="commit-sha">123</a>', - ); - }) - .then(done) - .catch(done.fail); + it('updates commit message with short_id', async () => { + await store.dispatch('commit/setLastCommitMessage', { short_id: '123' }); + expect(store.state.lastCommitMsg).toContain( + 'Your changes have been committed. Commit <a href="http://testing/-/commit/123" class="commit-sha">123</a>', + ); }); - it('updates commit message with stats', (done) => { - store - .dispatch('commit/setLastCommitMessage', { - short_id: '123', - stats: { - additions: '1', - deletions: '2', - }, - }) - .then(() => { - expect(store.state.lastCommitMsg).toBe( - 'Your changes have been committed. Commit <a href="http://testing/-/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.', - ); - }) - .then(done) - .catch(done.fail); + it('updates commit message with stats', async () => { + await store.dispatch('commit/setLastCommitMessage', { + short_id: '123', + stats: { + additions: '1', + deletions: '2', + }, + }); + expect(store.state.lastCommitMsg).toBe( + 'Your changes have been committed. Commit <a href="http://testing/-/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.', + ); }); }); @@ -221,74 +196,49 @@ describe('IDE commit module actions', () => { }); }); - it('updates stores working reference', (done) => { - store - .dispatch('commit/updateFilesAfterCommit', { - data, - branch, - }) - .then(() => { - expect(store.state.projects.abcproject.branches.main.workingReference).toBe(data.id); - }) - .then(done) - .catch(done.fail); + it('updates stores working reference', async () => { + await store.dispatch('commit/updateFilesAfterCommit', { + data, + branch, + }); + expect(store.state.projects.abcproject.branches.main.workingReference).toBe(data.id); }); - it('resets all files changed status', (done) => { - store - .dispatch('commit/updateFilesAfterCommit', { - data, - branch, - }) - .then(() => { - store.state.openFiles.forEach((entry) => { - expect(entry.changed).toBeFalsy(); - }); - }) - .then(done) - .catch(done.fail); + it('resets all files changed status', async () => { + await store.dispatch('commit/updateFilesAfterCommit', { + data, + branch, + }); + store.state.openFiles.forEach((entry) => { + expect(entry.changed).toBeFalsy(); + }); }); - it('sets files commit data', (done) => { - store - .dispatch('commit/updateFilesAfterCommit', { - data, - branch, - }) - .then(() => { - expect(f.lastCommitSha).toBe(data.id); - }) - .then(done) - .catch(done.fail); + it('sets files commit data', async () => { + await store.dispatch('commit/updateFilesAfterCommit', { + data, + branch, + }); + expect(f.lastCommitSha).toBe(data.id); }); - it('updates raw content for changed file', (done) => { - store - .dispatch('commit/updateFilesAfterCommit', { - data, - branch, - }) - .then(() => { - expect(f.raw).toBe(f.content); - }) - .then(done) - .catch(done.fail); + it('updates raw content for changed file', async () => { + await store.dispatch('commit/updateFilesAfterCommit', { + data, + branch, + }); + expect(f.raw).toBe(f.content); }); - it('emits changed event for file', (done) => { - store - .dispatch('commit/updateFilesAfterCommit', { - data, - branch, - }) - .then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.content.${f.key}`, { - content: f.content, - changed: false, - }); - }) - .then(done) - .catch(done.fail); + it('emits changed event for file', async () => { + await store.dispatch('commit/updateFilesAfterCommit', { + data, + branch, + }); + expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.content.${f.key}`, { + content: f.content, + changed: false, + }); }); }); @@ -349,138 +299,93 @@ describe('IDE commit module actions', () => { jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); }); - it('calls service', (done) => { - store - .dispatch('commit/commitChanges') - .then(() => { - expect(service.commit).toHaveBeenCalledWith('abcproject', { - branch: expect.anything(), - commit_message: 'testing 123', - actions: [ - { - action: commitActionTypes.update, - file_path: expect.anything(), - content: '\n', - encoding: expect.anything(), - last_commit_id: undefined, - previous_path: undefined, - }, - ], - start_sha: TEST_COMMIT_SHA, - }); - - done(); - }) - .catch(done.fail); + it('calls service', async () => { + await store.dispatch('commit/commitChanges'); + expect(service.commit).toHaveBeenCalledWith('abcproject', { + branch: expect.anything(), + commit_message: 'testing 123', + actions: [ + { + action: commitActionTypes.update, + file_path: expect.anything(), + content: '\n', + encoding: expect.anything(), + last_commit_id: undefined, + previous_path: undefined, + }, + ], + start_sha: TEST_COMMIT_SHA, + }); }); - it('sends lastCommit ID when not creating new branch', (done) => { + it('sends lastCommit ID when not creating new branch', async () => { store.state.commit.commitAction = '1'; - store - .dispatch('commit/commitChanges') - .then(() => { - expect(service.commit).toHaveBeenCalledWith('abcproject', { - branch: expect.anything(), - commit_message: 'testing 123', - actions: [ - { - action: commitActionTypes.update, - file_path: expect.anything(), - content: '\n', - encoding: expect.anything(), - last_commit_id: TEST_COMMIT_SHA, - previous_path: undefined, - }, - ], - start_sha: undefined, - }); - - done(); - }) - .catch(done.fail); + await store.dispatch('commit/commitChanges'); + expect(service.commit).toHaveBeenCalledWith('abcproject', { + branch: expect.anything(), + commit_message: 'testing 123', + actions: [ + { + action: commitActionTypes.update, + file_path: expect.anything(), + content: '\n', + encoding: expect.anything(), + last_commit_id: TEST_COMMIT_SHA, + previous_path: undefined, + }, + ], + start_sha: undefined, + }); }); - it('sets last Commit Msg', (done) => { - store - .dispatch('commit/commitChanges') - .then(() => { - expect(store.state.lastCommitMsg).toBe( - 'Your changes have been committed. Commit <a href="webUrl/-/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.', - ); - - done(); - }) - .catch(done.fail); + it('sets last Commit Msg', async () => { + await store.dispatch('commit/commitChanges'); + expect(store.state.lastCommitMsg).toBe( + 'Your changes have been committed. Commit <a href="webUrl/-/commit/123" class="commit-sha">123</a> with 1 additions, 2 deletions.', + ); }); - it('adds commit data to files', (done) => { - store - .dispatch('commit/commitChanges') - .then(() => { - expect(store.state.entries[store.state.openFiles[0].path].lastCommitSha).toBe( - COMMIT_RESPONSE.id, - ); - - done(); - }) - .catch(done.fail); + it('adds commit data to files', async () => { + await store.dispatch('commit/commitChanges'); + expect(store.state.entries[store.state.openFiles[0].path].lastCommitSha).toBe( + COMMIT_RESPONSE.id, + ); }); - it('resets stores commit actions', (done) => { + it('resets stores commit actions', async () => { store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH; - store - .dispatch('commit/commitChanges') - .then(() => { - expect(store.state.commit.commitAction).not.toBe(COMMIT_TO_NEW_BRANCH); - }) - .then(done) - .catch(done.fail); + await store.dispatch('commit/commitChanges'); + expect(store.state.commit.commitAction).not.toBe(COMMIT_TO_NEW_BRANCH); }); - it('removes all staged files', (done) => { - store - .dispatch('commit/commitChanges') - .then(() => { - expect(store.state.stagedFiles.length).toBe(0); - }) - .then(done) - .catch(done.fail); + it('removes all staged files', async () => { + await store.dispatch('commit/commitChanges'); + expect(store.state.stagedFiles.length).toBe(0); }); describe('merge request', () => { - it('redirects to new merge request page', (done) => { + it('redirects to new merge request page', async () => { jest.spyOn(eventHub, '$on').mockImplementation(); store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH; store.state.commit.shouldCreateMR = true; - store - .dispatch('commit/commitChanges') - .then(() => { - expect(visitUrl).toHaveBeenCalledWith( - `webUrl/-/merge_requests/new?merge_request[source_branch]=${store.getters['commit/placeholderBranchName']}&merge_request[target_branch]=main&nav_source=webide`, - ); - - done(); - }) - .catch(done.fail); + await store.dispatch('commit/commitChanges'); + expect(visitUrl).toHaveBeenCalledWith( + `webUrl/-/merge_requests/new?merge_request[source_branch]=${store.getters['commit/placeholderBranchName']}&merge_request[target_branch]=main&nav_source=webide`, + ); }); - it('does not redirect to new merge request page when shouldCreateMR is not checked', (done) => { + it('does not redirect to new merge request page when shouldCreateMR is not checked', async () => { jest.spyOn(eventHub, '$on').mockImplementation(); store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH; store.state.commit.shouldCreateMR = false; - store - .dispatch('commit/commitChanges') - .then(() => { - expect(visitUrl).not.toHaveBeenCalled(); - done(); - }) - .catch(done.fail); + await store.dispatch('commit/commitChanges'); + expect(visitUrl).not.toHaveBeenCalled(); }); it('does not redirect to merge request page if shouldCreateMR is checked, but branch is the default branch', async () => { @@ -514,17 +419,11 @@ describe('IDE commit module actions', () => { }); }); - it('shows failed message', (done) => { - store - .dispatch('commit/commitChanges') - .then(() => { - const alert = document.querySelector('.flash-container'); - - expect(alert.textContent.trim()).toBe('failed message'); + it('shows failed message', async () => { + await store.dispatch('commit/commitChanges'); + const alert = document.querySelector('.flash-container'); - done(); - }) - .catch(done.fail); + expect(alert.textContent.trim()).toBe('failed message'); }); }); @@ -548,52 +447,37 @@ describe('IDE commit module actions', () => { }); describe('first commit of a branch', () => { - it('commits TOGGLE_EMPTY_STATE mutation on empty repo', (done) => { + it('commits TOGGLE_EMPTY_STATE mutation on empty repo', async () => { jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); jest.spyOn(store, 'commit'); - store - .dispatch('commit/commitChanges') - .then(() => { - expect(store.commit.mock.calls).toEqual( - expect.arrayContaining([ - ['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)], - ]), - ); - done(); - }) - .catch(done.fail); + await store.dispatch('commit/commitChanges'); + expect(store.commit.mock.calls).toEqual( + expect.arrayContaining([['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)]]), + ); }); - it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', (done) => { + it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', async () => { COMMIT_RESPONSE.parent_ids.push('1234'); jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); jest.spyOn(store, 'commit'); - store - .dispatch('commit/commitChanges') - .then(() => { - expect(store.commit.mock.calls).not.toEqual( - expect.arrayContaining([ - ['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)], - ]), - ); - done(); - }) - .catch(done.fail); + await store.dispatch('commit/commitChanges'); + expect(store.commit.mock.calls).not.toEqual( + expect.arrayContaining([['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)]]), + ); }); }); }); describe('toggleShouldCreateMR', () => { - it('commits both toggle and interacting with MR checkbox actions', (done) => { - testAction( + it('commits both toggle and interacting with MR checkbox actions', () => { + return testAction( actions.toggleShouldCreateMR, {}, store.state, [{ type: mutationTypes.TOGGLE_SHOULD_CREATE_MR }], [], - done, ); }); }); diff --git a/spec/frontend/ide/stores/modules/file_templates/actions_spec.js b/spec/frontend/ide/stores/modules/file_templates/actions_spec.js index 9ff950b0875..1080a30d2d8 100644 --- a/spec/frontend/ide/stores/modules/file_templates/actions_spec.js +++ b/spec/frontend/ide/stores/modules/file_templates/actions_spec.js @@ -20,21 +20,20 @@ describe('IDE file templates actions', () => { }); describe('requestTemplateTypes', () => { - it('commits REQUEST_TEMPLATE_TYPES', (done) => { - testAction( + it('commits REQUEST_TEMPLATE_TYPES', () => { + return testAction( actions.requestTemplateTypes, null, state, [{ type: types.REQUEST_TEMPLATE_TYPES }], [], - done, ); }); }); describe('receiveTemplateTypesError', () => { - it('commits RECEIVE_TEMPLATE_TYPES_ERROR and dispatches setErrorMessage', (done) => { - testAction( + it('commits RECEIVE_TEMPLATE_TYPES_ERROR and dispatches setErrorMessage', () => { + return testAction( actions.receiveTemplateTypesError, null, state, @@ -49,20 +48,18 @@ describe('IDE file templates actions', () => { }, }, ], - done, ); }); }); describe('receiveTemplateTypesSuccess', () => { - it('commits RECEIVE_TEMPLATE_TYPES_SUCCESS', (done) => { - testAction( + it('commits RECEIVE_TEMPLATE_TYPES_SUCCESS', () => { + return testAction( actions.receiveTemplateTypesSuccess, 'test', state, [{ type: types.RECEIVE_TEMPLATE_TYPES_SUCCESS, payload: 'test' }], [], - done, ); }); }); @@ -81,23 +78,17 @@ describe('IDE file templates actions', () => { }); }); - it('rejects if selectedTemplateType is empty', (done) => { + it('rejects if selectedTemplateType is empty', async () => { const dispatch = jest.fn().mockName('dispatch'); - actions - .fetchTemplateTypes({ dispatch, state }) - .then(done.fail) - .catch(() => { - expect(dispatch).not.toHaveBeenCalled(); - - done(); - }); + await expect(actions.fetchTemplateTypes({ dispatch, state })).rejects.toBeUndefined(); + expect(dispatch).not.toHaveBeenCalled(); }); - it('dispatches actions', (done) => { + it('dispatches actions', () => { state.selectedTemplateType = { key: 'licenses' }; - testAction( + return testAction( actions.fetchTemplateTypes, null, state, @@ -111,7 +102,6 @@ describe('IDE file templates actions', () => { payload: pages[0].concat(pages[1]).concat(pages[2]), }, ], - done, ); }); }); @@ -121,16 +111,15 @@ describe('IDE file templates actions', () => { mock.onGet(/api\/(.*)\/templates\/licenses/).replyOnce(500); }); - it('dispatches actions', (done) => { + it('dispatches actions', () => { state.selectedTemplateType = { key: 'licenses' }; - testAction( + return testAction( actions.fetchTemplateTypes, null, state, [], [{ type: 'requestTemplateTypes' }, { type: 'receiveTemplateTypesError' }], - done, ); }); }); @@ -184,8 +173,8 @@ describe('IDE file templates actions', () => { }); describe('receiveTemplateError', () => { - it('dispatches setErrorMessage', (done) => { - testAction( + it('dispatches setErrorMessage', () => { + return testAction( actions.receiveTemplateError, 'test', state, @@ -201,7 +190,6 @@ describe('IDE file templates actions', () => { }, }, ], - done, ); }); }); @@ -217,46 +205,43 @@ describe('IDE file templates actions', () => { .replyOnce(200, { content: 'testing content' }); }); - it('dispatches setFileTemplate if template already has content', (done) => { + it('dispatches setFileTemplate if template already has content', () => { const template = { content: 'already has content' }; - testAction( + return testAction( actions.fetchTemplate, template, state, [], [{ type: 'setFileTemplate', payload: template }], - done, ); }); - it('dispatches success', (done) => { + it('dispatches success', () => { const template = { key: 'mit' }; state.selectedTemplateType = { key: 'licenses' }; - testAction( + return testAction( actions.fetchTemplate, template, state, [], [{ type: 'setFileTemplate', payload: { content: 'MIT content' } }], - done, ); }); - it('dispatches success and uses name key for API call', (done) => { + it('dispatches success and uses name key for API call', () => { const template = { name: 'testing' }; state.selectedTemplateType = { key: 'licenses' }; - testAction( + return testAction( actions.fetchTemplate, template, state, [], [{ type: 'setFileTemplate', payload: { content: 'testing content' } }], - done, ); }); }); @@ -266,18 +251,17 @@ describe('IDE file templates actions', () => { mock.onGet(/api\/(.*)\/templates\/licenses\/mit/).replyOnce(500); }); - it('dispatches error', (done) => { + it('dispatches error', () => { const template = { name: 'testing' }; state.selectedTemplateType = { key: 'licenses' }; - testAction( + return testAction( actions.fetchTemplate, template, state, [], [{ type: 'receiveTemplateError', payload: template }], - done, ); }); }); diff --git a/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js b/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js index e1f2b165dd9..344fe3a41c3 100644 --- a/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js +++ b/spec/frontend/ide/stores/modules/merge_requests/actions_spec.js @@ -28,21 +28,20 @@ describe('IDE merge requests actions', () => { }); describe('requestMergeRequests', () => { - it('should commit request', (done) => { - testAction( + it('should commit request', () => { + return testAction( requestMergeRequests, null, mockedState, [{ type: types.REQUEST_MERGE_REQUESTS }], [], - done, ); }); }); describe('receiveMergeRequestsError', () => { - it('should commit error', (done) => { - testAction( + it('should commit error', () => { + return testAction( receiveMergeRequestsError, { type: 'created', search: '' }, mockedState, @@ -58,20 +57,18 @@ describe('IDE merge requests actions', () => { }, }, ], - done, ); }); }); describe('receiveMergeRequestsSuccess', () => { - it('should commit received data', (done) => { - testAction( + it('should commit received data', () => { + return testAction( receiveMergeRequestsSuccess, mergeRequests, mockedState, [{ type: types.RECEIVE_MERGE_REQUESTS_SUCCESS, payload: mergeRequests }], [], - done, ); }); }); @@ -118,8 +115,8 @@ describe('IDE merge requests actions', () => { }); }); - it('dispatches success with received data', (done) => { - testAction( + it('dispatches success with received data', () => { + return testAction( fetchMergeRequests, { type: 'created' }, mockedState, @@ -129,7 +126,6 @@ describe('IDE merge requests actions', () => { { type: 'resetMergeRequests' }, { type: 'receiveMergeRequestsSuccess', payload: mergeRequests }, ], - done, ); }); }); @@ -156,8 +152,8 @@ describe('IDE merge requests actions', () => { ); }); - it('dispatches success with received data', (done) => { - testAction( + it('dispatches success with received data', () => { + return testAction( fetchMergeRequests, { type: null }, { ...mockedState, ...mockedRootState }, @@ -167,7 +163,6 @@ describe('IDE merge requests actions', () => { { type: 'resetMergeRequests' }, { type: 'receiveMergeRequestsSuccess', payload: mergeRequests }, ], - done, ); }); }); @@ -177,8 +172,8 @@ describe('IDE merge requests actions', () => { mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(500); }); - it('dispatches error', (done) => { - testAction( + it('dispatches error', () => { + return testAction( fetchMergeRequests, { type: 'created', search: '' }, mockedState, @@ -188,21 +183,19 @@ describe('IDE merge requests actions', () => { { type: 'resetMergeRequests' }, { type: 'receiveMergeRequestsError', payload: { type: 'created', search: '' } }, ], - done, ); }); }); }); describe('resetMergeRequests', () => { - it('commits reset', (done) => { - testAction( + it('commits reset', () => { + return testAction( resetMergeRequests, null, mockedState, [{ type: types.RESET_MERGE_REQUESTS }], [], - done, ); }); }); diff --git a/spec/frontend/ide/stores/modules/pane/actions_spec.js b/spec/frontend/ide/stores/modules/pane/actions_spec.js index 42fe8b400b8..98c4f22dac8 100644 --- a/spec/frontend/ide/stores/modules/pane/actions_spec.js +++ b/spec/frontend/ide/stores/modules/pane/actions_spec.js @@ -7,19 +7,19 @@ describe('IDE pane module actions', () => { const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true }; describe('toggleOpen', () => { - it('dispatches open if closed', (done) => { - testAction(actions.toggleOpen, TEST_VIEW, { isOpen: false }, [], [{ type: 'open' }], done); + it('dispatches open if closed', () => { + return testAction(actions.toggleOpen, TEST_VIEW, { isOpen: false }, [], [{ type: 'open' }]); }); - it('dispatches close if opened', (done) => { - testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }], done); + it('dispatches close if opened', () => { + return testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }]); }); }); describe('open', () => { describe('with a view specified', () => { - it('commits SET_OPEN and SET_CURRENT_VIEW', (done) => { - testAction( + it('commits SET_OPEN and SET_CURRENT_VIEW', () => { + return testAction( actions.open, TEST_VIEW, {}, @@ -28,12 +28,11 @@ describe('IDE pane module actions', () => { { type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name }, ], [], - done, ); }); - it('commits KEEP_ALIVE_VIEW if keepAlive is true', (done) => { - testAction( + it('commits KEEP_ALIVE_VIEW if keepAlive is true', () => { + return testAction( actions.open, TEST_VIEW_KEEP_ALIVE, {}, @@ -43,28 +42,26 @@ describe('IDE pane module actions', () => { { type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name }, ], [], - done, ); }); }); describe('without a view specified', () => { - it('commits SET_OPEN', (done) => { - testAction( + it('commits SET_OPEN', () => { + return testAction( actions.open, undefined, {}, [{ type: types.SET_OPEN, payload: true }], [], - done, ); }); }); }); describe('close', () => { - it('commits SET_OPEN', (done) => { - testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], [], done); + it('commits SET_OPEN', () => { + return testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], []); }); }); }); diff --git a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js index 3ede37e2eed..b76b673c3a2 100644 --- a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js +++ b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js @@ -25,6 +25,7 @@ import { import * as types from '~/ide/stores/modules/pipelines/mutation_types'; import state from '~/ide/stores/modules/pipelines/state'; import axios from '~/lib/utils/axios_utils'; +import waitForPromises from 'helpers/wait_for_promises'; import { pipelines, jobs } from '../../../mock_data'; describe('IDE pipelines actions', () => { @@ -44,32 +45,30 @@ describe('IDE pipelines actions', () => { }); describe('requestLatestPipeline', () => { - it('commits request', (done) => { - testAction( + it('commits request', () => { + return testAction( requestLatestPipeline, null, mockedState, [{ type: types.REQUEST_LATEST_PIPELINE }], [], - done, ); }); }); describe('receiveLatestPipelineError', () => { - it('commits error', (done) => { - testAction( + it('commits error', () => { + return testAction( receiveLatestPipelineError, { status: 404 }, mockedState, [{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }], [{ type: 'stopPipelinePolling' }], - done, ); }); - it('dispatches setErrorMessage is not 404', (done) => { - testAction( + it('dispatches setErrorMessage is not 404', () => { + return testAction( receiveLatestPipelineError, { status: 500 }, mockedState, @@ -86,7 +85,6 @@ describe('IDE pipelines actions', () => { }, { type: 'stopPipelinePolling' }, ], - done, ); }); }); @@ -123,7 +121,7 @@ describe('IDE pipelines actions', () => { .reply(200, { data: { foo: 'bar' } }, { 'poll-interval': '10000' }); }); - it('dispatches request', (done) => { + it('dispatches request', async () => { jest.spyOn(axios, 'get'); jest.spyOn(Visibility, 'hidden').mockReturnValue(false); @@ -133,34 +131,21 @@ describe('IDE pipelines actions', () => { currentProject: { path_with_namespace: 'abc/def' }, }; - fetchLatestPipeline({ dispatch, rootGetters }); + await fetchLatestPipeline({ dispatch, rootGetters }); expect(dispatch).toHaveBeenCalledWith('requestLatestPipeline'); - jest.advanceTimersByTime(1000); - - new Promise((resolve) => requestAnimationFrame(resolve)) - .then(() => { - expect(axios.get).toHaveBeenCalled(); - expect(axios.get).toHaveBeenCalledTimes(1); - expect(dispatch).toHaveBeenCalledWith( - 'receiveLatestPipelineSuccess', - expect.anything(), - ); - - jest.advanceTimersByTime(10000); - }) - .then(() => new Promise((resolve) => requestAnimationFrame(resolve))) - .then(() => { - expect(axios.get).toHaveBeenCalled(); - expect(axios.get).toHaveBeenCalledTimes(2); - expect(dispatch).toHaveBeenCalledWith( - 'receiveLatestPipelineSuccess', - expect.anything(), - ); - }) - .then(done) - .catch(done.fail); + await waitForPromises(); + + expect(axios.get).toHaveBeenCalled(); + expect(axios.get).toHaveBeenCalledTimes(1); + expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineSuccess', expect.anything()); + + jest.advanceTimersByTime(10000); + + expect(axios.get).toHaveBeenCalled(); + expect(axios.get).toHaveBeenCalledTimes(2); + expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineSuccess', expect.anything()); }); }); @@ -169,27 +154,22 @@ describe('IDE pipelines actions', () => { mock.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines').reply(500); }); - it('dispatches error', (done) => { + it('dispatches error', async () => { const dispatch = jest.fn().mockName('dispatch'); const rootGetters = { lastCommit: { id: 'abc123def456ghi789jkl' }, currentProject: { path_with_namespace: 'abc/def' }, }; - fetchLatestPipeline({ dispatch, rootGetters }); + await fetchLatestPipeline({ dispatch, rootGetters }); - jest.advanceTimersByTime(1500); + await waitForPromises(); - new Promise((resolve) => requestAnimationFrame(resolve)) - .then(() => { - expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything()); - }) - .then(done) - .catch(done.fail); + expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything()); }); }); - it('sets latest pipeline to `null` and stops polling on empty project', (done) => { + it('sets latest pipeline to `null` and stops polling on empty project', () => { mockedState = { ...mockedState, rootGetters: { @@ -197,26 +177,31 @@ describe('IDE pipelines actions', () => { }, }; - testAction( + return testAction( fetchLatestPipeline, {}, mockedState, [{ type: types.RECEIVE_LASTEST_PIPELINE_SUCCESS, payload: null }], [{ type: 'stopPipelinePolling' }], - done, ); }); }); describe('requestJobs', () => { - it('commits request', (done) => { - testAction(requestJobs, 1, mockedState, [{ type: types.REQUEST_JOBS, payload: 1 }], [], done); + it('commits request', () => { + return testAction( + requestJobs, + 1, + mockedState, + [{ type: types.REQUEST_JOBS, payload: 1 }], + [], + ); }); }); describe('receiveJobsError', () => { - it('commits error', (done) => { - testAction( + it('commits error', () => { + return testAction( receiveJobsError, { id: 1 }, mockedState, @@ -232,20 +217,18 @@ describe('IDE pipelines actions', () => { }, }, ], - done, ); }); }); describe('receiveJobsSuccess', () => { - it('commits data', (done) => { - testAction( + it('commits data', () => { + return testAction( receiveJobsSuccess, { id: 1, data: jobs }, mockedState, [{ type: types.RECEIVE_JOBS_SUCCESS, payload: { id: 1, data: jobs } }], [], - done, ); }); }); @@ -258,8 +241,8 @@ describe('IDE pipelines actions', () => { mock.onGet(stage.dropdownPath).replyOnce(200, jobs); }); - it('dispatches request', (done) => { - testAction( + it('dispatches request', () => { + return testAction( fetchJobs, stage, mockedState, @@ -268,7 +251,6 @@ describe('IDE pipelines actions', () => { { type: 'requestJobs', payload: stage.id }, { type: 'receiveJobsSuccess', payload: { id: stage.id, data: jobs } }, ], - done, ); }); }); @@ -278,8 +260,8 @@ describe('IDE pipelines actions', () => { mock.onGet(stage.dropdownPath).replyOnce(500); }); - it('dispatches error', (done) => { - testAction( + it('dispatches error', () => { + return testAction( fetchJobs, stage, mockedState, @@ -288,69 +270,64 @@ describe('IDE pipelines actions', () => { { type: 'requestJobs', payload: stage.id }, { type: 'receiveJobsError', payload: stage }, ], - done, ); }); }); }); describe('toggleStageCollapsed', () => { - it('commits collapse', (done) => { - testAction( + it('commits collapse', () => { + return testAction( toggleStageCollapsed, 1, mockedState, [{ type: types.TOGGLE_STAGE_COLLAPSE, payload: 1 }], [], - done, ); }); }); describe('setDetailJob', () => { - it('commits job', (done) => { - testAction( + it('commits job', () => { + return testAction( setDetailJob, 'job', mockedState, [{ type: types.SET_DETAIL_JOB, payload: 'job' }], [{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }], - done, ); }); - it('dispatches rightPane/open as pipeline when job is null', (done) => { - testAction( + it('dispatches rightPane/open as pipeline when job is null', () => { + return testAction( setDetailJob, null, mockedState, [{ type: types.SET_DETAIL_JOB, payload: null }], [{ type: 'rightPane/open', payload: rightSidebarViews.pipelines }], - done, ); }); - it('dispatches rightPane/open as job', (done) => { - testAction( + it('dispatches rightPane/open as job', () => { + return testAction( setDetailJob, 'job', mockedState, [{ type: types.SET_DETAIL_JOB, payload: 'job' }], [{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }], - done, ); }); }); describe('requestJobLogs', () => { - it('commits request', (done) => { - testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], [], done); + it('commits request', () => { + return testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], []); }); }); describe('receiveJobLogsError', () => { - it('commits error', (done) => { - testAction( + it('commits error', () => { + return testAction( receiveJobLogsError, null, mockedState, @@ -366,20 +343,18 @@ describe('IDE pipelines actions', () => { }, }, ], - done, ); }); }); describe('receiveJobLogsSuccess', () => { - it('commits data', (done) => { - testAction( + it('commits data', () => { + return testAction( receiveJobLogsSuccess, 'data', mockedState, [{ type: types.RECEIVE_JOB_LOGS_SUCCESS, payload: 'data' }], [], - done, ); }); }); @@ -395,8 +370,8 @@ describe('IDE pipelines actions', () => { mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' }); }); - it('dispatches request', (done) => { - testAction( + it('dispatches request', () => { + return testAction( fetchJobLogs, null, mockedState, @@ -405,7 +380,6 @@ describe('IDE pipelines actions', () => { { type: 'requestJobLogs' }, { type: 'receiveJobLogsSuccess', payload: { html: 'html' } }, ], - done, ); }); @@ -426,22 +400,21 @@ describe('IDE pipelines actions', () => { mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500); }); - it('dispatches error', (done) => { - testAction( + it('dispatches error', () => { + return testAction( fetchJobLogs, null, mockedState, [], [{ type: 'requestJobLogs' }, { type: 'receiveJobLogsError' }], - done, ); }); }); }); describe('resetLatestPipeline', () => { - it('commits reset mutations', (done) => { - testAction( + it('commits reset mutations', () => { + return testAction( resetLatestPipeline, null, mockedState, @@ -450,7 +423,6 @@ describe('IDE pipelines actions', () => { { type: types.SET_DETAIL_JOB, payload: null }, ], [], - done, ); }); }); diff --git a/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js b/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js index 22b0615c6d0..448fd909f39 100644 --- a/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js +++ b/spec/frontend/ide/stores/modules/terminal_sync/actions_spec.js @@ -22,43 +22,37 @@ describe('ide/stores/modules/terminal_sync/actions', () => { }); describe('upload', () => { - it('uploads to mirror and sets success', (done) => { + it('uploads to mirror and sets success', async () => { mirror.upload.mockReturnValue(Promise.resolve()); - testAction( + await testAction( actions.upload, null, rootState, [{ type: types.START_LOADING }, { type: types.SET_SUCCESS }], [], - () => { - expect(mirror.upload).toHaveBeenCalledWith(rootState); - done(); - }, ); + expect(mirror.upload).toHaveBeenCalledWith(rootState); }); - it('sets error when failed', (done) => { + it('sets error when failed', () => { const err = { message: 'it failed!' }; mirror.upload.mockReturnValue(Promise.reject(err)); - testAction( + return testAction( actions.upload, null, rootState, [{ type: types.START_LOADING }, { type: types.SET_ERROR, payload: err }], [], - done, ); }); }); describe('stop', () => { - it('disconnects from mirror', (done) => { - testAction(actions.stop, null, rootState, [{ type: types.STOP }], [], () => { - expect(mirror.disconnect).toHaveBeenCalled(); - done(); - }); + it('disconnects from mirror', async () => { + await testAction(actions.stop, null, rootState, [{ type: types.STOP }], []); + expect(mirror.disconnect).toHaveBeenCalled(); }); }); @@ -83,20 +77,17 @@ describe('ide/stores/modules/terminal_sync/actions', () => { }; }); - it('connects to mirror and sets success', (done) => { + it('connects to mirror and sets success', async () => { mirror.connect.mockReturnValue(Promise.resolve()); - testAction( + await testAction( actions.start, null, rootState, [{ type: types.START_LOADING }, { type: types.SET_SUCCESS }], [], - () => { - expect(mirror.connect).toHaveBeenCalledWith(TEST_SESSION.proxyWebsocketPath); - done(); - }, ); + expect(mirror.connect).toHaveBeenCalledWith(TEST_SESSION.proxyWebsocketPath); }); it('sets error if connection fails', () => { |