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,25 +69,21 @@ describe('new dropdown upload', () => {
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));
vm.createFile(textTarget, textFile);
expect(FileReader.prototype.readAsText).toHaveBeenCalledWith(textFile);
waitForCreate
.then(() => {
expect(vm.$emit).toHaveBeenCalledWith('create', {
name: textFile.name,
type: 'blob',
content: 'plain text',
rawPath: '',
mimeType: 'test/mime-text',
});
})
.then(done)
.catch(done.fail);
await waitForCreate;
expect(vm.$emit).toHaveBeenCalledWith('create', {
name: textFile.name,
type: 'blob',
content: 'plain text',
rawPath: '',
mimeType: 'test/mime-text',
});
});
it('creates a blob URL for the content if binary', () => {
......
......@@ -146,22 +146,16 @@ describe('IDE store project actions', () => {
});
});
it('calls the service', (done) => {
store
.dispatch('refreshLastCommitData', {
projectId: store.state.currentProjectId,
branchId: store.state.currentBranchId,
})
.then(() => {
expect(service.getBranchData).toHaveBeenCalledWith('abc/def', 'main');
done();
})
.catch(done.fail);
it('calls the service', async () => {
await store.dispatch('refreshLastCommitData', {
projectId: store.state.currentProjectId,
branchId: store.state.currentBranchId,
});
expect(service.getBranchData).toHaveBeenCalledWith('abc/def', 'main');
});
it('commits getBranchData', (done) => {
testAction(
it('commits getBranchData', () => {
return testAction(
refreshLastCommitData,
{
projectId: store.state.currentProjectId,
......@@ -181,14 +175,13 @@ describe('IDE store project actions', () => {
],
// action
[],
done,
);
});
});
describe('showBranchNotFoundError', () => {
it('dispatches setErrorMessage', (done) => {
testAction(
it('dispatches setErrorMessage', () => {
return testAction(
showBranchNotFoundError,
'main',
null,
......@@ -204,7 +197,6 @@ describe('IDE store project actions', () => {
},
},
],
done,
);
});
});
......@@ -216,8 +208,8 @@ describe('IDE store project actions', () => {
jest.spyOn(api, 'createBranch').mockResolvedValue();
});
it('calls API', (done) => {
createNewBranchFromDefault(
it('calls API', async () => {
await createNewBranchFromDefault(
{
state: {
currentProjectId: 'project-path',
......@@ -230,21 +222,17 @@ describe('IDE store project actions', () => {
dispatch() {},
},
'new-branch-name',
)
.then(() => {
expect(api.createBranch).toHaveBeenCalledWith('project-path', {
ref: 'main',
branch: 'new-branch-name',
});
})
.then(done)
.catch(done.fail);
);
expect(api.createBranch).toHaveBeenCalledWith('project-path', {
ref: 'main',
branch: 'new-branch-name',
});
});
it('clears error message', (done) => {
it('clears error message', async () => {
const dispatchSpy = jest.fn().mockName('dispatch');
createNewBranchFromDefault(
await createNewBranchFromDefault(
{
state: {
currentProjectId: 'project-path',
......@@ -257,16 +245,12 @@ describe('IDE store project actions', () => {
dispatch: dispatchSpy,
},
'new-branch-name',
)
.then(() => {
expect(dispatchSpy).toHaveBeenCalledWith('setErrorMessage', null);
})
.then(done)
.catch(done.fail);
);
expect(dispatchSpy).toHaveBeenCalledWith('setErrorMessage', null);
});
it('reloads window', (done) => {
createNewBranchFromDefault(
it('reloads window', async () => {
await createNewBranchFromDefault(
{
state: {
currentProjectId: 'project-path',
......@@ -279,18 +263,14 @@ describe('IDE store project actions', () => {
dispatch() {},
},
'new-branch-name',
)
.then(() => {
expect(window.location.reload).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
);
expect(window.location.reload).toHaveBeenCalled();
});
});
describe('loadEmptyBranch', () => {
it('creates a blank tree and sets loading state to false', (done) => {
testAction(
it('creates a blank tree and sets loading state to false', () => {
return testAction(
loadEmptyBranch,
{ projectId: TEST_PROJECT_ID, branchId: 'main' },
store.state,
......@@ -302,20 +282,18 @@ describe('IDE store project actions', () => {
},
],
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`]: [] };
testAction(
return testAction(
loadEmptyBranch,
{ projectId: TEST_PROJECT_ID, branchId: 'main' },
{ trees },
[],
[],
done,
);
});
});
......@@ -372,56 +350,48 @@ describe('IDE store project actions', () => {
const branchId = '123-lorem';
const ref = 'abcd2322';
it('when empty repo, loads empty branch', (done) => {
it('when empty repo, loads empty branch', () => {
const mockGetters = { emptyRepo: true };
testAction(
return testAction(
loadBranch,
{ projectId, branchId },
{ ...store.state, ...mockGetters },
[],
[{ 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] = {};
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 } }) };
jest.spyOn(store, 'dispatch').mockResolvedValue();
loadBranch(
await loadBranch(
{ getters: mockGetters, state: store.state, dispatch: store.dispatch },
{ projectId, branchId },
)
.then(() => {
expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }],
['getMergeRequestsForBranch', { projectId, branchId }],
['getFiles', { projectId, branchId, ref }],
]);
})
.then(done)
.catch(done.fail);
);
expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }],
['getMergeRequestsForBranch', { projectId, branchId }],
['getFiles', { projectId, branchId, ref }],
]);
});
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());
loadBranch(store, { projectId, branchId })
.then(done.fail)
.catch(() => {
expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }],
['showBranchNotFoundError', branchId],
]);
done();
});
await expect(loadBranch(store, { projectId, branchId })).rejects.toBeUndefined();
expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }],
['showBranchNotFoundError', branchId],
]);
});
});
......@@ -449,17 +419,13 @@ describe('IDE store project actions', () => {
jest.spyOn(store, 'dispatch').mockResolvedValue();
});
it('dispatches branch actions', (done) => {
openBranch(store, branch)
.then(() => {
expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }],
['loadFile', { basePath: undefined }],
]);
})
.then(done)
.catch(done.fail);
it('dispatches branch actions', async () => {
await openBranch(store, branch);
expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }],
['loadFile', { basePath: undefined }],
]);
});
});
......@@ -468,22 +434,18 @@ describe('IDE store project actions', () => {
jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject());
});
it('dispatches correct branch actions', (done) => {
openBranch(store, branch)
.then((val) => {
expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }],
]);
expect(val).toEqual(
new Error(
`An error occurred while getting files for - <strong>${projectId}/${branchId}</strong>`,
),
);
})
.then(done)
.catch(done.fail);
it('dispatches correct branch actions', async () => {
const val = await openBranch(store, branch);
expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }],
]);
expect(val).toEqual(
new Error(
`An error occurred while getting files for - <strong>${projectId}/${branchId}</strong>`,
),
);
});
});
});
......
......@@ -62,27 +62,21 @@ describe('Multi-file store tree actions', () => {
});
});
it('adds data into tree', (done) => {
store
.dispatch('getFiles', basicCallParameters)
.then(() => {
projectTree = store.state.trees['abcproject/main'];
expect(projectTree.tree.length).toBe(2);
expect(projectTree.tree[0].type).toBe('tree');
expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js');
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].name).toBe('fileinsubfolder.js');
done();
})
.catch(done.fail);
it('adds data into tree', async () => {
await store.dispatch('getFiles', basicCallParameters);
projectTree = store.state.trees['abcproject/main'];
expect(projectTree.tree.length).toBe(2);
expect(projectTree.tree[0].type).toBe('tree');
expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js');
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].name).toBe('fileinsubfolder.js');
});
});
describe('error', () => {
it('dispatches error action', (done) => {
it('dispatches error action', async () => {
const dispatch = jest.fn();
store.state.projects = {
......@@ -103,28 +97,26 @@ describe('Multi-file store tree actions', () => {
mock.onGet(/(.*)/).replyOnce(500);
getFiles(
{
commit() {},
dispatch,
state: store.state,
getters,
},
{
projectId: 'abc/def',
branchId: 'main-testing',
},
)
.then(done.fail)
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading all the files.',
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: { projectId: 'abc/def', branchId: 'main-testing' },
});
done();
});
await expect(
getFiles(
{
commit() {},
dispatch,
state: store.state,
getters,
},
{
projectId: 'abc/def',
branchId: 'main-testing',
},
),
).rejects.toEqual(new Error('Request failed with status code 500'));
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading all the files.',
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: { projectId: 'abc/def', branchId: 'main-testing' },
});
});
});
});
......@@ -137,15 +129,9 @@ describe('Multi-file store tree actions', () => {
store.state.entries[tree.path] = tree;
});
it('toggles the tree open', (done) => {
store
.dispatch('toggleTreeOpen', tree.path)
.then(() => {
expect(tree.opened).toBeTruthy();
done();
})
.catch(done.fail);
it('toggles the tree open', async () => {
await store.dispatch('toggleTreeOpen', tree.path);
expect(tree.opened).toBeTruthy();
});
});
......@@ -163,24 +149,23 @@ describe('Multi-file store tree actions', () => {
Object.assign(store.state.entries, createEntriesFromPaths(paths));
});
it('opens the parents', (done) => {
testAction(
it('opens the parents', () => {
return testAction(
showTreeEntry,
'grandparent/parent/child.txt',
store.state,
[{ type: types.SET_TREE_OPEN, payload: 'grandparent/parent' }],
[{ type: 'showTreeEntry', payload: 'grandparent/parent' }],
done,
);
});
});
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' });
store.state.trees['abcproject/main'] = {};
testAction(
return testAction(
setDirectoryData,
{ projectId: 'abcproject', branchId: 'main', treeList: [treeFile] },
store.state,
......@@ -201,7 +186,6 @@ describe('Multi-file store tree actions', () => {
},
],
[],
done,
);
});
});
......
This diff is collapsed.
......@@ -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,
);
});
});
......
......@@ -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();
});
});
});
......@@ -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,
);
});
});
......
......@@ -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,
);
});
});
......
......@@ -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 }], []);
});
});
});
......@@ -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', () => {
......
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