Commit 10109de8 authored by Vitaly Slobodin's avatar Vitaly Slobodin Committed by Peter Hegman

Remove jest test callbacks from IDE specs

Jest 27 does not support the test callback anymore so
the following code is no longer valid:

```
it('test', (done) => { /* code */ })
```
parent e926bab8
...@@ -69,15 +69,14 @@ describe('new dropdown upload', () => { ...@@ -69,15 +69,14 @@ describe('new dropdown upload', () => {
jest.spyOn(FileReader.prototype, 'readAsText'); jest.spyOn(FileReader.prototype, 'readAsText');
}); });
it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', (done) => { it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', async () => {
const waitForCreate = new Promise((resolve) => vm.$on('create', resolve)); const waitForCreate = new Promise((resolve) => vm.$on('create', resolve));
vm.createFile(textTarget, textFile); vm.createFile(textTarget, textFile);
expect(FileReader.prototype.readAsText).toHaveBeenCalledWith(textFile); expect(FileReader.prototype.readAsText).toHaveBeenCalledWith(textFile);
waitForCreate await waitForCreate;
.then(() => {
expect(vm.$emit).toHaveBeenCalledWith('create', { expect(vm.$emit).toHaveBeenCalledWith('create', {
name: textFile.name, name: textFile.name,
type: 'blob', type: 'blob',
...@@ -85,9 +84,6 @@ describe('new dropdown upload', () => { ...@@ -85,9 +84,6 @@ describe('new dropdown upload', () => {
rawPath: '', rawPath: '',
mimeType: 'test/mime-text', mimeType: 'test/mime-text',
}); });
})
.then(done)
.catch(done.fail);
}); });
it('creates a blob URL for the content if binary', () => { it('creates a blob URL for the content if binary', () => {
......
...@@ -146,22 +146,16 @@ describe('IDE store project actions', () => { ...@@ -146,22 +146,16 @@ describe('IDE store project actions', () => {
}); });
}); });
it('calls the service', (done) => { it('calls the service', async () => {
store await store.dispatch('refreshLastCommitData', {
.dispatch('refreshLastCommitData', {
projectId: store.state.currentProjectId, projectId: store.state.currentProjectId,
branchId: store.state.currentBranchId, branchId: store.state.currentBranchId,
}) });
.then(() => {
expect(service.getBranchData).toHaveBeenCalledWith('abc/def', 'main'); expect(service.getBranchData).toHaveBeenCalledWith('abc/def', 'main');
done();
})
.catch(done.fail);
}); });
it('commits getBranchData', (done) => { it('commits getBranchData', () => {
testAction( return testAction(
refreshLastCommitData, refreshLastCommitData,
{ {
projectId: store.state.currentProjectId, projectId: store.state.currentProjectId,
...@@ -181,14 +175,13 @@ describe('IDE store project actions', () => { ...@@ -181,14 +175,13 @@ describe('IDE store project actions', () => {
], ],
// action // action
[], [],
done,
); );
}); });
}); });
describe('showBranchNotFoundError', () => { describe('showBranchNotFoundError', () => {
it('dispatches setErrorMessage', (done) => { it('dispatches setErrorMessage', () => {
testAction( return testAction(
showBranchNotFoundError, showBranchNotFoundError,
'main', 'main',
null, null,
...@@ -204,7 +197,6 @@ describe('IDE store project actions', () => { ...@@ -204,7 +197,6 @@ describe('IDE store project actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
...@@ -216,8 +208,8 @@ describe('IDE store project actions', () => { ...@@ -216,8 +208,8 @@ describe('IDE store project actions', () => {
jest.spyOn(api, 'createBranch').mockResolvedValue(); jest.spyOn(api, 'createBranch').mockResolvedValue();
}); });
it('calls API', (done) => { it('calls API', async () => {
createNewBranchFromDefault( await createNewBranchFromDefault(
{ {
state: { state: {
currentProjectId: 'project-path', currentProjectId: 'project-path',
...@@ -230,21 +222,17 @@ describe('IDE store project actions', () => { ...@@ -230,21 +222,17 @@ describe('IDE store project actions', () => {
dispatch() {}, dispatch() {},
}, },
'new-branch-name', 'new-branch-name',
) );
.then(() => {
expect(api.createBranch).toHaveBeenCalledWith('project-path', { expect(api.createBranch).toHaveBeenCalledWith('project-path', {
ref: 'main', ref: 'main',
branch: 'new-branch-name', branch: 'new-branch-name',
}); });
})
.then(done)
.catch(done.fail);
}); });
it('clears error message', (done) => { it('clears error message', async () => {
const dispatchSpy = jest.fn().mockName('dispatch'); const dispatchSpy = jest.fn().mockName('dispatch');
createNewBranchFromDefault( await createNewBranchFromDefault(
{ {
state: { state: {
currentProjectId: 'project-path', currentProjectId: 'project-path',
...@@ -257,16 +245,12 @@ describe('IDE store project actions', () => { ...@@ -257,16 +245,12 @@ describe('IDE store project actions', () => {
dispatch: dispatchSpy, dispatch: dispatchSpy,
}, },
'new-branch-name', 'new-branch-name',
) );
.then(() => {
expect(dispatchSpy).toHaveBeenCalledWith('setErrorMessage', null); expect(dispatchSpy).toHaveBeenCalledWith('setErrorMessage', null);
})
.then(done)
.catch(done.fail);
}); });
it('reloads window', (done) => { it('reloads window', async () => {
createNewBranchFromDefault( await createNewBranchFromDefault(
{ {
state: { state: {
currentProjectId: 'project-path', currentProjectId: 'project-path',
...@@ -279,18 +263,14 @@ describe('IDE store project actions', () => { ...@@ -279,18 +263,14 @@ describe('IDE store project actions', () => {
dispatch() {}, dispatch() {},
}, },
'new-branch-name', 'new-branch-name',
) );
.then(() => {
expect(window.location.reload).toHaveBeenCalled(); expect(window.location.reload).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
}); });
}); });
describe('loadEmptyBranch', () => { describe('loadEmptyBranch', () => {
it('creates a blank tree and sets loading state to false', (done) => { it('creates a blank tree and sets loading state to false', () => {
testAction( return testAction(
loadEmptyBranch, loadEmptyBranch,
{ projectId: TEST_PROJECT_ID, branchId: 'main' }, { projectId: TEST_PROJECT_ID, branchId: 'main' },
store.state, store.state,
...@@ -302,20 +282,18 @@ describe('IDE store project actions', () => { ...@@ -302,20 +282,18 @@ describe('IDE store project actions', () => {
}, },
], ],
expect.any(Object), expect.any(Object),
done,
); );
}); });
it('does nothing, if tree already exists', (done) => { it('does nothing, if tree already exists', () => {
const trees = { [`${TEST_PROJECT_ID}/main`]: [] }; const trees = { [`${TEST_PROJECT_ID}/main`]: [] };
testAction( return testAction(
loadEmptyBranch, loadEmptyBranch,
{ projectId: TEST_PROJECT_ID, branchId: 'main' }, { projectId: TEST_PROJECT_ID, branchId: 'main' },
{ trees }, { trees },
[], [],
[], [],
done,
); );
}); });
}); });
...@@ -372,56 +350,48 @@ describe('IDE store project actions', () => { ...@@ -372,56 +350,48 @@ describe('IDE store project actions', () => {
const branchId = '123-lorem'; const branchId = '123-lorem';
const ref = 'abcd2322'; const ref = 'abcd2322';
it('when empty repo, loads empty branch', (done) => { it('when empty repo, loads empty branch', () => {
const mockGetters = { emptyRepo: true }; const mockGetters = { emptyRepo: true };
testAction( return testAction(
loadBranch, loadBranch,
{ projectId, branchId }, { projectId, branchId },
{ ...store.state, ...mockGetters }, { ...store.state, ...mockGetters },
[], [],
[{ type: 'loadEmptyBranch', payload: { projectId, branchId } }], [{ type: 'loadEmptyBranch', payload: { projectId, branchId } }],
done,
); );
}); });
it('when branch already exists, does nothing', (done) => { it('when branch already exists, does nothing', () => {
store.state.projects[projectId].branches[branchId] = {}; store.state.projects[projectId].branches[branchId] = {};
testAction(loadBranch, { projectId, branchId }, store.state, [], [], done); return testAction(loadBranch, { projectId, branchId }, store.state, [], []);
}); });
it('fetches branch data', (done) => { it('fetches branch data', async () => {
const mockGetters = { findBranch: () => ({ commit: { id: ref } }) }; const mockGetters = { findBranch: () => ({ commit: { id: ref } }) };
jest.spyOn(store, 'dispatch').mockResolvedValue(); jest.spyOn(store, 'dispatch').mockResolvedValue();
loadBranch( await loadBranch(
{ getters: mockGetters, state: store.state, dispatch: store.dispatch }, { getters: mockGetters, state: store.state, dispatch: store.dispatch },
{ projectId, branchId }, { projectId, branchId },
) );
.then(() => {
expect(store.dispatch.mock.calls).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }], ['getBranchData', { projectId, branchId }],
['getMergeRequestsForBranch', { projectId, branchId }], ['getMergeRequestsForBranch', { projectId, branchId }],
['getFiles', { projectId, branchId, ref }], ['getFiles', { projectId, branchId, ref }],
]); ]);
})
.then(done)
.catch(done.fail);
}); });
it('shows an error if branch can not be fetched', (done) => { it('shows an error if branch can not be fetched', async () => {
jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject()); jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject());
loadBranch(store, { projectId, branchId }) await expect(loadBranch(store, { projectId, branchId })).rejects.toBeUndefined();
.then(done.fail)
.catch(() => {
expect(store.dispatch.mock.calls).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }], ['getBranchData', { projectId, branchId }],
['showBranchNotFoundError', branchId], ['showBranchNotFoundError', branchId],
]); ]);
done();
});
}); });
}); });
...@@ -449,17 +419,13 @@ describe('IDE store project actions', () => { ...@@ -449,17 +419,13 @@ describe('IDE store project actions', () => {
jest.spyOn(store, 'dispatch').mockResolvedValue(); jest.spyOn(store, 'dispatch').mockResolvedValue();
}); });
it('dispatches branch actions', (done) => { it('dispatches branch actions', async () => {
openBranch(store, branch) await openBranch(store, branch);
.then(() => {
expect(store.dispatch.mock.calls).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId], ['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }], ['loadBranch', { projectId, branchId }],
['loadFile', { basePath: undefined }], ['loadFile', { basePath: undefined }],
]); ]);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -468,9 +434,8 @@ describe('IDE store project actions', () => { ...@@ -468,9 +434,8 @@ describe('IDE store project actions', () => {
jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject()); jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject());
}); });
it('dispatches correct branch actions', (done) => { it('dispatches correct branch actions', async () => {
openBranch(store, branch) const val = await openBranch(store, branch);
.then((val) => {
expect(store.dispatch.mock.calls).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId], ['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }], ['loadBranch', { projectId, branchId }],
...@@ -481,9 +446,6 @@ describe('IDE store project actions', () => { ...@@ -481,9 +446,6 @@ describe('IDE store project actions', () => {
`An error occurred while getting files for - <strong>${projectId}/${branchId}</strong>`, `An error occurred while getting files for - <strong>${projectId}/${branchId}</strong>`,
), ),
); );
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
......
...@@ -62,10 +62,8 @@ describe('Multi-file store tree actions', () => { ...@@ -62,10 +62,8 @@ describe('Multi-file store tree actions', () => {
}); });
}); });
it('adds data into tree', (done) => { it('adds data into tree', async () => {
store await store.dispatch('getFiles', basicCallParameters);
.dispatch('getFiles', basicCallParameters)
.then(() => {
projectTree = store.state.trees['abcproject/main']; projectTree = store.state.trees['abcproject/main'];
expect(projectTree.tree.length).toBe(2); expect(projectTree.tree.length).toBe(2);
...@@ -74,15 +72,11 @@ describe('Multi-file store tree actions', () => { ...@@ -74,15 +72,11 @@ describe('Multi-file store tree actions', () => {
expect(projectTree.tree[1].type).toBe('blob'); expect(projectTree.tree[1].type).toBe('blob');
expect(projectTree.tree[0].tree[0].tree[0].type).toBe('blob'); expect(projectTree.tree[0].tree[0].tree[0].type).toBe('blob');
expect(projectTree.tree[0].tree[0].tree[0].name).toBe('fileinsubfolder.js'); expect(projectTree.tree[0].tree[0].tree[0].name).toBe('fileinsubfolder.js');
done();
})
.catch(done.fail);
}); });
}); });
describe('error', () => { describe('error', () => {
it('dispatches error action', (done) => { it('dispatches error action', async () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
store.state.projects = { store.state.projects = {
...@@ -103,6 +97,7 @@ describe('Multi-file store tree actions', () => { ...@@ -103,6 +97,7 @@ describe('Multi-file store tree actions', () => {
mock.onGet(/(.*)/).replyOnce(500); mock.onGet(/(.*)/).replyOnce(500);
await expect(
getFiles( getFiles(
{ {
commit() {}, commit() {},
...@@ -114,17 +109,14 @@ describe('Multi-file store tree actions', () => { ...@@ -114,17 +109,14 @@ describe('Multi-file store tree actions', () => {
projectId: 'abc/def', projectId: 'abc/def',
branchId: 'main-testing', branchId: 'main-testing',
}, },
) ),
.then(done.fail) ).rejects.toEqual(new Error('Request failed with status code 500'));
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading all the files.', text: 'An error occurred while loading all the files.',
action: expect.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { projectId: 'abc/def', branchId: 'main-testing' }, actionPayload: { projectId: 'abc/def', branchId: 'main-testing' },
}); });
done();
});
}); });
}); });
}); });
...@@ -137,15 +129,9 @@ describe('Multi-file store tree actions', () => { ...@@ -137,15 +129,9 @@ describe('Multi-file store tree actions', () => {
store.state.entries[tree.path] = tree; store.state.entries[tree.path] = tree;
}); });
it('toggles the tree open', (done) => { it('toggles the tree open', async () => {
store await store.dispatch('toggleTreeOpen', tree.path);
.dispatch('toggleTreeOpen', tree.path)
.then(() => {
expect(tree.opened).toBeTruthy(); expect(tree.opened).toBeTruthy();
done();
})
.catch(done.fail);
}); });
}); });
...@@ -163,24 +149,23 @@ describe('Multi-file store tree actions', () => { ...@@ -163,24 +149,23 @@ describe('Multi-file store tree actions', () => {
Object.assign(store.state.entries, createEntriesFromPaths(paths)); Object.assign(store.state.entries, createEntriesFromPaths(paths));
}); });
it('opens the parents', (done) => { it('opens the parents', () => {
testAction( return testAction(
showTreeEntry, showTreeEntry,
'grandparent/parent/child.txt', 'grandparent/parent/child.txt',
store.state, store.state,
[{ type: types.SET_TREE_OPEN, payload: 'grandparent/parent' }], [{ type: types.SET_TREE_OPEN, payload: 'grandparent/parent' }],
[{ type: 'showTreeEntry', payload: 'grandparent/parent' }], [{ type: 'showTreeEntry', payload: 'grandparent/parent' }],
done,
); );
}); });
}); });
describe('setDirectoryData', () => { describe('setDirectoryData', () => {
it('sets tree correctly if there are no opened files yet', (done) => { it('sets tree correctly if there are no opened files yet', () => {
const treeFile = file({ name: 'README.md' }); const treeFile = file({ name: 'README.md' });
store.state.trees['abcproject/main'] = {}; store.state.trees['abcproject/main'] = {};
testAction( return testAction(
setDirectoryData, setDirectoryData,
{ projectId: 'abcproject', branchId: 'main', treeList: [treeFile] }, { projectId: 'abcproject', branchId: 'main', treeList: [treeFile] },
store.state, store.state,
...@@ -201,7 +186,6 @@ describe('Multi-file store tree actions', () => { ...@@ -201,7 +186,6 @@ describe('Multi-file store tree actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
......
This diff is collapsed.
...@@ -42,21 +42,20 @@ describe('IDE branches actions', () => { ...@@ -42,21 +42,20 @@ describe('IDE branches actions', () => {
}); });
describe('requestBranches', () => { describe('requestBranches', () => {
it('should commit request', (done) => { it('should commit request', () => {
testAction( return testAction(
requestBranches, requestBranches,
null, null,
mockedContext.state, mockedContext.state,
[{ type: types.REQUEST_BRANCHES }], [{ type: types.REQUEST_BRANCHES }],
[], [],
done,
); );
}); });
}); });
describe('receiveBranchesError', () => { describe('receiveBranchesError', () => {
it('should commit error', (done) => { it('should commit error', () => {
testAction( return testAction(
receiveBranchesError, receiveBranchesError,
{ search: TEST_SEARCH }, { search: TEST_SEARCH },
mockedContext.state, mockedContext.state,
...@@ -72,20 +71,18 @@ describe('IDE branches actions', () => { ...@@ -72,20 +71,18 @@ describe('IDE branches actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
describe('receiveBranchesSuccess', () => { describe('receiveBranchesSuccess', () => {
it('should commit received data', (done) => { it('should commit received data', () => {
testAction( return testAction(
receiveBranchesSuccess, receiveBranchesSuccess,
branches, branches,
mockedContext.state, mockedContext.state,
[{ type: types.RECEIVE_BRANCHES_SUCCESS, payload: branches }], [{ type: types.RECEIVE_BRANCHES_SUCCESS, payload: branches }],
[], [],
done,
); );
}); });
}); });
...@@ -110,8 +107,8 @@ describe('IDE branches actions', () => { ...@@ -110,8 +107,8 @@ describe('IDE branches actions', () => {
}); });
}); });
it('dispatches success with received data', (done) => { it('dispatches success with received data', () => {
testAction( return testAction(
fetchBranches, fetchBranches,
{ search: TEST_SEARCH }, { search: TEST_SEARCH },
mockedState, mockedState,
...@@ -121,7 +118,6 @@ describe('IDE branches actions', () => { ...@@ -121,7 +118,6 @@ describe('IDE branches actions', () => {
{ type: 'resetBranches' }, { type: 'resetBranches' },
{ type: 'receiveBranchesSuccess', payload: branches }, { type: 'receiveBranchesSuccess', payload: branches },
], ],
done,
); );
}); });
}); });
...@@ -131,8 +127,8 @@ describe('IDE branches actions', () => { ...@@ -131,8 +127,8 @@ describe('IDE branches actions', () => {
mock.onGet(/\/api\/v4\/projects\/\d+\/repository\/branches(.*)$/).replyOnce(500); mock.onGet(/\/api\/v4\/projects\/\d+\/repository\/branches(.*)$/).replyOnce(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
testAction( return testAction(
fetchBranches, fetchBranches,
{ search: TEST_SEARCH }, { search: TEST_SEARCH },
mockedState, mockedState,
...@@ -142,20 +138,18 @@ describe('IDE branches actions', () => { ...@@ -142,20 +138,18 @@ describe('IDE branches actions', () => {
{ type: 'resetBranches' }, { type: 'resetBranches' },
{ type: 'receiveBranchesError', payload: { search: TEST_SEARCH } }, { type: 'receiveBranchesError', payload: { search: TEST_SEARCH } },
], ],
done,
); );
}); });
}); });
describe('resetBranches', () => { describe('resetBranches', () => {
it('commits reset', (done) => { it('commits reset', () => {
testAction( return testAction(
resetBranches, resetBranches,
null, null,
mockedContext.state, mockedContext.state,
[{ type: types.RESET_BRANCHES }], [{ type: types.RESET_BRANCHES }],
[], [],
done,
); );
}); });
}); });
......
...@@ -26,15 +26,13 @@ describe('IDE store module clientside actions', () => { ...@@ -26,15 +26,13 @@ describe('IDE store module clientside actions', () => {
}); });
describe('pingUsage', () => { describe('pingUsage', () => {
it('posts to usage endpoint', (done) => { it('posts to usage endpoint', async () => {
const usageSpy = jest.fn(() => [200]); const usageSpy = jest.fn(() => [200]);
mock.onPost(TEST_USAGE_URL).reply(() => usageSpy()); mock.onPost(TEST_USAGE_URL).reply(() => usageSpy());
testAction(actions.pingUsage, PING_USAGE_PREVIEW_KEY, rootGetters, [], [], () => { await testAction(actions.pingUsage, PING_USAGE_PREVIEW_KEY, rootGetters, [], []);
expect(usageSpy).toHaveBeenCalled(); expect(usageSpy).toHaveBeenCalled();
done();
});
}); });
}); });
}); });
...@@ -20,21 +20,20 @@ describe('IDE file templates actions', () => { ...@@ -20,21 +20,20 @@ describe('IDE file templates actions', () => {
}); });
describe('requestTemplateTypes', () => { describe('requestTemplateTypes', () => {
it('commits REQUEST_TEMPLATE_TYPES', (done) => { it('commits REQUEST_TEMPLATE_TYPES', () => {
testAction( return testAction(
actions.requestTemplateTypes, actions.requestTemplateTypes,
null, null,
state, state,
[{ type: types.REQUEST_TEMPLATE_TYPES }], [{ type: types.REQUEST_TEMPLATE_TYPES }],
[], [],
done,
); );
}); });
}); });
describe('receiveTemplateTypesError', () => { describe('receiveTemplateTypesError', () => {
it('commits RECEIVE_TEMPLATE_TYPES_ERROR and dispatches setErrorMessage', (done) => { it('commits RECEIVE_TEMPLATE_TYPES_ERROR and dispatches setErrorMessage', () => {
testAction( return testAction(
actions.receiveTemplateTypesError, actions.receiveTemplateTypesError,
null, null,
state, state,
...@@ -49,20 +48,18 @@ describe('IDE file templates actions', () => { ...@@ -49,20 +48,18 @@ describe('IDE file templates actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
describe('receiveTemplateTypesSuccess', () => { describe('receiveTemplateTypesSuccess', () => {
it('commits RECEIVE_TEMPLATE_TYPES_SUCCESS', (done) => { it('commits RECEIVE_TEMPLATE_TYPES_SUCCESS', () => {
testAction( return testAction(
actions.receiveTemplateTypesSuccess, actions.receiveTemplateTypesSuccess,
'test', 'test',
state, state,
[{ type: types.RECEIVE_TEMPLATE_TYPES_SUCCESS, payload: 'test' }], [{ type: types.RECEIVE_TEMPLATE_TYPES_SUCCESS, payload: 'test' }],
[], [],
done,
); );
}); });
}); });
...@@ -81,23 +78,17 @@ describe('IDE file templates actions', () => { ...@@ -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'); const dispatch = jest.fn().mockName('dispatch');
actions await expect(actions.fetchTemplateTypes({ dispatch, state })).rejects.toBeUndefined();
.fetchTemplateTypes({ dispatch, state })
.then(done.fail)
.catch(() => {
expect(dispatch).not.toHaveBeenCalled(); expect(dispatch).not.toHaveBeenCalled();
done();
});
}); });
it('dispatches actions', (done) => { it('dispatches actions', () => {
state.selectedTemplateType = { key: 'licenses' }; state.selectedTemplateType = { key: 'licenses' };
testAction( return testAction(
actions.fetchTemplateTypes, actions.fetchTemplateTypes,
null, null,
state, state,
...@@ -111,7 +102,6 @@ describe('IDE file templates actions', () => { ...@@ -111,7 +102,6 @@ describe('IDE file templates actions', () => {
payload: pages[0].concat(pages[1]).concat(pages[2]), payload: pages[0].concat(pages[1]).concat(pages[2]),
}, },
], ],
done,
); );
}); });
}); });
...@@ -121,16 +111,15 @@ describe('IDE file templates actions', () => { ...@@ -121,16 +111,15 @@ describe('IDE file templates actions', () => {
mock.onGet(/api\/(.*)\/templates\/licenses/).replyOnce(500); mock.onGet(/api\/(.*)\/templates\/licenses/).replyOnce(500);
}); });
it('dispatches actions', (done) => { it('dispatches actions', () => {
state.selectedTemplateType = { key: 'licenses' }; state.selectedTemplateType = { key: 'licenses' };
testAction( return testAction(
actions.fetchTemplateTypes, actions.fetchTemplateTypes,
null, null,
state, state,
[], [],
[{ type: 'requestTemplateTypes' }, { type: 'receiveTemplateTypesError' }], [{ type: 'requestTemplateTypes' }, { type: 'receiveTemplateTypesError' }],
done,
); );
}); });
}); });
...@@ -184,8 +173,8 @@ describe('IDE file templates actions', () => { ...@@ -184,8 +173,8 @@ describe('IDE file templates actions', () => {
}); });
describe('receiveTemplateError', () => { describe('receiveTemplateError', () => {
it('dispatches setErrorMessage', (done) => { it('dispatches setErrorMessage', () => {
testAction( return testAction(
actions.receiveTemplateError, actions.receiveTemplateError,
'test', 'test',
state, state,
...@@ -201,7 +190,6 @@ describe('IDE file templates actions', () => { ...@@ -201,7 +190,6 @@ describe('IDE file templates actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
...@@ -217,46 +205,43 @@ describe('IDE file templates actions', () => { ...@@ -217,46 +205,43 @@ describe('IDE file templates actions', () => {
.replyOnce(200, { content: 'testing content' }); .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' }; const template = { content: 'already has content' };
testAction( return testAction(
actions.fetchTemplate, actions.fetchTemplate,
template, template,
state, state,
[], [],
[{ type: 'setFileTemplate', payload: template }], [{ type: 'setFileTemplate', payload: template }],
done,
); );
}); });
it('dispatches success', (done) => { it('dispatches success', () => {
const template = { key: 'mit' }; const template = { key: 'mit' };
state.selectedTemplateType = { key: 'licenses' }; state.selectedTemplateType = { key: 'licenses' };
testAction( return testAction(
actions.fetchTemplate, actions.fetchTemplate,
template, template,
state, state,
[], [],
[{ type: 'setFileTemplate', payload: { content: 'MIT content' } }], [{ 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' }; const template = { name: 'testing' };
state.selectedTemplateType = { key: 'licenses' }; state.selectedTemplateType = { key: 'licenses' };
testAction( return testAction(
actions.fetchTemplate, actions.fetchTemplate,
template, template,
state, state,
[], [],
[{ type: 'setFileTemplate', payload: { content: 'testing content' } }], [{ type: 'setFileTemplate', payload: { content: 'testing content' } }],
done,
); );
}); });
}); });
...@@ -266,18 +251,17 @@ describe('IDE file templates actions', () => { ...@@ -266,18 +251,17 @@ describe('IDE file templates actions', () => {
mock.onGet(/api\/(.*)\/templates\/licenses\/mit/).replyOnce(500); mock.onGet(/api\/(.*)\/templates\/licenses\/mit/).replyOnce(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
const template = { name: 'testing' }; const template = { name: 'testing' };
state.selectedTemplateType = { key: 'licenses' }; state.selectedTemplateType = { key: 'licenses' };
testAction( return testAction(
actions.fetchTemplate, actions.fetchTemplate,
template, template,
state, state,
[], [],
[{ type: 'receiveTemplateError', payload: template }], [{ type: 'receiveTemplateError', payload: template }],
done,
); );
}); });
}); });
......
...@@ -28,21 +28,20 @@ describe('IDE merge requests actions', () => { ...@@ -28,21 +28,20 @@ describe('IDE merge requests actions', () => {
}); });
describe('requestMergeRequests', () => { describe('requestMergeRequests', () => {
it('should commit request', (done) => { it('should commit request', () => {
testAction( return testAction(
requestMergeRequests, requestMergeRequests,
null, null,
mockedState, mockedState,
[{ type: types.REQUEST_MERGE_REQUESTS }], [{ type: types.REQUEST_MERGE_REQUESTS }],
[], [],
done,
); );
}); });
}); });
describe('receiveMergeRequestsError', () => { describe('receiveMergeRequestsError', () => {
it('should commit error', (done) => { it('should commit error', () => {
testAction( return testAction(
receiveMergeRequestsError, receiveMergeRequestsError,
{ type: 'created', search: '' }, { type: 'created', search: '' },
mockedState, mockedState,
...@@ -58,20 +57,18 @@ describe('IDE merge requests actions', () => { ...@@ -58,20 +57,18 @@ describe('IDE merge requests actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
describe('receiveMergeRequestsSuccess', () => { describe('receiveMergeRequestsSuccess', () => {
it('should commit received data', (done) => { it('should commit received data', () => {
testAction( return testAction(
receiveMergeRequestsSuccess, receiveMergeRequestsSuccess,
mergeRequests, mergeRequests,
mockedState, mockedState,
[{ type: types.RECEIVE_MERGE_REQUESTS_SUCCESS, payload: mergeRequests }], [{ type: types.RECEIVE_MERGE_REQUESTS_SUCCESS, payload: mergeRequests }],
[], [],
done,
); );
}); });
}); });
...@@ -118,8 +115,8 @@ describe('IDE merge requests actions', () => { ...@@ -118,8 +115,8 @@ describe('IDE merge requests actions', () => {
}); });
}); });
it('dispatches success with received data', (done) => { it('dispatches success with received data', () => {
testAction( return testAction(
fetchMergeRequests, fetchMergeRequests,
{ type: 'created' }, { type: 'created' },
mockedState, mockedState,
...@@ -129,7 +126,6 @@ describe('IDE merge requests actions', () => { ...@@ -129,7 +126,6 @@ describe('IDE merge requests actions', () => {
{ type: 'resetMergeRequests' }, { type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests }, { type: 'receiveMergeRequestsSuccess', payload: mergeRequests },
], ],
done,
); );
}); });
}); });
...@@ -156,8 +152,8 @@ describe('IDE merge requests actions', () => { ...@@ -156,8 +152,8 @@ describe('IDE merge requests actions', () => {
); );
}); });
it('dispatches success with received data', (done) => { it('dispatches success with received data', () => {
testAction( return testAction(
fetchMergeRequests, fetchMergeRequests,
{ type: null }, { type: null },
{ ...mockedState, ...mockedRootState }, { ...mockedState, ...mockedRootState },
...@@ -167,7 +163,6 @@ describe('IDE merge requests actions', () => { ...@@ -167,7 +163,6 @@ describe('IDE merge requests actions', () => {
{ type: 'resetMergeRequests' }, { type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests }, { type: 'receiveMergeRequestsSuccess', payload: mergeRequests },
], ],
done,
); );
}); });
}); });
...@@ -177,8 +172,8 @@ describe('IDE merge requests actions', () => { ...@@ -177,8 +172,8 @@ describe('IDE merge requests actions', () => {
mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(500); mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
testAction( return testAction(
fetchMergeRequests, fetchMergeRequests,
{ type: 'created', search: '' }, { type: 'created', search: '' },
mockedState, mockedState,
...@@ -188,21 +183,19 @@ describe('IDE merge requests actions', () => { ...@@ -188,21 +183,19 @@ describe('IDE merge requests actions', () => {
{ type: 'resetMergeRequests' }, { type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsError', payload: { type: 'created', search: '' } }, { type: 'receiveMergeRequestsError', payload: { type: 'created', search: '' } },
], ],
done,
); );
}); });
}); });
}); });
describe('resetMergeRequests', () => { describe('resetMergeRequests', () => {
it('commits reset', (done) => { it('commits reset', () => {
testAction( return testAction(
resetMergeRequests, resetMergeRequests,
null, null,
mockedState, mockedState,
[{ type: types.RESET_MERGE_REQUESTS }], [{ type: types.RESET_MERGE_REQUESTS }],
[], [],
done,
); );
}); });
}); });
......
...@@ -7,19 +7,19 @@ describe('IDE pane module actions', () => { ...@@ -7,19 +7,19 @@ describe('IDE pane module actions', () => {
const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true }; const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true };
describe('toggleOpen', () => { describe('toggleOpen', () => {
it('dispatches open if closed', (done) => { it('dispatches open if closed', () => {
testAction(actions.toggleOpen, TEST_VIEW, { isOpen: false }, [], [{ type: 'open' }], done); return testAction(actions.toggleOpen, TEST_VIEW, { isOpen: false }, [], [{ type: 'open' }]);
}); });
it('dispatches close if opened', (done) => { it('dispatches close if opened', () => {
testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }], done); return testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }]);
}); });
}); });
describe('open', () => { describe('open', () => {
describe('with a view specified', () => { describe('with a view specified', () => {
it('commits SET_OPEN and SET_CURRENT_VIEW', (done) => { it('commits SET_OPEN and SET_CURRENT_VIEW', () => {
testAction( return testAction(
actions.open, actions.open,
TEST_VIEW, TEST_VIEW,
{}, {},
...@@ -28,12 +28,11 @@ describe('IDE pane module actions', () => { ...@@ -28,12 +28,11 @@ describe('IDE pane module actions', () => {
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name }, { type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name },
], ],
[], [],
done,
); );
}); });
it('commits KEEP_ALIVE_VIEW if keepAlive is true', (done) => { it('commits KEEP_ALIVE_VIEW if keepAlive is true', () => {
testAction( return testAction(
actions.open, actions.open,
TEST_VIEW_KEEP_ALIVE, TEST_VIEW_KEEP_ALIVE,
{}, {},
...@@ -43,28 +42,26 @@ describe('IDE pane module actions', () => { ...@@ -43,28 +42,26 @@ describe('IDE pane module actions', () => {
{ type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name }, { type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
], ],
[], [],
done,
); );
}); });
}); });
describe('without a view specified', () => { describe('without a view specified', () => {
it('commits SET_OPEN', (done) => { it('commits SET_OPEN', () => {
testAction( return testAction(
actions.open, actions.open,
undefined, undefined,
{}, {},
[{ type: types.SET_OPEN, payload: true }], [{ type: types.SET_OPEN, payload: true }],
[], [],
done,
); );
}); });
}); });
}); });
describe('close', () => { describe('close', () => {
it('commits SET_OPEN', (done) => { it('commits SET_OPEN', () => {
testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], [], done); return testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], []);
}); });
}); });
}); });
...@@ -22,43 +22,37 @@ describe('ide/stores/modules/terminal_sync/actions', () => { ...@@ -22,43 +22,37 @@ describe('ide/stores/modules/terminal_sync/actions', () => {
}); });
describe('upload', () => { describe('upload', () => {
it('uploads to mirror and sets success', (done) => { it('uploads to mirror and sets success', async () => {
mirror.upload.mockReturnValue(Promise.resolve()); mirror.upload.mockReturnValue(Promise.resolve());
testAction( await testAction(
actions.upload, actions.upload,
null, null,
rootState, rootState,
[{ type: types.START_LOADING }, { type: types.SET_SUCCESS }], [{ 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!' }; const err = { message: 'it failed!' };
mirror.upload.mockReturnValue(Promise.reject(err)); mirror.upload.mockReturnValue(Promise.reject(err));
testAction( return testAction(
actions.upload, actions.upload,
null, null,
rootState, rootState,
[{ type: types.START_LOADING }, { type: types.SET_ERROR, payload: err }], [{ type: types.START_LOADING }, { type: types.SET_ERROR, payload: err }],
[], [],
done,
); );
}); });
}); });
describe('stop', () => { describe('stop', () => {
it('disconnects from mirror', (done) => { it('disconnects from mirror', async () => {
testAction(actions.stop, null, rootState, [{ type: types.STOP }], [], () => { await testAction(actions.stop, null, rootState, [{ type: types.STOP }], []);
expect(mirror.disconnect).toHaveBeenCalled(); expect(mirror.disconnect).toHaveBeenCalled();
done();
});
}); });
}); });
...@@ -83,20 +77,17 @@ describe('ide/stores/modules/terminal_sync/actions', () => { ...@@ -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()); mirror.connect.mockReturnValue(Promise.resolve());
testAction( await testAction(
actions.start, actions.start,
null, null,
rootState, rootState,
[{ type: types.START_LOADING }, { type: types.SET_SUCCESS }], [{ 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', () => { it('sets error if connection fails', () => {
......
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