Commit 94027a97 authored by Peter Hegman's avatar Peter Hegman

Merge branch 'vs/remove-jest-test-callback-ide' into 'master'

Remove jest test callbacks from IDE specs

See merge request gitlab-org/gitlab!84477
parents 794a90a1 10109de8
...@@ -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', () => {
......
...@@ -63,10 +63,11 @@ describe('IDE store merge request actions', () => { ...@@ -63,10 +63,11 @@ describe('IDE store merge request actions', () => {
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, mockData); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, mockData);
}); });
it('calls getProjectMergeRequests service method', (done) => { it('calls getProjectMergeRequests service method', async () => {
store await store.dispatch('getMergeRequestsForBranch', {
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) projectId: TEST_PROJECT,
.then(() => { branchId: 'bar',
});
expect(service.getProjectMergeRequests).toHaveBeenCalledWith(TEST_PROJECT, { expect(service.getProjectMergeRequests).toHaveBeenCalledWith(TEST_PROJECT, {
source_branch: 'bar', source_branch: 'bar',
source_project_id: TEST_PROJECT_ID, source_project_id: TEST_PROJECT_ID,
...@@ -74,45 +75,35 @@ describe('IDE store merge request actions', () => { ...@@ -74,45 +75,35 @@ describe('IDE store merge request actions', () => {
order_by: 'created_at', order_by: 'created_at',
per_page: 1, per_page: 1,
}); });
done();
})
.catch(done.fail);
}); });
it('sets the "Merge Request" Object', (done) => { it('sets the "Merge Request" Object', async () => {
store await store.dispatch('getMergeRequestsForBranch', {
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) projectId: TEST_PROJECT,
.then(() => { branchId: 'bar',
});
expect(store.state.projects.abcproject.mergeRequests).toEqual({ expect(store.state.projects.abcproject.mergeRequests).toEqual({
2: expect.objectContaining(mrData), 2: expect.objectContaining(mrData),
}); });
done();
})
.catch(done.fail);
}); });
it('sets "Current Merge Request" object to the most recent MR', (done) => { it('sets "Current Merge Request" object to the most recent MR', async () => {
store await store.dispatch('getMergeRequestsForBranch', {
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) projectId: TEST_PROJECT,
.then(() => { branchId: 'bar',
});
expect(store.state.currentMergeRequestId).toEqual('2'); expect(store.state.currentMergeRequestId).toEqual('2');
done();
})
.catch(done.fail);
}); });
it('does nothing if user cannot read MRs', (done) => { it('does nothing if user cannot read MRs', async () => {
store.state.projects[TEST_PROJECT].userPermissions[PERMISSION_READ_MR] = false; store.state.projects[TEST_PROJECT].userPermissions[PERMISSION_READ_MR] = false;
store await store.dispatch('getMergeRequestsForBranch', {
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) projectId: TEST_PROJECT,
.then(() => { branchId: 'bar',
});
expect(service.getProjectMergeRequests).not.toHaveBeenCalled(); expect(service.getProjectMergeRequests).not.toHaveBeenCalled();
expect(store.state.currentMergeRequestId).toBe(''); expect(store.state.currentMergeRequestId).toBe('');
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -122,15 +113,13 @@ describe('IDE store merge request actions', () => { ...@@ -122,15 +113,13 @@ describe('IDE store merge request actions', () => {
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, []); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, []);
}); });
it('does not fail if there are no merge requests for current branch', (done) => { it('does not fail if there are no merge requests for current branch', async () => {
store await store.dispatch('getMergeRequestsForBranch', {
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'foo' }) projectId: TEST_PROJECT,
.then(() => { branchId: 'foo',
});
expect(store.state.projects[TEST_PROJECT].mergeRequests).toEqual({}); expect(store.state.projects[TEST_PROJECT].mergeRequests).toEqual({});
expect(store.state.currentMergeRequestId).toEqual(''); expect(store.state.currentMergeRequestId).toEqual('');
done();
})
.catch(done.fail);
}); });
}); });
}); });
...@@ -140,17 +129,18 @@ describe('IDE store merge request actions', () => { ...@@ -140,17 +129,18 @@ describe('IDE store merge request actions', () => {
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).networkError(); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).networkError();
}); });
it('flashes message, if error', (done) => { it('flashes message, if error', () => {
store return store
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .dispatch('getMergeRequestsForBranch', {
projectId: TEST_PROJECT,
branchId: 'bar',
})
.catch(() => { .catch(() => {
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalled();
expect(createFlash.mock.calls[0][0].message).toBe( expect(createFlash.mock.calls[0][0].message).toBe(
'Error fetching merge requests for bar', 'Error fetching merge requests for bar',
); );
}) });
.then(done)
.catch(done.fail);
}); });
}); });
}); });
...@@ -165,29 +155,15 @@ describe('IDE store merge request actions', () => { ...@@ -165,29 +155,15 @@ describe('IDE store merge request actions', () => {
.reply(200, { title: 'mergerequest' }); .reply(200, { title: 'mergerequest' });
}); });
it('calls getProjectMergeRequestData service method', (done) => { it('calls getProjectMergeRequestData service method', async () => {
store await store.dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 });
.dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 })
.then(() => {
expect(service.getProjectMergeRequestData).toHaveBeenCalledWith(TEST_PROJECT, 1); expect(service.getProjectMergeRequestData).toHaveBeenCalledWith(TEST_PROJECT, 1);
done();
})
.catch(done.fail);
}); });
it('sets the Merge Request Object', (done) => { it('sets the Merge Request Object', async () => {
store await store.dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 });
.dispatch('getMergeRequestData', { projectId: TEST_PROJECT, mergeRequestId: 1 })
.then(() => {
expect(store.state.currentMergeRequestId).toBe(1); expect(store.state.currentMergeRequestId).toBe(1);
expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].title).toBe( expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].title).toBe('mergerequest');
'mergerequest',
);
done();
})
.catch(done.fail);
}); });
}); });
...@@ -196,19 +172,17 @@ describe('IDE store merge request actions', () => { ...@@ -196,19 +172,17 @@ describe('IDE store merge request actions', () => {
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/).networkError(); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/).networkError();
}); });
it('dispatches error action', (done) => { it('dispatches error action', () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
getMergeRequestData( return getMergeRequestData(
{ {
commit() {}, commit() {},
dispatch, dispatch,
state: store.state, state: store.state,
}, },
{ projectId: TEST_PROJECT, mergeRequestId: 1 }, { projectId: TEST_PROJECT, mergeRequestId: 1 },
) ).catch(() => {
.then(done.fail)
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading the merge request.', text: 'An error occurred while loading the merge request.',
action: expect.any(Function), action: expect.any(Function),
...@@ -219,8 +193,6 @@ describe('IDE store merge request actions', () => { ...@@ -219,8 +193,6 @@ describe('IDE store merge request actions', () => {
force: false, force: false,
}, },
}); });
done();
}); });
}); });
}); });
...@@ -240,27 +212,22 @@ describe('IDE store merge request actions', () => { ...@@ -240,27 +212,22 @@ describe('IDE store merge request actions', () => {
.reply(200, { title: 'mergerequest' }); .reply(200, { title: 'mergerequest' });
}); });
it('calls getProjectMergeRequestChanges service method', (done) => { it('calls getProjectMergeRequestChanges service method', async () => {
store await store.dispatch('getMergeRequestChanges', {
.dispatch('getMergeRequestChanges', { projectId: TEST_PROJECT, mergeRequestId: 1 }) projectId: TEST_PROJECT,
.then(() => { mergeRequestId: 1,
});
expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith(TEST_PROJECT, 1); expect(service.getProjectMergeRequestChanges).toHaveBeenCalledWith(TEST_PROJECT, 1);
done();
})
.catch(done.fail);
}); });
it('sets the Merge Request Changes Object', (done) => { it('sets the Merge Request Changes Object', async () => {
store await store.dispatch('getMergeRequestChanges', {
.dispatch('getMergeRequestChanges', { projectId: TEST_PROJECT, mergeRequestId: 1 }) projectId: TEST_PROJECT,
.then(() => { mergeRequestId: 1,
});
expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].changes.title).toBe( expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].changes.title).toBe(
'mergerequest', 'mergerequest',
); );
done();
})
.catch(done.fail);
}); });
}); });
...@@ -269,9 +236,10 @@ describe('IDE store merge request actions', () => { ...@@ -269,9 +236,10 @@ describe('IDE store merge request actions', () => {
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/).networkError(); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/).networkError();
}); });
it('dispatches error action', (done) => { it('dispatches error action', async () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
await expect(
getMergeRequestChanges( getMergeRequestChanges(
{ {
commit() {}, commit() {},
...@@ -279,9 +247,9 @@ describe('IDE store merge request actions', () => { ...@@ -279,9 +247,9 @@ describe('IDE store merge request actions', () => {
state: store.state, state: store.state,
}, },
{ projectId: TEST_PROJECT, mergeRequestId: 1 }, { projectId: TEST_PROJECT, mergeRequestId: 1 },
) ),
.then(done.fail) ).rejects.toEqual(new Error('Merge request changes not loaded abcproject'));
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading the merge request changes.', text: 'An error occurred while loading the merge request changes.',
action: expect.any(Function), action: expect.any(Function),
...@@ -292,9 +260,6 @@ describe('IDE store merge request actions', () => { ...@@ -292,9 +260,6 @@ describe('IDE store merge request actions', () => {
force: false, force: false,
}, },
}); });
done();
});
}); });
}); });
}); });
...@@ -312,25 +277,20 @@ describe('IDE store merge request actions', () => { ...@@ -312,25 +277,20 @@ describe('IDE store merge request actions', () => {
jest.spyOn(service, 'getProjectMergeRequestVersions'); jest.spyOn(service, 'getProjectMergeRequestVersions');
}); });
it('calls getProjectMergeRequestVersions service method', (done) => { it('calls getProjectMergeRequestVersions service method', async () => {
store await store.dispatch('getMergeRequestVersions', {
.dispatch('getMergeRequestVersions', { projectId: TEST_PROJECT, mergeRequestId: 1 }) projectId: TEST_PROJECT,
.then(() => { mergeRequestId: 1,
});
expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith(TEST_PROJECT, 1); expect(service.getProjectMergeRequestVersions).toHaveBeenCalledWith(TEST_PROJECT, 1);
done();
})
.catch(done.fail);
}); });
it('sets the Merge Request Versions Object', (done) => { it('sets the Merge Request Versions Object', async () => {
store await store.dispatch('getMergeRequestVersions', {
.dispatch('getMergeRequestVersions', { projectId: TEST_PROJECT, mergeRequestId: 1 }) projectId: TEST_PROJECT,
.then(() => { mergeRequestId: 1,
});
expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].versions.length).toBe(1); expect(store.state.projects[TEST_PROJECT].mergeRequests['1'].versions.length).toBe(1);
done();
})
.catch(done.fail);
}); });
}); });
...@@ -339,19 +299,17 @@ describe('IDE store merge request actions', () => { ...@@ -339,19 +299,17 @@ describe('IDE store merge request actions', () => {
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/).networkError(); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/).networkError();
}); });
it('dispatches error action', (done) => { it('dispatches error action', () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
getMergeRequestVersions( return getMergeRequestVersions(
{ {
commit() {}, commit() {},
dispatch, dispatch,
state: store.state, state: store.state,
}, },
{ projectId: TEST_PROJECT, mergeRequestId: 1 }, { projectId: TEST_PROJECT, mergeRequestId: 1 },
) ).catch(() => {
.then(done.fail)
.catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading the merge request version data.', text: 'An error occurred while loading the merge request version data.',
action: expect.any(Function), action: expect.any(Function),
...@@ -362,8 +320,6 @@ describe('IDE store merge request actions', () => { ...@@ -362,8 +320,6 @@ describe('IDE store merge request actions', () => {
force: false, force: false,
}, },
}); });
done();
}); });
}); });
}); });
...@@ -503,9 +459,11 @@ describe('IDE store merge request actions', () => { ...@@ -503,9 +459,11 @@ describe('IDE store merge request actions', () => {
); );
}); });
it('dispatches actions for merge request data', (done) => { it('dispatches actions for merge request data', async () => {
openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr) await openMergeRequest(
.then(() => { { state: store.state, dispatch: store.dispatch, getters: mockGetters },
mr,
);
expect(store.dispatch.mock.calls).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['getMergeRequestData', mr], ['getMergeRequestData', mr],
['setCurrentBranchId', testMergeRequest.source_branch], ['setCurrentBranchId', testMergeRequest.source_branch],
...@@ -528,12 +486,9 @@ describe('IDE store merge request actions', () => { ...@@ -528,12 +486,9 @@ describe('IDE store merge request actions', () => {
['getMergeRequestChanges', mr], ['getMergeRequestChanges', mr],
['openMergeRequestChanges', testMergeRequestChanges.changes], ['openMergeRequestChanges', testMergeRequestChanges.changes],
]); ]);
})
.then(done)
.catch(done.fail);
}); });
it('updates activity bar view and gets file data, if changes are found', (done) => { it('updates activity bar view and gets file data, if changes are found', async () => {
store.state.entries.foo = { store.state.entries.foo = {
type: 'blob', type: 'blob',
path: 'foo', path: 'foo',
...@@ -548,28 +503,24 @@ describe('IDE store merge request actions', () => { ...@@ -548,28 +503,24 @@ describe('IDE store merge request actions', () => {
{ new_path: 'bar', path: 'bar' }, { new_path: 'bar', path: 'bar' },
]; ];
openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr) await openMergeRequest(
.then(() => { { state: store.state, dispatch: store.dispatch, getters: mockGetters },
mr,
);
expect(store.dispatch).toHaveBeenCalledWith( expect(store.dispatch).toHaveBeenCalledWith(
'openMergeRequestChanges', 'openMergeRequestChanges',
testMergeRequestChanges.changes, testMergeRequestChanges.changes,
); );
})
.then(done)
.catch(done.fail);
}); });
it('flashes message, if error', (done) => { it('flashes message, if error', () => {
store.dispatch.mockRejectedValue(); store.dispatch.mockRejectedValue();
openMergeRequest(store, mr) return openMergeRequest(store, mr).catch(() => {
.catch(() => {
expect(createFlash).toHaveBeenCalledWith({ expect(createFlash).toHaveBeenCalledWith({
message: expect.any(String), message: expect.any(String),
}); });
}) });
.then(done)
.catch(done.fail);
}); });
}); });
}); });
...@@ -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,
); );
}); });
}); });
......
...@@ -43,15 +43,9 @@ describe('Multi-file store actions', () => { ...@@ -43,15 +43,9 @@ describe('Multi-file store actions', () => {
}); });
describe('redirectToUrl', () => { describe('redirectToUrl', () => {
it('calls visitUrl', (done) => { it('calls visitUrl', async () => {
store await store.dispatch('redirectToUrl', 'test');
.dispatch('redirectToUrl', 'test')
.then(() => {
expect(visitUrl).toHaveBeenCalledWith('test'); expect(visitUrl).toHaveBeenCalledWith('test');
done();
})
.catch(done.fail);
}); });
}); });
...@@ -89,15 +83,10 @@ describe('Multi-file store actions', () => { ...@@ -89,15 +83,10 @@ describe('Multi-file store actions', () => {
expect(store.dispatch.mock.calls).toEqual(expect.arrayContaining(expectedCalls)); expect(store.dispatch.mock.calls).toEqual(expect.arrayContaining(expectedCalls));
}); });
it('removes all files from changedFiles state', (done) => { it('removes all files from changedFiles state', async () => {
store await store.dispatch('discardAllChanges');
.dispatch('discardAllChanges')
.then(() => {
expect(store.state.changedFiles.length).toBe(0); expect(store.state.changedFiles.length).toBe(0);
expect(store.state.openFiles.length).toBe(2); expect(store.state.openFiles.length).toBe(2);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -121,24 +110,18 @@ describe('Multi-file store actions', () => { ...@@ -121,24 +110,18 @@ describe('Multi-file store actions', () => {
}); });
describe('tree', () => { describe('tree', () => {
it('creates temp tree', (done) => { it('creates temp tree', async () => {
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name: 'test', name: 'test',
type: 'tree', type: 'tree',
}) });
.then(() => {
const entry = store.state.entries.test; const entry = store.state.entries.test;
expect(entry).not.toBeNull(); expect(entry).not.toBeNull();
expect(entry.type).toBe('tree'); expect(entry.type).toBe('tree');
done();
})
.catch(done.fail);
}); });
it('creates new folder inside another tree', (done) => { it('creates new folder inside another tree', async () => {
const tree = { const tree = {
type: 'tree', type: 'tree',
name: 'testing', name: 'testing',
...@@ -148,22 +131,16 @@ describe('Multi-file store actions', () => { ...@@ -148,22 +131,16 @@ describe('Multi-file store actions', () => {
store.state.entries[tree.path] = tree; store.state.entries[tree.path] = tree;
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name: 'testing/test', name: 'testing/test',
type: 'tree', type: 'tree',
}) });
.then(() => {
expect(tree.tree[0].tempFile).toBeTruthy(); expect(tree.tree[0].tempFile).toBeTruthy();
expect(tree.tree[0].name).toBe('test'); expect(tree.tree[0].name).toBe('test');
expect(tree.tree[0].type).toBe('tree'); expect(tree.tree[0].type).toBe('tree');
done();
})
.catch(done.fail);
}); });
it('does not create new tree if already exists', (done) => { it('does not create new tree if already exists', async () => {
const tree = { const tree = {
type: 'tree', type: 'tree',
path: 'testing', path: 'testing',
...@@ -173,76 +150,52 @@ describe('Multi-file store actions', () => { ...@@ -173,76 +150,52 @@ describe('Multi-file store actions', () => {
store.state.entries[tree.path] = tree; store.state.entries[tree.path] = tree;
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name: 'testing', name: 'testing',
type: 'tree', type: 'tree',
}) });
.then(() => {
expect(store.state.entries[tree.path].tempFile).toEqual(false); expect(store.state.entries[tree.path].tempFile).toEqual(false);
expect(document.querySelector('.flash-alert')).not.toBeNull(); expect(document.querySelector('.flash-alert')).not.toBeNull();
done();
})
.catch(done.fail);
}); });
}); });
describe('blob', () => { describe('blob', () => {
it('creates temp file', (done) => { it('creates temp file', async () => {
const name = 'test'; const name = 'test';
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name, name,
type: 'blob', type: 'blob',
mimeType: 'test/mime', mimeType: 'test/mime',
}) });
.then(() => {
const f = store.state.entries[name]; const f = store.state.entries[name];
expect(f.tempFile).toBeTruthy(); expect(f.tempFile).toBeTruthy();
expect(f.mimeType).toBe('test/mime'); expect(f.mimeType).toBe('test/mime');
expect(store.state.trees['abcproject/mybranch'].tree.length).toBe(1); expect(store.state.trees['abcproject/mybranch'].tree.length).toBe(1);
done();
})
.catch(done.fail);
}); });
it('adds tmp file to open files', (done) => { it('adds tmp file to open files', async () => {
const name = 'test'; const name = 'test';
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name, name,
type: 'blob', type: 'blob',
}) });
.then(() => {
const f = store.state.entries[name]; const f = store.state.entries[name];
expect(store.state.openFiles.length).toBe(1); expect(store.state.openFiles.length).toBe(1);
expect(store.state.openFiles[0].name).toBe(f.name); expect(store.state.openFiles[0].name).toBe(f.name);
done();
})
.catch(done.fail);
}); });
it('adds tmp file to staged files', (done) => { it('adds tmp file to staged files', async () => {
const name = 'test'; const name = 'test';
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name, name,
type: 'blob', type: 'blob',
}) });
.then(() => {
expect(store.state.stagedFiles).toEqual([expect.objectContaining({ name })]); expect(store.state.stagedFiles).toEqual([expect.objectContaining({ name })]);
done();
})
.catch(done.fail);
}); });
it('sets tmp file as active', () => { it('sets tmp file as active', () => {
...@@ -251,24 +204,18 @@ describe('Multi-file store actions', () => { ...@@ -251,24 +204,18 @@ describe('Multi-file store actions', () => {
expect(store.dispatch).toHaveBeenCalledWith('setFileActive', 'test'); expect(store.dispatch).toHaveBeenCalledWith('setFileActive', 'test');
}); });
it('creates flash message if file already exists', (done) => { it('creates flash message if file already exists', async () => {
const f = file('test', '1', 'blob'); const f = file('test', '1', 'blob');
store.state.trees['abcproject/mybranch'].tree = [f]; store.state.trees['abcproject/mybranch'].tree = [f];
store.state.entries[f.path] = f; store.state.entries[f.path] = f;
store await store.dispatch('createTempEntry', {
.dispatch('createTempEntry', {
name: 'test', name: 'test',
type: 'blob', type: 'blob',
}) });
.then(() => {
expect(document.querySelector('.flash-alert')?.textContent.trim()).toEqual( expect(document.querySelector('.flash-alert')?.textContent.trim()).toEqual(
`The name "${f.name}" is already taken in this directory.`, `The name "${f.name}" is already taken in this directory.`,
); );
done();
})
.catch(done.fail);
}); });
}); });
}); });
...@@ -372,45 +319,38 @@ describe('Multi-file store actions', () => { ...@@ -372,45 +319,38 @@ describe('Multi-file store actions', () => {
}); });
describe('updateViewer', () => { describe('updateViewer', () => {
it('updates viewer state', (done) => { it('updates viewer state', async () => {
store await store.dispatch('updateViewer', 'diff');
.dispatch('updateViewer', 'diff')
.then(() => {
expect(store.state.viewer).toBe('diff'); expect(store.state.viewer).toBe('diff');
})
.then(done)
.catch(done.fail);
}); });
}); });
describe('updateActivityBarView', () => { describe('updateActivityBarView', () => {
it('commits UPDATE_ACTIVITY_BAR_VIEW', (done) => { it('commits UPDATE_ACTIVITY_BAR_VIEW', () => {
testAction( return testAction(
updateActivityBarView, updateActivityBarView,
'test', 'test',
{}, {},
[{ type: 'UPDATE_ACTIVITY_BAR_VIEW', payload: 'test' }], [{ type: 'UPDATE_ACTIVITY_BAR_VIEW', payload: 'test' }],
[], [],
done,
); );
}); });
}); });
describe('setEmptyStateSvgs', () => { describe('setEmptyStateSvgs', () => {
it('commits setEmptyStateSvgs', (done) => { it('commits setEmptyStateSvgs', () => {
testAction( return testAction(
setEmptyStateSvgs, setEmptyStateSvgs,
'svg', 'svg',
{}, {},
[{ type: 'SET_EMPTY_STATE_SVGS', payload: 'svg' }], [{ type: 'SET_EMPTY_STATE_SVGS', payload: 'svg' }],
[], [],
done,
); );
}); });
}); });
describe('updateTempFlagForEntry', () => { describe('updateTempFlagForEntry', () => {
it('commits UPDATE_TEMP_FLAG', (done) => { it('commits UPDATE_TEMP_FLAG', () => {
const f = { const f = {
...file(), ...file(),
path: 'test', path: 'test',
...@@ -418,17 +358,16 @@ describe('Multi-file store actions', () => { ...@@ -418,17 +358,16 @@ describe('Multi-file store actions', () => {
}; };
store.state.entries[f.path] = f; store.state.entries[f.path] = f;
testAction( return testAction(
updateTempFlagForEntry, updateTempFlagForEntry,
{ file: f, tempFile: false }, { file: f, tempFile: false },
store.state, store.state,
[{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }], [{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }],
[], [],
done,
); );
}); });
it('commits UPDATE_TEMP_FLAG and dispatches for parent', (done) => { it('commits UPDATE_TEMP_FLAG and dispatches for parent', () => {
const parent = { const parent = {
...file(), ...file(),
path: 'testing', path: 'testing',
...@@ -441,17 +380,16 @@ describe('Multi-file store actions', () => { ...@@ -441,17 +380,16 @@ describe('Multi-file store actions', () => {
store.state.entries[parent.path] = parent; store.state.entries[parent.path] = parent;
store.state.entries[f.path] = f; store.state.entries[f.path] = f;
testAction( return testAction(
updateTempFlagForEntry, updateTempFlagForEntry,
{ file: f, tempFile: false }, { file: f, tempFile: false },
store.state, store.state,
[{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }], [{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }],
[{ type: 'updateTempFlagForEntry', payload: { file: parent, tempFile: false } }], [{ type: 'updateTempFlagForEntry', payload: { file: parent, tempFile: false } }],
done,
); );
}); });
it('does not dispatch for parent, if parent does not exist', (done) => { it('does not dispatch for parent, if parent does not exist', () => {
const f = { const f = {
...file(), ...file(),
path: 'test', path: 'test',
...@@ -459,71 +397,66 @@ describe('Multi-file store actions', () => { ...@@ -459,71 +397,66 @@ describe('Multi-file store actions', () => {
}; };
store.state.entries[f.path] = f; store.state.entries[f.path] = f;
testAction( return testAction(
updateTempFlagForEntry, updateTempFlagForEntry,
{ file: f, tempFile: false }, { file: f, tempFile: false },
store.state, store.state,
[{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }], [{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }],
[], [],
done,
); );
}); });
}); });
describe('setCurrentBranchId', () => { describe('setCurrentBranchId', () => {
it('commits setCurrentBranchId', (done) => { it('commits setCurrentBranchId', () => {
testAction( return testAction(
setCurrentBranchId, setCurrentBranchId,
'branchId', 'branchId',
{}, {},
[{ type: 'SET_CURRENT_BRANCH', payload: 'branchId' }], [{ type: 'SET_CURRENT_BRANCH', payload: 'branchId' }],
[], [],
done,
); );
}); });
}); });
describe('toggleFileFinder', () => { describe('toggleFileFinder', () => {
it('commits TOGGLE_FILE_FINDER', (done) => { it('commits TOGGLE_FILE_FINDER', () => {
testAction( return testAction(
toggleFileFinder, toggleFileFinder,
true, true,
null, null,
[{ type: 'TOGGLE_FILE_FINDER', payload: true }], [{ type: 'TOGGLE_FILE_FINDER', payload: true }],
[], [],
done,
); );
}); });
}); });
describe('setErrorMessage', () => { describe('setErrorMessage', () => {
it('commis error messsage', (done) => { it('commis error messsage', () => {
testAction( return testAction(
setErrorMessage, setErrorMessage,
'error', 'error',
null, null,
[{ type: types.SET_ERROR_MESSAGE, payload: 'error' }], [{ type: types.SET_ERROR_MESSAGE, payload: 'error' }],
[], [],
done,
); );
}); });
}); });
describe('deleteEntry', () => { describe('deleteEntry', () => {
it('commits entry deletion', (done) => { it('commits entry deletion', () => {
store.state.entries.path = 'testing'; store.state.entries.path = 'testing';
testAction( return testAction(
deleteEntry, deleteEntry,
'path', 'path',
store.state, store.state,
[{ type: types.DELETE_ENTRY, payload: 'path' }], [{ type: types.DELETE_ENTRY, payload: 'path' }],
[{ type: 'stageChange', payload: 'path' }, createTriggerChangeAction()], [{ type: 'stageChange', payload: 'path' }, createTriggerChangeAction()],
done,
); );
}); });
it('does not delete a folder after it is emptied', (done) => { it('does not delete a folder after it is emptied', () => {
const testFolder = { const testFolder = {
type: 'tree', type: 'tree',
tree: [], tree: [],
...@@ -540,7 +473,7 @@ describe('Multi-file store actions', () => { ...@@ -540,7 +473,7 @@ describe('Multi-file store actions', () => {
'testFolder/entry-to-delete': testEntry, 'testFolder/entry-to-delete': testEntry,
}; };
testAction( return testAction(
deleteEntry, deleteEntry,
'testFolder/entry-to-delete', 'testFolder/entry-to-delete',
store.state, store.state,
...@@ -549,7 +482,6 @@ describe('Multi-file store actions', () => { ...@@ -549,7 +482,6 @@ describe('Multi-file store actions', () => {
{ type: 'stageChange', payload: 'testFolder/entry-to-delete' }, { type: 'stageChange', payload: 'testFolder/entry-to-delete' },
createTriggerChangeAction(), createTriggerChangeAction(),
], ],
done,
); );
}); });
...@@ -569,8 +501,8 @@ describe('Multi-file store actions', () => { ...@@ -569,8 +501,8 @@ describe('Multi-file store actions', () => {
}); });
describe('and previous does not exist', () => { describe('and previous does not exist', () => {
it('reverts the rename before deleting', (done) => { it('reverts the rename before deleting', () => {
testAction( return testAction(
deleteEntry, deleteEntry,
testEntry.path, testEntry.path,
store.state, store.state,
...@@ -589,7 +521,6 @@ describe('Multi-file store actions', () => { ...@@ -589,7 +521,6 @@ describe('Multi-file store actions', () => {
payload: testEntry.prevPath, payload: testEntry.prevPath,
}, },
], ],
done,
); );
}); });
}); });
...@@ -604,21 +535,20 @@ describe('Multi-file store actions', () => { ...@@ -604,21 +535,20 @@ describe('Multi-file store actions', () => {
store.state.entries[oldEntry.path] = oldEntry; store.state.entries[oldEntry.path] = oldEntry;
}); });
it('does not revert rename before deleting', (done) => { it('does not revert rename before deleting', () => {
testAction( return testAction(
deleteEntry, deleteEntry,
testEntry.path, testEntry.path,
store.state, store.state,
[{ type: types.DELETE_ENTRY, payload: testEntry.path }], [{ type: types.DELETE_ENTRY, payload: testEntry.path }],
[{ type: 'stageChange', payload: testEntry.path }, createTriggerChangeAction()], [{ type: 'stageChange', payload: testEntry.path }, createTriggerChangeAction()],
done,
); );
}); });
it('when previous is deleted, it reverts rename before deleting', (done) => { it('when previous is deleted, it reverts rename before deleting', () => {
store.state.entries[testEntry.prevPath].deleted = true; store.state.entries[testEntry.prevPath].deleted = true;
testAction( return testAction(
deleteEntry, deleteEntry,
testEntry.path, testEntry.path,
store.state, store.state,
...@@ -637,7 +567,6 @@ describe('Multi-file store actions', () => { ...@@ -637,7 +567,6 @@ describe('Multi-file store actions', () => {
payload: testEntry.prevPath, payload: testEntry.prevPath,
}, },
], ],
done,
); );
}); });
}); });
...@@ -650,7 +579,7 @@ describe('Multi-file store actions', () => { ...@@ -650,7 +579,7 @@ describe('Multi-file store actions', () => {
jest.spyOn(eventHub, '$emit').mockImplementation(); jest.spyOn(eventHub, '$emit').mockImplementation();
}); });
it('does not purge model cache for temporary entries that got renamed', (done) => { it('does not purge model cache for temporary entries that got renamed', async () => {
Object.assign(store.state.entries, { Object.assign(store.state.entries, {
test: { test: {
...file('test'), ...file('test'),
...@@ -660,19 +589,14 @@ describe('Multi-file store actions', () => { ...@@ -660,19 +589,14 @@ describe('Multi-file store actions', () => {
}, },
}); });
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: 'test', path: 'test',
name: 'new', name: 'new',
}) });
.then(() => {
expect(eventHub.$emit.mock.calls).not.toContain('editor.update.model.dispose.foo-bar'); expect(eventHub.$emit.mock.calls).not.toContain('editor.update.model.dispose.foo-bar');
})
.then(done)
.catch(done.fail);
}); });
it('purges model cache for renamed entry', (done) => { it('purges model cache for renamed entry', async () => {
Object.assign(store.state.entries, { Object.assign(store.state.entries, {
test: { test: {
...file('test'), ...file('test'),
...@@ -682,17 +606,12 @@ describe('Multi-file store actions', () => { ...@@ -682,17 +606,12 @@ describe('Multi-file store actions', () => {
}, },
}); });
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: 'test', path: 'test',
name: 'new', name: 'new',
}) });
.then(() => {
expect(eventHub.$emit).toHaveBeenCalled(); expect(eventHub.$emit).toHaveBeenCalled();
expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.dispose.foo-key`); expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.dispose.foo-key`);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -731,8 +650,8 @@ describe('Multi-file store actions', () => { ...@@ -731,8 +650,8 @@ describe('Multi-file store actions', () => {
]); ]);
}); });
it('if not changed, completely unstages and discards entry if renamed to original', (done) => { it('if not changed, completely unstages and discards entry if renamed to original', () => {
testAction( return testAction(
renameEntry, renameEntry,
{ path: 'renamed', name: 'orig' }, { path: 'renamed', name: 'orig' },
store.state, store.state,
...@@ -751,24 +670,22 @@ describe('Multi-file store actions', () => { ...@@ -751,24 +670,22 @@ describe('Multi-file store actions', () => {
}, },
], ],
[createTriggerRenameAction('renamed', 'orig')], [createTriggerRenameAction('renamed', 'orig')],
done,
); );
}); });
it('if already in changed, does not add to change', (done) => { it('if already in changed, does not add to change', () => {
store.state.changedFiles.push(renamedEntry); store.state.changedFiles.push(renamedEntry);
testAction( return testAction(
renameEntry, renameEntry,
{ path: 'orig', name: 'renamed' }, { path: 'orig', name: 'renamed' },
store.state, store.state,
[expect.objectContaining({ type: types.RENAME_ENTRY })], [expect.objectContaining({ type: types.RENAME_ENTRY })],
[createTriggerRenameAction('orig', 'renamed')], [createTriggerRenameAction('orig', 'renamed')],
done,
); );
}); });
it('routes to the renamed file if the original file has been opened', (done) => { it('routes to the renamed file if the original file has been opened', async () => {
store.state.currentProjectId = 'test/test'; store.state.currentProjectId = 'test/test';
store.state.currentBranchId = 'main'; store.state.currentBranchId = 'main';
...@@ -776,17 +693,12 @@ describe('Multi-file store actions', () => { ...@@ -776,17 +693,12 @@ describe('Multi-file store actions', () => {
opened: true, opened: true,
}); });
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: 'orig', path: 'orig',
name: 'renamed', name: 'renamed',
}) });
.then(() => {
expect(router.push.mock.calls).toHaveLength(1); expect(router.push.mock.calls).toHaveLength(1);
expect(router.push).toHaveBeenCalledWith(`/project/test/test/tree/main/-/renamed/`); expect(router.push).toHaveBeenCalledWith(`/project/test/test/tree/main/-/renamed/`);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -809,25 +721,20 @@ describe('Multi-file store actions', () => { ...@@ -809,25 +721,20 @@ describe('Multi-file store actions', () => {
}); });
}); });
it('updates entries in a folder correctly, when folder is renamed', (done) => { it('updates entries in a folder correctly, when folder is renamed', async () => {
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: 'folder', path: 'folder',
name: 'new-folder', name: 'new-folder',
}) });
.then(() => {
const keys = Object.keys(store.state.entries); const keys = Object.keys(store.state.entries);
expect(keys.length).toBe(3); expect(keys.length).toBe(3);
expect(keys.indexOf('new-folder')).toBe(0); expect(keys.indexOf('new-folder')).toBe(0);
expect(keys.indexOf('new-folder/file-1')).toBe(1); expect(keys.indexOf('new-folder/file-1')).toBe(1);
expect(keys.indexOf('new-folder/file-2')).toBe(2); expect(keys.indexOf('new-folder/file-2')).toBe(2);
})
.then(done)
.catch(done.fail);
}); });
it('discards renaming of an entry if the root folder is renamed back to a previous name', (done) => { it('discards renaming of an entry if the root folder is renamed back to a previous name', async () => {
const rootFolder = file('old-folder', 'old-folder', 'tree'); const rootFolder = file('old-folder', 'old-folder', 'tree');
const testEntry = file('test', 'test', 'blob', rootFolder); const testEntry = file('test', 'test', 'blob', rootFolder);
...@@ -841,12 +748,10 @@ describe('Multi-file store actions', () => { ...@@ -841,12 +748,10 @@ describe('Multi-file store actions', () => {
}, },
}); });
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: 'old-folder', path: 'old-folder',
name: 'new-folder', name: 'new-folder',
}) });
.then(() => {
const { entries } = store.state; const { entries } = store.state;
expect(Object.keys(entries).length).toBe(2); expect(Object.keys(entries).length).toBe(2);
...@@ -862,22 +767,19 @@ describe('Multi-file store actions', () => { ...@@ -862,22 +767,19 @@ describe('Multi-file store actions', () => {
prevName: 'test', prevName: 'test',
}), }),
); );
})
.then(() => await store.dispatch('renameEntry', {
store.dispatch('renameEntry', {
path: 'new-folder', path: 'new-folder',
name: 'old-folder', name: 'old-folder',
}), });
) const { entries: newEntries } = store.state;
.then(() => {
const { entries } = store.state;
expect(Object.keys(entries).length).toBe(2); expect(Object.keys(newEntries).length).toBe(2);
expect(entries['new-folder']).toBeUndefined(); expect(newEntries['new-folder']).toBeUndefined();
expect(entries['new-folder/test']).toBeUndefined(); expect(newEntries['new-folder/test']).toBeUndefined();
expect(entries['old-folder']).toBeDefined(); expect(newEntries['old-folder']).toBeDefined();
expect(entries['old-folder/test']).toEqual( expect(newEntries['old-folder/test']).toEqual(
expect.objectContaining({ expect.objectContaining({
path: 'old-folder/test', path: 'old-folder/test',
name: 'test', name: 'test',
...@@ -885,9 +787,6 @@ describe('Multi-file store actions', () => { ...@@ -885,9 +787,6 @@ describe('Multi-file store actions', () => {
prevName: undefined, prevName: undefined,
}), }),
); );
})
.then(done)
.catch(done.fail);
}); });
describe('with file in directory', () => { describe('with file in directory', () => {
...@@ -919,24 +818,21 @@ describe('Multi-file store actions', () => { ...@@ -919,24 +818,21 @@ describe('Multi-file store actions', () => {
}); });
}); });
it('creates new directory', (done) => { it('creates new directory', async () => {
expect(store.state.entries[newParentPath]).toBeUndefined(); expect(store.state.entries[newParentPath]).toBeUndefined();
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', { path: filePath, name: fileName, parentPath: newParentPath }) path: filePath,
.then(() => { name: fileName,
parentPath: newParentPath,
});
expect(store.state.entries[newParentPath]).toEqual( expect(store.state.entries[newParentPath]).toEqual(
expect.objectContaining({ expect.objectContaining({
path: newParentPath, path: newParentPath,
type: 'tree', type: 'tree',
tree: expect.arrayContaining([ tree: expect.arrayContaining([store.state.entries[`${newParentPath}/${fileName}`]]),
store.state.entries[`${newParentPath}/${fileName}`],
]),
}), }),
); );
})
.then(done)
.catch(done.fail);
}); });
describe('when new directory exists', () => { describe('when new directory exists', () => {
...@@ -949,40 +845,30 @@ describe('Multi-file store actions', () => { ...@@ -949,40 +845,30 @@ describe('Multi-file store actions', () => {
rootDir.tree.push(newDir); rootDir.tree.push(newDir);
}); });
it('inserts in new directory', (done) => { it('inserts in new directory', async () => {
expect(newDir.tree).toEqual([]); expect(newDir.tree).toEqual([]);
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: filePath, path: filePath,
name: fileName, name: fileName,
parentPath: newParentPath, parentPath: newParentPath,
}) });
.then(() => {
expect(newDir.tree).toEqual([store.state.entries[`${newParentPath}/${fileName}`]]); expect(newDir.tree).toEqual([store.state.entries[`${newParentPath}/${fileName}`]]);
})
.then(done)
.catch(done.fail);
}); });
it('when new directory is deleted, it undeletes it', (done) => { it('when new directory is deleted, it undeletes it', async () => {
store.dispatch('deleteEntry', newParentPath); await store.dispatch('deleteEntry', newParentPath);
expect(store.state.entries[newParentPath].deleted).toBe(true); expect(store.state.entries[newParentPath].deleted).toBe(true);
expect(rootDir.tree.some((x) => x.path === newParentPath)).toBe(false); expect(rootDir.tree.some((x) => x.path === newParentPath)).toBe(false);
store await store.dispatch('renameEntry', {
.dispatch('renameEntry', {
path: filePath, path: filePath,
name: fileName, name: fileName,
parentPath: newParentPath, parentPath: newParentPath,
}) });
.then(() => {
expect(store.state.entries[newParentPath].deleted).toBe(false); expect(store.state.entries[newParentPath].deleted).toBe(false);
expect(rootDir.tree.some((x) => x.path === newParentPath)).toBe(true); expect(rootDir.tree.some((x) => x.path === newParentPath)).toBe(true);
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
...@@ -1023,30 +909,25 @@ describe('Multi-file store actions', () => { ...@@ -1023,30 +909,25 @@ describe('Multi-file store actions', () => {
document.querySelector('.flash-container').remove(); document.querySelector('.flash-container').remove();
}); });
it('passes the error further unchanged without dispatching any action when response is 404', (done) => { it('passes the error further unchanged without dispatching any action when response is 404', async () => {
mock.onGet(/(.*)/).replyOnce(404); mock.onGet(/(.*)/).replyOnce(404);
getBranchData(...callParams) await expect(getBranchData(...callParams)).rejects.toEqual(
.then(done.fail) new Error('Request failed with status code 404'),
.catch((e) => { );
expect(dispatch.mock.calls).toHaveLength(0); expect(dispatch.mock.calls).toHaveLength(0);
expect(e.response.status).toEqual(404);
expect(document.querySelector('.flash-alert')).toBeNull(); expect(document.querySelector('.flash-alert')).toBeNull();
done();
});
}); });
it('does not pass the error further and flashes an alert if error is not 404', (done) => { it('does not pass the error further and flashes an alert if error is not 404', async () => {
mock.onGet(/(.*)/).replyOnce(418); mock.onGet(/(.*)/).replyOnce(418);
getBranchData(...callParams) await expect(getBranchData(...callParams)).rejects.toEqual(
.then(done.fail) new Error('Branch not loaded - <strong>abc/def/main-testing</strong>'),
.catch((e) => { );
expect(dispatch.mock.calls).toHaveLength(0); expect(dispatch.mock.calls).toHaveLength(0);
expect(e.response).toBeUndefined();
expect(document.querySelector('.flash-alert')).not.toBeNull(); expect(document.querySelector('.flash-alert')).not.toBeNull();
done();
});
}); });
}); });
}); });
......
...@@ -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();
});
}); });
}); });
}); });
...@@ -57,40 +57,25 @@ describe('IDE commit module actions', () => { ...@@ -57,40 +57,25 @@ describe('IDE commit module actions', () => {
}); });
describe('updateCommitMessage', () => { describe('updateCommitMessage', () => {
it('updates store with new commit message', (done) => { it('updates store with new commit message', async () => {
store await store.dispatch('commit/updateCommitMessage', 'testing');
.dispatch('commit/updateCommitMessage', 'testing')
.then(() => {
expect(store.state.commit.commitMessage).toBe('testing'); expect(store.state.commit.commitMessage).toBe('testing');
})
.then(done)
.catch(done.fail);
}); });
}); });
describe('discardDraft', () => { describe('discardDraft', () => {
it('resets commit message to blank', (done) => { it('resets commit message to blank', async () => {
store.state.commit.commitMessage = 'testing'; store.state.commit.commitMessage = 'testing';
store await store.dispatch('commit/discardDraft');
.dispatch('commit/discardDraft')
.then(() => {
expect(store.state.commit.commitMessage).not.toBe('testing'); expect(store.state.commit.commitMessage).not.toBe('testing');
})
.then(done)
.catch(done.fail);
}); });
}); });
describe('updateCommitAction', () => { describe('updateCommitAction', () => {
it('updates store with new commit action', (done) => { it('updates store with new commit action', async () => {
store await store.dispatch('commit/updateCommitAction', '1');
.dispatch('commit/updateCommitAction', '1')
.then(() => {
expect(store.state.commit.commitAction).toBe('1'); expect(store.state.commit.commitAction).toBe('1');
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -139,34 +124,24 @@ describe('IDE commit module actions', () => { ...@@ -139,34 +124,24 @@ describe('IDE commit module actions', () => {
}); });
}); });
it('updates commit message with short_id', (done) => { it('updates commit message with short_id', async () => {
store await store.dispatch('commit/setLastCommitMessage', { short_id: '123' });
.dispatch('commit/setLastCommitMessage', { short_id: '123' })
.then(() => {
expect(store.state.lastCommitMsg).toContain( expect(store.state.lastCommitMsg).toContain(
'Your changes have been committed. Commit <a href="http://testing/-/commit/123" class="commit-sha">123</a>', '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 stats', (done) => { it('updates commit message with stats', async () => {
store await store.dispatch('commit/setLastCommitMessage', {
.dispatch('commit/setLastCommitMessage', {
short_id: '123', short_id: '123',
stats: { stats: {
additions: '1', additions: '1',
deletions: '2', deletions: '2',
}, },
}) });
.then(() => {
expect(store.state.lastCommitMsg).toBe( 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.', '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);
}); });
}); });
...@@ -221,74 +196,49 @@ describe('IDE commit module actions', () => { ...@@ -221,74 +196,49 @@ describe('IDE commit module actions', () => {
}); });
}); });
it('updates stores working reference', (done) => { it('updates stores working reference', async () => {
store await store.dispatch('commit/updateFilesAfterCommit', {
.dispatch('commit/updateFilesAfterCommit', {
data, data,
branch, branch,
}) });
.then(() => {
expect(store.state.projects.abcproject.branches.main.workingReference).toBe(data.id); expect(store.state.projects.abcproject.branches.main.workingReference).toBe(data.id);
})
.then(done)
.catch(done.fail);
}); });
it('resets all files changed status', (done) => { it('resets all files changed status', async () => {
store await store.dispatch('commit/updateFilesAfterCommit', {
.dispatch('commit/updateFilesAfterCommit', {
data, data,
branch, branch,
}) });
.then(() => {
store.state.openFiles.forEach((entry) => { store.state.openFiles.forEach((entry) => {
expect(entry.changed).toBeFalsy(); expect(entry.changed).toBeFalsy();
}); });
})
.then(done)
.catch(done.fail);
}); });
it('sets files commit data', (done) => { it('sets files commit data', async () => {
store await store.dispatch('commit/updateFilesAfterCommit', {
.dispatch('commit/updateFilesAfterCommit', {
data, data,
branch, branch,
}) });
.then(() => {
expect(f.lastCommitSha).toBe(data.id); expect(f.lastCommitSha).toBe(data.id);
})
.then(done)
.catch(done.fail);
}); });
it('updates raw content for changed file', (done) => { it('updates raw content for changed file', async () => {
store await store.dispatch('commit/updateFilesAfterCommit', {
.dispatch('commit/updateFilesAfterCommit', {
data, data,
branch, branch,
}) });
.then(() => {
expect(f.raw).toBe(f.content); expect(f.raw).toBe(f.content);
})
.then(done)
.catch(done.fail);
}); });
it('emits changed event for file', (done) => { it('emits changed event for file', async () => {
store await store.dispatch('commit/updateFilesAfterCommit', {
.dispatch('commit/updateFilesAfterCommit', {
data, data,
branch, branch,
}) });
.then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.content.${f.key}`, { expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.content.${f.key}`, {
content: f.content, content: f.content,
changed: false, changed: false,
}); });
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -349,10 +299,8 @@ describe('IDE commit module actions', () => { ...@@ -349,10 +299,8 @@ describe('IDE commit module actions', () => {
jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
}); });
it('calls service', (done) => { it('calls service', async () => {
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(service.commit).toHaveBeenCalledWith('abcproject', { expect(service.commit).toHaveBeenCalledWith('abcproject', {
branch: expect.anything(), branch: expect.anything(),
commit_message: 'testing 123', commit_message: 'testing 123',
...@@ -368,18 +316,12 @@ describe('IDE commit module actions', () => { ...@@ -368,18 +316,12 @@ describe('IDE commit module actions', () => {
], ],
start_sha: TEST_COMMIT_SHA, start_sha: TEST_COMMIT_SHA,
}); });
done();
})
.catch(done.fail);
}); });
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.state.commit.commitAction = '1';
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(service.commit).toHaveBeenCalledWith('abcproject', { expect(service.commit).toHaveBeenCalledWith('abcproject', {
branch: expect.anything(), branch: expect.anything(),
commit_message: 'testing 123', commit_message: 'testing 123',
...@@ -395,92 +337,55 @@ describe('IDE commit module actions', () => { ...@@ -395,92 +337,55 @@ describe('IDE commit module actions', () => {
], ],
start_sha: undefined, start_sha: undefined,
}); });
done();
})
.catch(done.fail);
}); });
it('sets last Commit Msg', (done) => { it('sets last Commit Msg', async () => {
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.lastCommitMsg).toBe( 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.', '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('adds commit data to files', (done) => { it('adds commit data to files', async () => {
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.entries[store.state.openFiles[0].path].lastCommitSha).toBe( expect(store.state.entries[store.state.openFiles[0].path].lastCommitSha).toBe(
COMMIT_RESPONSE.id, COMMIT_RESPONSE.id,
); );
done();
})
.catch(done.fail);
}); });
it('resets stores commit actions', (done) => { it('resets stores commit actions', async () => {
store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH; store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH;
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.commit.commitAction).not.toBe(COMMIT_TO_NEW_BRANCH); expect(store.state.commit.commitAction).not.toBe(COMMIT_TO_NEW_BRANCH);
})
.then(done)
.catch(done.fail);
}); });
it('removes all staged files', (done) => { it('removes all staged files', async () => {
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.stagedFiles.length).toBe(0); expect(store.state.stagedFiles.length).toBe(0);
})
.then(done)
.catch(done.fail);
}); });
describe('merge request', () => { describe('merge request', () => {
it('redirects to new merge request page', (done) => { it('redirects to new merge request page', async () => {
jest.spyOn(eventHub, '$on').mockImplementation(); jest.spyOn(eventHub, '$on').mockImplementation();
store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH; store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH;
store.state.commit.shouldCreateMR = true; store.state.commit.shouldCreateMR = true;
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(visitUrl).toHaveBeenCalledWith( expect(visitUrl).toHaveBeenCalledWith(
`webUrl/-/merge_requests/new?merge_request[source_branch]=${store.getters['commit/placeholderBranchName']}&merge_request[target_branch]=main&nav_source=webide`, `webUrl/-/merge_requests/new?merge_request[source_branch]=${store.getters['commit/placeholderBranchName']}&merge_request[target_branch]=main&nav_source=webide`,
); );
done();
})
.catch(done.fail);
}); });
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(); jest.spyOn(eventHub, '$on').mockImplementation();
store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH; store.state.commit.commitAction = COMMIT_TO_NEW_BRANCH;
store.state.commit.shouldCreateMR = false; store.state.commit.shouldCreateMR = false;
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(visitUrl).not.toHaveBeenCalled(); expect(visitUrl).not.toHaveBeenCalled();
done();
})
.catch(done.fail);
}); });
it('does not redirect to merge request page if shouldCreateMR is checked, but branch is the default branch', async () => { 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', () => { ...@@ -514,17 +419,11 @@ describe('IDE commit module actions', () => {
}); });
}); });
it('shows failed message', (done) => { it('shows failed message', async () => {
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
const alert = document.querySelector('.flash-container'); const alert = document.querySelector('.flash-container');
expect(alert.textContent.trim()).toBe('failed message'); expect(alert.textContent.trim()).toBe('failed message');
done();
})
.catch(done.fail);
}); });
}); });
...@@ -548,52 +447,37 @@ describe('IDE commit module actions', () => { ...@@ -548,52 +447,37 @@ describe('IDE commit module actions', () => {
}); });
describe('first commit of a branch', () => { 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(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
jest.spyOn(store, 'commit'); jest.spyOn(store, 'commit');
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(store.commit.mock.calls).toEqual( expect(store.commit.mock.calls).toEqual(
expect.arrayContaining([ expect.arrayContaining([['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)]]),
['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)],
]),
); );
done();
})
.catch(done.fail);
}); });
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'); COMMIT_RESPONSE.parent_ids.push('1234');
jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE }); jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
jest.spyOn(store, 'commit'); jest.spyOn(store, 'commit');
store await store.dispatch('commit/commitChanges');
.dispatch('commit/commitChanges')
.then(() => {
expect(store.commit.mock.calls).not.toEqual( expect(store.commit.mock.calls).not.toEqual(
expect.arrayContaining([ expect.arrayContaining([['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)]]),
['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)],
]),
); );
done();
})
.catch(done.fail);
}); });
}); });
}); });
describe('toggleShouldCreateMR', () => { describe('toggleShouldCreateMR', () => {
it('commits both toggle and interacting with MR checkbox actions', (done) => { it('commits both toggle and interacting with MR checkbox actions', () => {
testAction( return testAction(
actions.toggleShouldCreateMR, actions.toggleShouldCreateMR,
{}, {},
store.state, store.state,
[{ type: mutationTypes.TOGGLE_SHOULD_CREATE_MR }], [{ type: mutationTypes.TOGGLE_SHOULD_CREATE_MR }],
[], [],
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 }], []);
}); });
}); });
}); });
...@@ -25,6 +25,7 @@ import { ...@@ -25,6 +25,7 @@ import {
import * as types from '~/ide/stores/modules/pipelines/mutation_types'; import * as types from '~/ide/stores/modules/pipelines/mutation_types';
import state from '~/ide/stores/modules/pipelines/state'; import state from '~/ide/stores/modules/pipelines/state';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import waitForPromises from 'helpers/wait_for_promises';
import { pipelines, jobs } from '../../../mock_data'; import { pipelines, jobs } from '../../../mock_data';
describe('IDE pipelines actions', () => { describe('IDE pipelines actions', () => {
...@@ -44,32 +45,30 @@ describe('IDE pipelines actions', () => { ...@@ -44,32 +45,30 @@ describe('IDE pipelines actions', () => {
}); });
describe('requestLatestPipeline', () => { describe('requestLatestPipeline', () => {
it('commits request', (done) => { it('commits request', () => {
testAction( return testAction(
requestLatestPipeline, requestLatestPipeline,
null, null,
mockedState, mockedState,
[{ type: types.REQUEST_LATEST_PIPELINE }], [{ type: types.REQUEST_LATEST_PIPELINE }],
[], [],
done,
); );
}); });
}); });
describe('receiveLatestPipelineError', () => { describe('receiveLatestPipelineError', () => {
it('commits error', (done) => { it('commits error', () => {
testAction( return testAction(
receiveLatestPipelineError, receiveLatestPipelineError,
{ status: 404 }, { status: 404 },
mockedState, mockedState,
[{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }], [{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }],
[{ type: 'stopPipelinePolling' }], [{ type: 'stopPipelinePolling' }],
done,
); );
}); });
it('dispatches setErrorMessage is not 404', (done) => { it('dispatches setErrorMessage is not 404', () => {
testAction( return testAction(
receiveLatestPipelineError, receiveLatestPipelineError,
{ status: 500 }, { status: 500 },
mockedState, mockedState,
...@@ -86,7 +85,6 @@ describe('IDE pipelines actions', () => { ...@@ -86,7 +85,6 @@ describe('IDE pipelines actions', () => {
}, },
{ type: 'stopPipelinePolling' }, { type: 'stopPipelinePolling' },
], ],
done,
); );
}); });
}); });
...@@ -123,7 +121,7 @@ describe('IDE pipelines actions', () => { ...@@ -123,7 +121,7 @@ describe('IDE pipelines actions', () => {
.reply(200, { data: { foo: 'bar' } }, { 'poll-interval': '10000' }); .reply(200, { data: { foo: 'bar' } }, { 'poll-interval': '10000' });
}); });
it('dispatches request', (done) => { it('dispatches request', async () => {
jest.spyOn(axios, 'get'); jest.spyOn(axios, 'get');
jest.spyOn(Visibility, 'hidden').mockReturnValue(false); jest.spyOn(Visibility, 'hidden').mockReturnValue(false);
...@@ -133,34 +131,21 @@ describe('IDE pipelines actions', () => { ...@@ -133,34 +131,21 @@ describe('IDE pipelines actions', () => {
currentProject: { path_with_namespace: 'abc/def' }, currentProject: { path_with_namespace: 'abc/def' },
}; };
fetchLatestPipeline({ dispatch, rootGetters }); await fetchLatestPipeline({ dispatch, rootGetters });
expect(dispatch).toHaveBeenCalledWith('requestLatestPipeline'); expect(dispatch).toHaveBeenCalledWith('requestLatestPipeline');
jest.advanceTimersByTime(1000); await waitForPromises();
new Promise((resolve) => requestAnimationFrame(resolve))
.then(() => {
expect(axios.get).toHaveBeenCalled(); expect(axios.get).toHaveBeenCalled();
expect(axios.get).toHaveBeenCalledTimes(1); expect(axios.get).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineSuccess', expect.anything());
'receiveLatestPipelineSuccess',
expect.anything(),
);
jest.advanceTimersByTime(10000); jest.advanceTimersByTime(10000);
})
.then(() => new Promise((resolve) => requestAnimationFrame(resolve)))
.then(() => {
expect(axios.get).toHaveBeenCalled(); expect(axios.get).toHaveBeenCalled();
expect(axios.get).toHaveBeenCalledTimes(2); expect(axios.get).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineSuccess', expect.anything());
'receiveLatestPipelineSuccess',
expect.anything(),
);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -169,27 +154,22 @@ describe('IDE pipelines actions', () => { ...@@ -169,27 +154,22 @@ describe('IDE pipelines actions', () => {
mock.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines').reply(500); mock.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines').reply(500);
}); });
it('dispatches error', (done) => { it('dispatches error', async () => {
const dispatch = jest.fn().mockName('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const rootGetters = { const rootGetters = {
lastCommit: { id: 'abc123def456ghi789jkl' }, lastCommit: { id: 'abc123def456ghi789jkl' },
currentProject: { path_with_namespace: 'abc/def' }, 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()); expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything());
})
.then(done)
.catch(done.fail);
}); });
}); });
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 = {
...mockedState, ...mockedState,
rootGetters: { rootGetters: {
...@@ -197,26 +177,31 @@ describe('IDE pipelines actions', () => { ...@@ -197,26 +177,31 @@ describe('IDE pipelines actions', () => {
}, },
}; };
testAction( return testAction(
fetchLatestPipeline, fetchLatestPipeline,
{}, {},
mockedState, mockedState,
[{ type: types.RECEIVE_LASTEST_PIPELINE_SUCCESS, payload: null }], [{ type: types.RECEIVE_LASTEST_PIPELINE_SUCCESS, payload: null }],
[{ type: 'stopPipelinePolling' }], [{ type: 'stopPipelinePolling' }],
done,
); );
}); });
}); });
describe('requestJobs', () => { describe('requestJobs', () => {
it('commits request', (done) => { it('commits request', () => {
testAction(requestJobs, 1, mockedState, [{ type: types.REQUEST_JOBS, payload: 1 }], [], done); return testAction(
requestJobs,
1,
mockedState,
[{ type: types.REQUEST_JOBS, payload: 1 }],
[],
);
}); });
}); });
describe('receiveJobsError', () => { describe('receiveJobsError', () => {
it('commits error', (done) => { it('commits error', () => {
testAction( return testAction(
receiveJobsError, receiveJobsError,
{ id: 1 }, { id: 1 },
mockedState, mockedState,
...@@ -232,20 +217,18 @@ describe('IDE pipelines actions', () => { ...@@ -232,20 +217,18 @@ describe('IDE pipelines actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
describe('receiveJobsSuccess', () => { describe('receiveJobsSuccess', () => {
it('commits data', (done) => { it('commits data', () => {
testAction( return testAction(
receiveJobsSuccess, receiveJobsSuccess,
{ id: 1, data: jobs }, { id: 1, data: jobs },
mockedState, mockedState,
[{ type: types.RECEIVE_JOBS_SUCCESS, payload: { id: 1, data: jobs } }], [{ type: types.RECEIVE_JOBS_SUCCESS, payload: { id: 1, data: jobs } }],
[], [],
done,
); );
}); });
}); });
...@@ -258,8 +241,8 @@ describe('IDE pipelines actions', () => { ...@@ -258,8 +241,8 @@ describe('IDE pipelines actions', () => {
mock.onGet(stage.dropdownPath).replyOnce(200, jobs); mock.onGet(stage.dropdownPath).replyOnce(200, jobs);
}); });
it('dispatches request', (done) => { it('dispatches request', () => {
testAction( return testAction(
fetchJobs, fetchJobs,
stage, stage,
mockedState, mockedState,
...@@ -268,7 +251,6 @@ describe('IDE pipelines actions', () => { ...@@ -268,7 +251,6 @@ describe('IDE pipelines actions', () => {
{ type: 'requestJobs', payload: stage.id }, { type: 'requestJobs', payload: stage.id },
{ type: 'receiveJobsSuccess', payload: { id: stage.id, data: jobs } }, { type: 'receiveJobsSuccess', payload: { id: stage.id, data: jobs } },
], ],
done,
); );
}); });
}); });
...@@ -278,8 +260,8 @@ describe('IDE pipelines actions', () => { ...@@ -278,8 +260,8 @@ describe('IDE pipelines actions', () => {
mock.onGet(stage.dropdownPath).replyOnce(500); mock.onGet(stage.dropdownPath).replyOnce(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
testAction( return testAction(
fetchJobs, fetchJobs,
stage, stage,
mockedState, mockedState,
...@@ -288,69 +270,64 @@ describe('IDE pipelines actions', () => { ...@@ -288,69 +270,64 @@ describe('IDE pipelines actions', () => {
{ type: 'requestJobs', payload: stage.id }, { type: 'requestJobs', payload: stage.id },
{ type: 'receiveJobsError', payload: stage }, { type: 'receiveJobsError', payload: stage },
], ],
done,
); );
}); });
}); });
}); });
describe('toggleStageCollapsed', () => { describe('toggleStageCollapsed', () => {
it('commits collapse', (done) => { it('commits collapse', () => {
testAction( return testAction(
toggleStageCollapsed, toggleStageCollapsed,
1, 1,
mockedState, mockedState,
[{ type: types.TOGGLE_STAGE_COLLAPSE, payload: 1 }], [{ type: types.TOGGLE_STAGE_COLLAPSE, payload: 1 }],
[], [],
done,
); );
}); });
}); });
describe('setDetailJob', () => { describe('setDetailJob', () => {
it('commits job', (done) => { it('commits job', () => {
testAction( return testAction(
setDetailJob, setDetailJob,
'job', 'job',
mockedState, mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }], [{ type: types.SET_DETAIL_JOB, payload: 'job' }],
[{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }], [{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }],
done,
); );
}); });
it('dispatches rightPane/open as pipeline when job is null', (done) => { it('dispatches rightPane/open as pipeline when job is null', () => {
testAction( return testAction(
setDetailJob, setDetailJob,
null, null,
mockedState, mockedState,
[{ type: types.SET_DETAIL_JOB, payload: null }], [{ type: types.SET_DETAIL_JOB, payload: null }],
[{ type: 'rightPane/open', payload: rightSidebarViews.pipelines }], [{ type: 'rightPane/open', payload: rightSidebarViews.pipelines }],
done,
); );
}); });
it('dispatches rightPane/open as job', (done) => { it('dispatches rightPane/open as job', () => {
testAction( return testAction(
setDetailJob, setDetailJob,
'job', 'job',
mockedState, mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }], [{ type: types.SET_DETAIL_JOB, payload: 'job' }],
[{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }], [{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }],
done,
); );
}); });
}); });
describe('requestJobLogs', () => { describe('requestJobLogs', () => {
it('commits request', (done) => { it('commits request', () => {
testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], [], done); return testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], []);
}); });
}); });
describe('receiveJobLogsError', () => { describe('receiveJobLogsError', () => {
it('commits error', (done) => { it('commits error', () => {
testAction( return testAction(
receiveJobLogsError, receiveJobLogsError,
null, null,
mockedState, mockedState,
...@@ -366,20 +343,18 @@ describe('IDE pipelines actions', () => { ...@@ -366,20 +343,18 @@ describe('IDE pipelines actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
describe('receiveJobLogsSuccess', () => { describe('receiveJobLogsSuccess', () => {
it('commits data', (done) => { it('commits data', () => {
testAction( return testAction(
receiveJobLogsSuccess, receiveJobLogsSuccess,
'data', 'data',
mockedState, mockedState,
[{ type: types.RECEIVE_JOB_LOGS_SUCCESS, payload: 'data' }], [{ type: types.RECEIVE_JOB_LOGS_SUCCESS, payload: 'data' }],
[], [],
done,
); );
}); });
}); });
...@@ -395,8 +370,8 @@ describe('IDE pipelines actions', () => { ...@@ -395,8 +370,8 @@ describe('IDE pipelines actions', () => {
mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' }); mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' });
}); });
it('dispatches request', (done) => { it('dispatches request', () => {
testAction( return testAction(
fetchJobLogs, fetchJobLogs,
null, null,
mockedState, mockedState,
...@@ -405,7 +380,6 @@ describe('IDE pipelines actions', () => { ...@@ -405,7 +380,6 @@ describe('IDE pipelines actions', () => {
{ type: 'requestJobLogs' }, { type: 'requestJobLogs' },
{ type: 'receiveJobLogsSuccess', payload: { html: 'html' } }, { type: 'receiveJobLogsSuccess', payload: { html: 'html' } },
], ],
done,
); );
}); });
...@@ -426,22 +400,21 @@ describe('IDE pipelines actions', () => { ...@@ -426,22 +400,21 @@ describe('IDE pipelines actions', () => {
mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500); mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
testAction( return testAction(
fetchJobLogs, fetchJobLogs,
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestJobLogs' }, { type: 'receiveJobLogsError' }], [{ type: 'requestJobLogs' }, { type: 'receiveJobLogsError' }],
done,
); );
}); });
}); });
}); });
describe('resetLatestPipeline', () => { describe('resetLatestPipeline', () => {
it('commits reset mutations', (done) => { it('commits reset mutations', () => {
testAction( return testAction(
resetLatestPipeline, resetLatestPipeline,
null, null,
mockedState, mockedState,
...@@ -450,7 +423,6 @@ describe('IDE pipelines actions', () => { ...@@ -450,7 +423,6 @@ describe('IDE pipelines actions', () => {
{ type: types.SET_DETAIL_JOB, payload: null }, { type: types.SET_DETAIL_JOB, payload: null },
], ],
[], [],
done,
); );
}); });
}); });
......
...@@ -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