Commit a0cc00ea authored by Vitaly Slobodin's avatar Vitaly Slobodin Committed by Natalia Tepluhina

Remove Jest test callback in EE specs

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

```
it('test', (done) => { /* code */ })
```
parent b0f8a7a4
---
extends: ../../../spec/frontend/.eslintrc.yml
rules:
jest/no-test-callback: error
......@@ -91,8 +91,8 @@ describe('Code review analytics mergeRequests actions', () => {
mock.onGet(/api\/(.*)\/analytics\/code_review/).replyOnce(500);
});
it('dispatches error', (done) => {
testAction(
it('dispatches error', async () => {
await testAction(
actions.fetchMergeRequests,
null,
state,
......@@ -104,11 +104,9 @@ describe('Code review analytics mergeRequests actions', () => {
},
],
[],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
);
expect(createFlash).toHaveBeenCalled();
});
});
});
......
......@@ -5,7 +5,7 @@ import testAction from 'helpers/vuex_action_helper';
describe('Productivity analytics actions', () => {
describe('setEndpoint', () => {
it('commits the SET_ENDPOINT mutation', (done) =>
it('commits the SET_ENDPOINT mutation', async () =>
testAction(
actions.setEndpoint,
'endpoint.json',
......@@ -17,7 +17,6 @@ describe('Productivity analytics actions', () => {
},
],
[],
done,
));
});
});
......@@ -72,7 +72,7 @@ describe('Productivity analytics chart actions', () => {
expect(axios.get).toHaveBeenCalledWith(mockedState.endpoint, { params: globalParams });
});
it('dispatches success with received data', (done) =>
it('dispatches success with received data', async () =>
testAction(
actions.fetchChartData,
chartKey,
......@@ -85,7 +85,6 @@ describe('Productivity analytics chart actions', () => {
payload: expect.objectContaining({ chartKey, data: mockHistogramData }),
},
],
done,
));
});
......@@ -94,8 +93,8 @@ describe('Productivity analytics chart actions', () => {
mock.onGet(mockedState.endpoint).replyOnce(200, mockScatterplotData);
});
it('dispatches success with received data and transformedData', (done) => {
testAction(
it('dispatches success with received data and transformedData', async () => {
await testAction(
actions.fetchChartData,
chartKeys.scatterplot,
mockedState,
......@@ -111,7 +110,6 @@ describe('Productivity analytics chart actions', () => {
},
},
],
done,
);
});
});
......@@ -122,8 +120,8 @@ describe('Productivity analytics chart actions', () => {
mock.onGet(mockedState.endpoint).replyOnce(500);
});
it('dispatches error', (done) => {
testAction(
it('dispatches error', async () => {
await testAction(
actions.fetchChartData,
chartKey,
mockedState,
......@@ -141,7 +139,6 @@ describe('Productivity analytics chart actions', () => {
},
},
],
done,
);
});
});
......@@ -149,14 +146,13 @@ describe('Productivity analytics chart actions', () => {
});
describe('requestChartData', () => {
it('should commit the request mutation', (done) => {
testAction(
it('should commit the request mutation', async () => {
await testAction(
actions.requestChartData,
chartKey,
mockedContext.state,
[{ type: types.REQUEST_CHART_DATA, payload: chartKey }],
[],
done,
);
});
......@@ -167,8 +163,8 @@ describe('Productivity analytics chart actions', () => {
mockedState.charts[disabledChartKey].enabled = false;
});
it('does not dispatch the requestChartData action', (done) => {
testAction(actions.fetchChartData, disabledChartKey, mockedState, [], [], done);
it('does not dispatch the requestChartData action', async () => {
await testAction(actions.fetchChartData, disabledChartKey, mockedState, [], []);
});
it('does not call the API', () => {
......@@ -180,8 +176,8 @@ describe('Productivity analytics chart actions', () => {
});
describe('receiveChartDataSuccess', () => {
it('should commit received data', (done) => {
testAction(
it('should commit received data', async () => {
await testAction(
actions.receiveChartDataSuccess,
{ chartKey, data: mockHistogramData },
mockedContext.state,
......@@ -192,15 +188,14 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
describe('receiveChartDataError', () => {
it('should commit error', (done) => {
it('should commit error', async () => {
const error = { response: { status: 500 } };
testAction(
await testAction(
actions.receiveChartDataError,
{ chartKey, error },
mockedContext.state,
......@@ -214,14 +209,13 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
describe('fetchSecondaryChartData', () => {
it('dispatches fetchChartData for all chart types except for the main chart', (done) => {
testAction(
it('dispatches fetchChartData for all chart types except for the main chart', async () => {
await testAction(
actions.fetchSecondaryChartData,
null,
mockedContext.state,
......@@ -231,7 +225,6 @@ describe('Productivity analytics chart actions', () => {
{ type: 'fetchChartData', payload: chartKeys.commitBasedHistogram },
{ type: 'fetchChartData', payload: chartKeys.scatterplot },
],
done,
);
});
});
......@@ -239,48 +232,45 @@ describe('Productivity analytics chart actions', () => {
describe('setMetricType', () => {
const metricType = 'time_to_merge';
it('should commit metricType', (done) => {
testAction(
it('should commit metricType', async () => {
await testAction(
actions.setMetricType,
{ chartKey, metricType },
mockedContext.state,
[{ type: types.SET_METRIC_TYPE, payload: { chartKey, metricType } }],
[{ type: 'fetchChartData', payload: chartKey }],
done,
);
});
});
describe('updateSelectedItems', () => {
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', (done) => {
testAction(
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', async () => {
await testAction(
actions.updateSelectedItems,
{ chartKey, item: 5 },
mockedContext.state,
[{ type: types.UPDATE_SELECTED_CHART_ITEMS, payload: { chartKey, item: 5 } }],
[{ type: 'fetchSecondaryChartData' }, { type: 'table/setPage', payload: 0 }],
done,
);
});
});
describe('resetMainChartSelection', () => {
describe('when skipReload is false (by default)', () => {
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', (done) => {
testAction(
it('should commit selected chart item and dispatch fetchSecondaryChartData and setPage', async () => {
await testAction(
actions.resetMainChartSelection,
null,
mockedContext.state,
[{ type: types.UPDATE_SELECTED_CHART_ITEMS, payload: { chartKey, item: null } }],
[{ type: 'fetchSecondaryChartData' }, { type: 'table/setPage', payload: 0 }],
done,
);
});
});
describe('when skipReload is true', () => {
it('should commit selected chart and it should not dispatch any further actions', (done) => {
testAction(
it('should commit selected chart and it should not dispatch any further actions', async () => {
await testAction(
actions.resetMainChartSelection,
true,
mockedContext.state,
......@@ -291,15 +281,14 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
});
describe('setChartEnabled', () => {
it('should commit enabled state', (done) => {
testAction(
it('should commit enabled state', async () => {
await testAction(
actions.setChartEnabled,
{ chartKey: chartKeys.scatterplot, isEnabled: false },
mockedContext.state,
......@@ -310,7 +299,6 @@ describe('Productivity analytics chart actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -30,31 +30,26 @@ describe('Productivity analytics filter actions', () => {
});
describe('setInitialData', () => {
it('commits the SET_INITIAL_DATA mutation and fetches data by default', (done) => {
actions
.setInitialData(store, { data: initialData })
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_INITIAL_DATA, initialData);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_INITIAL_DATA mutation and fetches data by default', async () => {
await actions.setInitialData(store, { data: initialData });
expect(store.commit).toHaveBeenCalledWith(types.SET_INITIAL_DATA, initialData);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual(['table/setPage', 0, { root: true }]);
});
it("commits the SET_INITIAL_DATA mutation and doesn't fetch data when skipFetch=true", (done) =>
it("commits the SET_INITIAL_DATA mutation and doesn't fetch data when skipFetch=true", async () =>
testAction(
actions.setInitialData,
{ skipFetch: true, data: initialData },
......@@ -66,135 +61,114 @@ describe('Productivity analytics filter actions', () => {
},
],
[],
done,
));
});
describe('setGroupNamespace', () => {
it('commits the SET_GROUP_NAMESPACE mutation', (done) => {
actions
.setGroupNamespace(store, groupNamespace)
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_GROUP_NAMESPACE, groupNamespace);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_GROUP_NAMESPACE mutation', async () => {
await actions.setGroupNamespace(store, groupNamespace);
expect(store.commit).toHaveBeenCalledWith(types.SET_GROUP_NAMESPACE, groupNamespace);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
describe('setProjectPath', () => {
it('commits the SET_PROJECT_PATH mutation', (done) => {
actions
.setProjectPath(store, projectPath)
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_PROJECT_PATH, projectPath);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_PROJECT_PATH mutation', async () => {
await actions.setProjectPath(store, projectPath);
expect(store.commit).toHaveBeenCalledWith(types.SET_PROJECT_PATH, projectPath);
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
describe('setFilters', () => {
it('commits the SET_FILTERS mutation', (done) => {
actions
.setFilters(store, { author_username: 'root' })
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_FILTERS, { authorUsername: 'root' });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_FILTERS mutation', async () => {
await actions.setFilters(store, { author_username: 'root' });
expect(store.commit).toHaveBeenCalledWith(types.SET_FILTERS, { authorUsername: 'root' });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
describe('setDateRange', () => {
it('commits the SET_DATE_RANGE mutation', (done) => {
actions
.setDateRange(store, { startDate, endDate })
.then(() => {
expect(store.commit).toHaveBeenCalledWith(types.SET_DATE_RANGE, { startDate, endDate });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
})
.then(done)
.catch(done.fail);
it('commits the SET_DATE_RANGE mutation', async () => {
await actions.setDateRange(store, { startDate, endDate });
expect(store.commit).toHaveBeenCalledWith(types.SET_DATE_RANGE, { startDate, endDate });
expect(store.dispatch.mock.calls[0]).toEqual([
'charts/resetMainChartSelection',
true,
{ root: true },
]);
expect(store.dispatch.mock.calls[1]).toEqual([
'charts/fetchChartData',
chartKeys.main,
{ root: true },
]);
expect(store.dispatch.mock.calls[2]).toEqual([
'charts/fetchSecondaryChartData',
null,
{ root: true },
]);
expect(store.dispatch.mock.calls[3]).toEqual(['table/setPage', 0, { root: true }]);
});
});
});
......@@ -104,7 +104,7 @@ describe('Productivity analytics table actions', () => {
});
});
it('dispatches success with received data', (done) =>
it('dispatches success with received data', async () =>
testAction(
actions.fetchMergeRequests,
null,
......@@ -117,7 +117,6 @@ describe('Productivity analytics table actions', () => {
payload: { data: mockMergeRequests, headers },
},
],
done,
));
});
......@@ -126,8 +125,8 @@ describe('Productivity analytics table actions', () => {
mock.onGet(mockedState.endpoint).replyOnce(500);
});
it('dispatches error', (done) => {
testAction(
it('dispatches error', async () => {
await testAction(
actions.fetchMergeRequests,
null,
mockedState,
......@@ -139,26 +138,24 @@ describe('Productivity analytics table actions', () => {
payload: new Error('Request failed with status code 500'),
},
],
done,
);
});
});
});
describe('requestMergeRequests', () => {
it('should commit the request mutation', (done) =>
it('should commit the request mutation', async () =>
testAction(
actions.requestMergeRequests,
null,
mockedContext.state,
[{ type: types.REQUEST_MERGE_REQUESTS }],
[],
done,
));
});
describe('receiveMergeRequestsSuccess', () => {
it('should commit received data', (done) =>
it('should commit received data', async () =>
testAction(
actions.receiveMergeRequestsSuccess,
{ headers, data: mockMergeRequests },
......@@ -170,24 +167,22 @@ describe('Productivity analytics table actions', () => {
},
],
[],
done,
));
});
describe('receiveMergeRequestsError', () => {
it('should commit error', (done) =>
it('should commit error', async () =>
testAction(
actions.receiveMergeRequestsError,
{ response: { status: 500 } },
mockedContext.state,
[{ type: types.RECEIVE_MERGE_REQUESTS_ERROR, payload: 500 }],
[],
done,
));
});
describe('setSortField', () => {
it('should commit setSortField', (done) =>
it('should commit setSortField', async () =>
testAction(
actions.setSortField,
'time_to_last_commit',
......@@ -197,53 +192,48 @@ describe('Productivity analytics table actions', () => {
{ type: 'setColumnMetric', payload: 'time_to_last_commit' },
{ type: 'fetchMergeRequests' },
],
done,
));
it('should not dispatch setColumnMetric when metric is "days_to_merge"', (done) =>
it('should not dispatch setColumnMetric when metric is "days_to_merge"', async () =>
testAction(
actions.setSortField,
'days_to_merge',
mockedContext.state,
[{ type: types.SET_SORT_FIELD, payload: 'days_to_merge' }],
[{ type: 'fetchMergeRequests' }],
done,
));
});
describe('toggleSortOrder', () => {
it('should commit toggleSortOrder', (done) =>
it('should commit toggleSortOrder', async () =>
testAction(
actions.toggleSortOrder,
null,
mockedContext.state,
[{ type: types.TOGGLE_SORT_ORDER }],
[{ type: 'fetchMergeRequests' }],
done,
));
});
describe('setColumnMetric', () => {
it('should commit setColumnMetric', (done) =>
it('should commit setColumnMetric', async () =>
testAction(
actions.setColumnMetric,
'time_to_first_comment',
mockedContext.state,
[{ type: types.SET_COLUMN_METRIC, payload: 'time_to_first_comment' }],
[],
done,
));
});
describe('setPage', () => {
it('should commit setPage', (done) =>
it('should commit setPage', async () =>
testAction(
actions.setPage,
2,
mockedContext.state,
[{ type: types.SET_PAGE, payload: 2 }],
[{ type: 'fetchMergeRequests' }],
done,
));
});
});
This diff is collapsed.
......@@ -70,6 +70,7 @@ describe('Approvals ApproversSelect', () => {
$input = $(wrapper.vm.$refs.input);
};
const search = (term = '') => {
$input.select2('search', term);
jest.runOnlyPendingTimers();
......@@ -93,37 +94,30 @@ describe('Approvals ApproversSelect', () => {
expect(select2Container()).not.toBe(null);
});
it('queries and displays groups and users', async (done) => {
it('queries and displays groups and users', async () => {
await factory();
const expected = TEST_GROUPS.concat(TEST_USERS)
.map(({ id, ...obj }) => obj)
.map(({ username, ...obj }) => (!username ? obj : { ...obj, username: `@${username}` }));
waitForEvent($input, 'select2-loaded')
.then(() => {
const items = select2DropdownItems();
search();
expect(items).toEqual(expected);
})
.then(done)
.catch(done.fail);
await waitForEvent($input, 'select2-loaded');
const items = select2DropdownItems();
search();
expect(items).toEqual(expected);
});
describe('with search term', () => {
const term = 'lorem';
beforeEach(async (done) => {
beforeEach(async () => {
await factory();
waitForEvent($input, 'select2-loaded')
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
search(term);
await waitForEvent($input, 'select2-loaded');
});
it('fetches all available groups', () => {
......@@ -151,14 +145,11 @@ describe('Approvals ApproversSelect', () => {
});
});
it('fetches all available groups including non-visible shared groups', async (done) => {
waitForEvent($input, 'select2-loaded')
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
it('fetches all available groups including non-visible shared groups', async () => {
search();
await waitForEvent($input, 'select2-loaded');
expect(Api.projectGroups).toHaveBeenCalledWith(TEST_PROJECT_ID, {
skip_groups: [],
with_shared: true,
......@@ -172,7 +163,7 @@ describe('Approvals ApproversSelect', () => {
const skipGroupIds = [7, 8];
const skipUserIds = [9, 10];
beforeEach(async (done) => {
beforeEach(async () => {
await factory({
propsData: {
skipGroupIds,
......@@ -180,12 +171,10 @@ describe('Approvals ApproversSelect', () => {
},
});
waitForEvent($input, 'select2-loaded')
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
search();
await waitForEvent($input, 'select2-loaded');
jest.runOnlyPendingTimers();
});
it('skips groups and does not fetch all available', () => {
......@@ -202,7 +191,7 @@ describe('Approvals ApproversSelect', () => {
});
});
it('emits input when data changes', async (done) => {
it('emits input when data changes', async () => {
await factory();
const expectedFinal = [
......@@ -211,24 +200,14 @@ describe('Approvals ApproversSelect', () => {
];
const expected = expectedFinal.map((x, idx) => [expectedFinal.slice(0, idx + 1)]);
waitForEvent($input, 'select2-loaded')
.then(() => {
const options = select2DropdownOptions();
$(options[TEST_GROUPS.length]).trigger('mouseup');
$(options[0]).trigger('mouseup');
})
.then(jest.runOnlyPendingTimers)
.then(done)
.catch(done.fail);
waitForEvent($input, 'change')
.then(jest.runOnlyPendingTimers)
.then(() => {
expect(wrapper.emitted().input).toEqual(expected);
})
.then(done)
.catch(done.fail);
search();
await waitForPromises();
const options = select2DropdownOptions();
$(options[TEST_GROUPS.length]).trigger('mouseup');
$(options[0]).trigger('mouseup');
await waitForPromises();
expect(wrapper.emitted().input).toEqual(expected);
});
});
......@@ -82,7 +82,7 @@ describe('EE approvals license-compliance actions', () => {
});
describe('postRule', () => {
it('posts correct data and dispatches "fetchRules" when request is successful', () => {
it('posts correct data and dispatches "fetchRules" when request is successful', async () => {
const rule = {
name: 'Foo',
approvalsRequired: 1,
......@@ -91,7 +91,7 @@ describe('EE approvals license-compliance actions', () => {
};
axiosMock.onPost(mocks.state.rulesPath).replyOnce(200);
return testAction(
await testAction(
actions.postRule,
rule,
state,
......@@ -101,11 +101,9 @@ describe('EE approvals license-compliance actions', () => {
type: 'fetchRules',
},
],
() => {
expect(axiosMock.history.post[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
},
);
expect(axiosMock.history.post[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
});
......@@ -122,7 +120,7 @@ describe('EE approvals license-compliance actions', () => {
const id = 4;
const putUrl = `${mocks.state.rulesPath}/${4}`;
it('puts correct data and dispatches "fetchRules" when request is successful', () => {
it('puts correct data and dispatches "fetchRules" when request is successful', async () => {
const payload = {
id,
name: 'Foo',
......@@ -132,7 +130,7 @@ describe('EE approvals license-compliance actions', () => {
};
axiosMock.onPut(putUrl).replyOnce(200);
return testAction(
await testAction(
actions.putRule,
payload,
state,
......@@ -142,11 +140,9 @@ describe('EE approvals license-compliance actions', () => {
type: 'fetchRules',
},
],
() => {
expect(axiosMock.history.put[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
},
);
expect(axiosMock.history.put[0].data).toBe(
'{"name":"Foo","approvals_required":1,"users":[8,9],"groups":[7]}',
);
});
......
......@@ -4,21 +4,20 @@ import testAction from 'helpers/vuex_action_helper';
describe('Approval MR edit module actions', () => {
describe('setTargetBranch', () => {
it('commits SET_TARGET_BRANCH', (done) => {
testAction(
it('commits SET_TARGET_BRANCH', async () => {
await testAction(
actions.setTargetBranch,
'main',
{},
[{ type: types.SET_TARGET_BRANCH, payload: 'main' }],
[],
done,
);
});
});
describe('undoRulesChange', () => {
it('commits UNDO_RULES', (done) => {
testAction(actions.undoRulesChange, null, {}, [{ type: types.UNDO_RULES }], [], done);
it('commits UNDO_RULES', async () => {
await testAction(actions.undoRulesChange, null, {}, [{ type: types.UNDO_RULES }], []);
});
});
});
......@@ -239,10 +239,10 @@ describe('fetchEpicsSwimlanes', () => {
},
};
it('should commit mutation RECEIVE_EPICS_SUCCESS on success', (done) => {
it('should commit mutation RECEIVE_EPICS_SUCCESS on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{},
state,
......@@ -253,14 +253,13 @@ describe('fetchEpicsSwimlanes', () => {
},
],
[],
done,
);
});
it('should commit mutation REQUEST_MORE_EPICS when fetchNext is true', (done) => {
it('should commit mutation REQUEST_MORE_EPICS when fetchNext is true', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{ fetchNext: true },
state,
......@@ -272,14 +271,13 @@ describe('fetchEpicsSwimlanes', () => {
},
],
[],
done,
);
});
it('should commit mutation RECEIVE_EPICS_SUCCESS on success with hasMoreEpics when hasNextPage', (done) => {
it('should commit mutation RECEIVE_EPICS_SUCCESS on success with hasMoreEpics when hasNextPage', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponseWithNextPage);
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{},
state,
......@@ -294,20 +292,18 @@ describe('fetchEpicsSwimlanes', () => {
},
],
[],
done,
);
});
it('should commit mutation RECEIVE_SWIMLANES_FAILURE on failure', (done) => {
it('should commit mutation RECEIVE_SWIMLANES_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction(
await testAction(
actions.fetchEpicsSwimlanes,
{},
state,
[{ type: types.RECEIVE_SWIMLANES_FAILURE }],
[],
done,
);
});
});
......@@ -368,14 +364,14 @@ describe('fetchItemsForList', () => {
});
});
it('add epicWildcardId with NONE as value when noEpicIssues is true', () => {
it('add epicWildcardId with NONE as value when noEpicIssues is true', async () => {
state = {
...state,
isShowingEpicsSwimlanes: true,
};
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchItemsForList,
{ listId, noEpicIssues: true },
state,
......@@ -390,27 +386,25 @@ describe('fetchItemsForList', () => {
},
],
[],
() => {
expect(gqlClient.query).toHaveBeenCalledWith({
query: listsIssuesQuery,
variables: {
boardId: 'gid://gitlab/Board/1',
filters: {
epicWildcardId: 'NONE',
},
fullPath: 'gitlab-org',
id: 'gid://gitlab/List/1',
isGroup: true,
isProject: false,
after: undefined,
first: 10,
},
context: {
isSingleRequest: true,
},
});
},
);
expect(gqlClient.query).toHaveBeenCalledWith({
query: listsIssuesQuery,
variables: {
boardId: 'gid://gitlab/Board/1',
filters: {
epicWildcardId: 'NONE',
},
fullPath: 'gitlab-org',
id: 'gid://gitlab/List/1',
isGroup: true,
isProject: false,
after: undefined,
first: 10,
},
context: {
isSingleRequest: true,
},
});
});
});
......@@ -428,11 +422,11 @@ describe('updateBoardEpicUserPreferences', () => {
},
});
it('should send mutation', (done) => {
it('should send mutation', async () => {
const collapsed = true;
jest.spyOn(gqlClient, 'mutate').mockResolvedValue(queryResponse(collapsed));
testAction(
await testAction(
actions.updateBoardEpicUserPreferences,
{ epicId: mockEpic.id, collapsed },
state,
......@@ -448,24 +442,22 @@ describe('updateBoardEpicUserPreferences', () => {
},
],
[],
done,
);
});
});
describe('setShowLabels', () => {
it('should commit mutation SET_SHOW_LABELS', (done) => {
it('should commit mutation SET_SHOW_LABELS', async () => {
const state = {
isShowingLabels: true,
};
testAction(
await testAction(
actions.setShowLabels,
false,
state,
[{ type: types.SET_SHOW_LABELS, payload: false }],
[],
done,
);
});
});
......@@ -561,10 +553,10 @@ describe('fetchIssuesForEpic', () => {
const formattedIssues = formatListIssues(queryResponse.data.group.board.lists);
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', (done) => {
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_SUCCESS on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchIssuesForEpic,
epicId,
state,
......@@ -573,14 +565,13 @@ describe('fetchIssuesForEpic', () => {
{ type: types.RECEIVE_ISSUES_FOR_EPIC_SUCCESS, payload: { ...formattedIssues, epicId } },
],
[],
done,
);
});
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', (done) => {
it('should commit mutations REQUEST_ISSUES_FOR_EPIC and RECEIVE_ITEMS_FOR_LIST_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(Promise.reject());
testAction(
await testAction(
actions.fetchIssuesForEpic,
epicId,
state,
......@@ -589,13 +580,12 @@ describe('fetchIssuesForEpic', () => {
{ type: types.RECEIVE_ISSUES_FOR_EPIC_FAILURE, payload: epicId },
],
[],
done,
);
});
});
describe('toggleEpicSwimlanes', () => {
it('should commit mutation TOGGLE_EPICS_SWIMLANES', () => {
it('should commit mutation TOGGLE_EPICS_SWIMLANES', async () => {
const startURl = `${TEST_HOST}/groups/gitlab-org/-/boards/1?group_by=epic`;
setWindowLocation(startURl);
......@@ -687,14 +677,14 @@ describe('setActiveItemWeight', () => {
const testWeight = mockIssue.weight + 1;
const input = { weight: testWeight, id: mockIssue.id };
it('should commit weight', (done) => {
it('should commit weight', async () => {
const payload = {
itemId: getters.activeBoardItem.id,
prop: 'weight',
value: testWeight,
};
testAction(
await testAction(
actions.setActiveItemWeight,
input,
{ ...state, ...getters },
......@@ -705,7 +695,6 @@ describe('setActiveItemWeight', () => {
},
],
[],
done,
);
});
......@@ -1280,10 +1269,10 @@ describe('fetchSubGroups', () => {
},
};
it('should commit mutations REQUEST_SUB_GROUPS, RECEIVE_SUB_GROUPS_SUCCESS, and SET_SELECTED_GROUP on success', (done) => {
it('should commit mutations REQUEST_SUB_GROUPS, RECEIVE_SUB_GROUPS_SUCCESS, and SET_SELECTED_GROUP on success', async () => {
jest.spyOn(gqlClient, 'query').mockResolvedValue(queryResponse);
testAction(
await testAction(
actions.fetchSubGroups,
{},
state,
......@@ -1302,14 +1291,13 @@ describe('fetchSubGroups', () => {
},
],
[],
done,
);
});
it('should commit mutations REQUEST_SUB_GROUPS and RECEIVE_SUB_GROUPS_FAILURE on failure', (done) => {
it('should commit mutations REQUEST_SUB_GROUPS and RECEIVE_SUB_GROUPS_FAILURE on failure', async () => {
jest.spyOn(gqlClient, 'query').mockRejectedValue();
testAction(
await testAction(
actions.fetchSubGroups,
{},
state,
......@@ -1323,14 +1311,13 @@ describe('fetchSubGroups', () => {
},
],
[],
done,
);
});
});
describe('setSelectedGroup', () => {
it('should commit mutation SET_SELECTED_GROUP', (done) => {
testAction(
it('should commit mutation SET_SELECTED_GROUP', async () => {
await testAction(
actions.setSelectedGroup,
mockGroup0,
{},
......@@ -1341,7 +1328,6 @@ describe('setSelectedGroup', () => {
},
],
[],
done,
);
});
});
......
......@@ -34,21 +34,14 @@ describe('Codequality report actions', () => {
});
describe('setPage', () => {
it('sets the page number', (done) => {
return testAction(
actions.setPage,
12,
state,
[{ type: types.SET_PAGE, payload: 12 }],
[],
done,
);
it('sets the page number', async () => {
await testAction(actions.setPage, 12, state, [{ type: types.SET_PAGE, payload: 12 }], []);
});
});
describe('requestReport', () => {
it('sets the loading flag', (done) => {
testAction(actions.requestReport, null, state, [{ type: types.REQUEST_REPORT }], [], done);
it('sets the loading flag', async () => {
await testAction(actions.requestReport, null, state, [{ type: types.REQUEST_REPORT }], []);
});
it('tracks a service ping event', () => {
......@@ -59,27 +52,25 @@ describe('Codequality report actions', () => {
});
describe('receiveReportSuccess', () => {
it('parses the list of issues from the report', (done) => {
return testAction(
it('parses the list of issues from the report', async () => {
await testAction(
actions.receiveReportSuccess,
unparsedIssues,
{ blobPath: '/root/test-codequality/blob/feature-branch', ...state },
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: parsedIssues }],
[],
done,
);
});
});
describe('receiveReportError', () => {
it('accepts a report error', (done) => {
testAction(
it('accepts a report error', async () => {
await testAction(
actions.receiveReportError,
'error',
state,
[{ type: types.RECEIVE_REPORT_ERROR, payload: 'error' }],
[],
done,
);
});
});
......@@ -89,47 +80,40 @@ describe('Codequality report actions', () => {
mock.onGet(endpoint).replyOnce(200, unparsedIssues);
});
it('fetches the report', (done) => {
return testAction(
it('fetches the report', async () => {
await testAction(
actions.fetchReport,
null,
{ blobPath: 'blah', ...state },
[],
[{ type: 'requestReport' }, { type: 'receiveReportSuccess', payload: unparsedIssues }],
done,
);
});
it('shows a flash message when there is an error', (done) => {
testAction(
it('shows a flash message when there is an error', async () => {
await testAction(
actions.fetchReport,
'error',
state,
[],
[{ type: 'requestReport' }, { type: 'receiveReportError', payload: expect.any(Error) }],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
done();
},
);
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
});
it('shows an error when blob path is missing', (done) => {
testAction(
it('shows an error when blob path is missing', async () => {
await testAction(
actions.fetchReport,
null,
state,
[],
[{ type: 'requestReport' }, { type: 'receiveReportError', payload: expect.any(Error) }],
() => {
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
done();
},
);
expect(createFlash).toHaveBeenCalledWith({
message: 'There was an error fetching the codequality report.',
});
});
});
});
......@@ -17,16 +17,15 @@ jest.mock('~/flash');
describe('EE DiffsStoreActions', () => {
describe('setCodequalityEndpoint', () => {
it('should set given endpoint', (done) => {
it('should set given endpoint', async () => {
const endpoint = '/codequality_mr_diff.json';
testAction(
await testAction(
setCodequalityEndpoint,
{ endpoint },
{},
[{ type: types.SET_CODEQUALITY_ENDPOINT, payload: { endpoint } }],
[],
done,
);
});
});
......@@ -44,20 +43,19 @@ describe('EE DiffsStoreActions', () => {
clearCodequalityPoll();
});
it('should commit SET_CODEQUALITY_DATA with received response and stop polling', (done) => {
it('should commit SET_CODEQUALITY_DATA with received response and stop polling', async () => {
const data = {
files: { 'app.js': [{ line: 1, description: 'Unexpected alert.', severity: 'minor' }] },
};
mock.onGet(endpointCodequality).reply(200, { data });
testAction(
await testAction(
fetchCodequality,
{},
{ endpointCodequality },
[{ type: types.SET_CODEQUALITY_DATA, payload: { data } }],
[{ type: 'stopCodequalityPolling' }],
done,
);
});
......@@ -72,63 +70,57 @@ describe('EE DiffsStoreActions', () => {
mock.onGet(endpointCodequality).reply(400);
});
it('should not show a flash message', (done) => {
testAction(fetchCodequality, {}, { endpointCodequality }, [], [], () => {
expect(createFlash).not.toHaveBeenCalled();
done();
});
it('should not show a flash message', async () => {
await testAction(fetchCodequality, {}, { endpointCodequality }, [], []);
expect(createFlash).not.toHaveBeenCalled();
});
it('should retry five times with a delay, then stop polling', (done) => {
testAction(fetchCodequality, {}, { endpointCodequality }, [], [], () => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(RETRY_DELAY);
waitForPromises()
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(2);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(5);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => {
expect(pollStop).toHaveBeenCalledTimes(1);
})
.then(done)
.catch(done.fail);
});
it('should retry five times with a delay, then stop polling', async () => {
await testAction(fetchCodequality, {}, { endpointCodequality }, [], []);
expect(pollDelayedRequest).toHaveBeenCalledTimes(1);
expect(pollStop).toHaveBeenCalledTimes(0);
jest.advanceTimersByTime(RETRY_DELAY);
return waitForPromises()
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(2);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => jest.advanceTimersByTime(RETRY_DELAY))
.then(() => waitForPromises())
.then(() => {
expect(pollDelayedRequest).toHaveBeenCalledTimes(5);
jest.advanceTimersByTime(RETRY_DELAY);
})
.then(() => waitForPromises())
.then(() => {
expect(pollStop).toHaveBeenCalledTimes(1);
});
});
});
it('with unexpected error should stop polling and show a flash message', (done) => {
it('with unexpected error should stop polling and show a flash message', async () => {
mock.onGet(endpointCodequality).reply(500);
testAction(
await testAction(
fetchCodequality,
{},
{ endpointCodequality },
[],
[{ type: 'stopCodequalityPolling' }],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
expect(createFlash).toHaveBeenCalledWith({
message: 'An unexpected error occurred while loading the code quality diff.',
});
done();
},
);
expect(createFlash).toHaveBeenCalledTimes(1);
expect(createFlash).toHaveBeenCalledWith({
message: 'An unexpected error occurred while loading the code quality diff.',
});
});
});
});
This diff is collapsed.
......@@ -41,21 +41,20 @@ describe('GeoReplicable Store Actions', () => {
});
describe('requestReplicableItems', () => {
it('should commit mutation REQUEST_REPLICABLE_ITEMS', (done) => {
testAction(
it('should commit mutation REQUEST_REPLICABLE_ITEMS', async () => {
await testAction(
actions.requestReplicableItems,
null,
state,
[{ type: types.REQUEST_REPLICABLE_ITEMS }],
[],
done,
);
});
});
describe('receiveReplicableItemsSuccess', () => {
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_SUCCESS', (done) => {
testAction(
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_SUCCESS', async () => {
await testAction(
actions.receiveReplicableItemsSuccess,
{ data: MOCK_BASIC_FETCH_DATA_MAP, pagination: MOCK_RESTFUL_PAGINATION_DATA },
state,
......@@ -66,14 +65,13 @@ describe('GeoReplicable Store Actions', () => {
},
],
[],
done,
);
});
});
describe('receiveReplicableItemsError', () => {
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_ERROR', () => {
testAction(
it('should commit mutation RECEIVE_REPLICABLE_ITEMS_ERROR', async () => {
await testAction(
actions.receiveReplicableItemsError,
null,
state,
......@@ -92,8 +90,8 @@ describe('GeoReplicable Store Actions', () => {
state.useGraphQl = true;
});
it('calls fetchReplicableItemsGraphQl', (done) => {
testAction(
it('calls fetchReplicableItemsGraphQl', async () => {
await testAction(
actions.fetchReplicableItems,
null,
state,
......@@ -102,7 +100,6 @@ describe('GeoReplicable Store Actions', () => {
{ type: 'requestReplicableItems' },
{ type: 'fetchReplicableItemsGraphQl', payload: null },
],
done,
);
});
});
......@@ -112,14 +109,13 @@ describe('GeoReplicable Store Actions', () => {
state.useGraphQl = false;
});
it('calls fetchReplicableItemsRestful', (done) => {
testAction(
it('calls fetchReplicableItemsRestful', async () => {
await testAction(
actions.fetchReplicableItems,
null,
state,
[],
[{ type: 'requestReplicableItems' }, { type: 'fetchReplicableItemsRestful' }],
done,
);
});
});
......@@ -278,14 +274,13 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(mockGeoGqClient, 'query').mockRejectedValue();
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.fetchReplicableItemsGraphQl,
null,
state,
[],
[{ type: 'receiveReplicableItemsError' }],
done,
);
});
});
......@@ -366,35 +361,33 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(Api, 'getGeoReplicableItems').mockRejectedValue(new Error(500));
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.fetchReplicableItemsRestful,
{},
state,
[],
[{ type: 'receiveReplicableItemsError' }],
done,
);
});
});
});
describe('requestInitiateAllReplicableSyncs', () => {
it('should commit mutation REQUEST_INITIATE_ALL_REPLICABLE_SYNCS', (done) => {
testAction(
it('should commit mutation REQUEST_INITIATE_ALL_REPLICABLE_SYNCS', async () => {
await testAction(
actions.requestInitiateAllReplicableSyncs,
null,
state,
[{ type: types.REQUEST_INITIATE_ALL_REPLICABLE_SYNCS }],
[],
done,
);
});
});
describe('receiveInitiateAllReplicableSyncsSuccess', () => {
it('should commit mutation RECEIVE_INITIATE_ALL_REPLICABLE_SYNCS_SUCCESS and call fetchReplicableItems and toast', () => {
testAction(
it('should commit mutation RECEIVE_INITIATE_ALL_REPLICABLE_SYNCS_SUCCESS and call fetchReplicableItems and toast', async () => {
await testAction(
actions.receiveInitiateAllReplicableSyncsSuccess,
{ action: ACTION_TYPES.RESYNC },
state,
......@@ -460,8 +453,8 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(Api, 'initiateAllGeoReplicableSyncs').mockRejectedValue(new Error(500));
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.initiateAllReplicableSyncs,
action,
state,
......@@ -470,53 +463,47 @@ describe('GeoReplicable Store Actions', () => {
{ type: 'requestInitiateAllReplicableSyncs' },
{ type: 'receiveInitiateAllReplicableSyncsError' },
],
done,
);
});
});
});
describe('requestInitiateReplicableSync', () => {
it('should commit mutation REQUEST_INITIATE_REPLICABLE_SYNC', (done) => {
testAction(
it('should commit mutation REQUEST_INITIATE_REPLICABLE_SYNC', async () => {
await testAction(
actions.requestInitiateReplicableSync,
null,
state,
[{ type: types.REQUEST_INITIATE_REPLICABLE_SYNC }],
[],
done,
);
});
});
describe('receiveInitiateReplicableSyncSuccess', () => {
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_SUCCESS and call fetchReplicableItems and toast', () => {
testAction(
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_SUCCESS and call fetchReplicableItems and toast', async () => {
await testAction(
actions.receiveInitiateReplicableSyncSuccess,
{ action: ACTION_TYPES.RESYNC, projectName: 'test' },
state,
[{ type: types.RECEIVE_INITIATE_REPLICABLE_SYNC_SUCCESS }],
[{ type: 'fetchReplicableItems' }],
() => {
expect(toast).toHaveBeenCalledTimes(1);
toast.mockClear();
},
);
expect(toast).toHaveBeenCalledTimes(1);
toast.mockClear();
});
});
describe('receiveInitiateReplicableSyncError', () => {
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_ERROR', () => {
testAction(
it('should commit mutation RECEIVE_INITIATE_REPLICABLE_SYNC_ERROR', async () => {
await testAction(
actions.receiveInitiateReplicableSyncError,
{ action: ACTION_TYPES.RESYNC, projectId: 1, projectName: 'test' },
state,
[{ type: types.RECEIVE_INITIATE_REPLICABLE_SYNC_ERROR }],
[],
() => {
expect(createFlash).toHaveBeenCalledTimes(1);
},
);
expect(createFlash).toHaveBeenCalledTimes(1);
});
});
......@@ -543,13 +530,11 @@ describe('GeoReplicable Store Actions', () => {
{ type: 'requestInitiateReplicableSync' },
{ type: 'receiveInitiateReplicableSyncSuccess', payload: { name, action } },
],
() => {
expect(Api.initiateGeoReplicableSync).toHaveBeenCalledWith(MOCK_REPLICABLE_TYPE, {
projectId,
action,
});
},
);
expect(Api.initiateGeoReplicableSync).toHaveBeenCalledWith(MOCK_REPLICABLE_TYPE, {
projectId,
action,
});
});
});
......@@ -561,8 +546,8 @@ describe('GeoReplicable Store Actions', () => {
jest.spyOn(Api, 'initiateGeoReplicableSync').mockRejectedValue(new Error(500));
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.initiateReplicableSync,
{ projectId, name, action },
state,
......@@ -574,55 +559,51 @@ describe('GeoReplicable Store Actions', () => {
payload: { name: 'test' },
},
],
done,
);
});
});
});
describe('setFilter', () => {
it('should commit mutation SET_FILTER', (done) => {
it('should commit mutation SET_FILTER', async () => {
const testValue = 1;
testAction(
await testAction(
actions.setFilter,
testValue,
state,
[{ type: types.SET_FILTER, payload: testValue }],
[],
done,
);
});
});
describe('setSearch', () => {
it('should commit mutation SET_SEARCH', (done) => {
it('should commit mutation SET_SEARCH', async () => {
const testValue = 'Test Search';
testAction(
await testAction(
actions.setSearch,
testValue,
state,
[{ type: types.SET_SEARCH, payload: testValue }],
[],
done,
);
});
});
describe('setPage', () => {
it('should commit mutation SET_PAGE', (done) => {
it('should commit mutation SET_PAGE', async () => {
state.paginationData.page = 1;
const testValue = 2;
testAction(
await testAction(
actions.setPage,
testValue,
state,
[{ type: types.SET_PAGE, payload: testValue }],
[],
done,
);
});
});
......
......@@ -70,41 +70,29 @@ describe('GroupMemberStore', () => {
mock.restore();
});
it('calls service.getContributedMembers and sets response to the store on success', (done) => {
it('calls service.getContributedMembers and sets response to the store on success', async () => {
mock.onGet(contributionsPath).reply(200, rawMembers);
jest.spyOn(store, 'setColumns').mockImplementation(() => {});
jest.spyOn(store, 'setMembers').mockImplementation(() => {});
store
.fetchContributedMembers()
.then(() => {
expect(store.isLoading).toBe(false);
expect(store.setColumns).toHaveBeenCalledWith(expect.any(Object));
expect(store.setMembers).toHaveBeenCalledWith(rawMembers);
done();
})
.catch(done.fail);
expect(store.isLoading).toBe(true);
await store.fetchContributedMembers();
expect(store.isLoading).toBe(false);
expect(store.setColumns).toHaveBeenCalledWith(expect.any(Object));
expect(store.setMembers).toHaveBeenCalledWith(rawMembers);
});
it('calls service.getContributedMembers and sets `isLoading` to false and shows flash message if request failed', (done) => {
it('calls service.getContributedMembers and sets `isLoading` to false and shows flash message if request failed', async () => {
mock.onGet(contributionsPath).reply(500, {});
store
.fetchContributedMembers()
.then(() => done.fail('Expected error to be thrown!'))
.catch((e) => {
expect(e.message).toBe('Request failed with status code 500');
expect(store.isLoading).toBe(false);
expect(createFlash).toHaveBeenCalledWith({
message: 'Something went wrong while fetching group member contributions',
});
})
.then(done)
.catch(done.fail);
expect(store.isLoading).toBe(true);
await expect(store.fetchContributedMembers()).rejects.toEqual(
new Error('Request failed with status code 500'),
);
expect(store.isLoading).toBe(false);
expect(createFlash).toHaveBeenCalledWith({
message: 'Something went wrong while fetching group member contributions',
});
});
});
});
......@@ -23,7 +23,7 @@ describe('saml_members actions', () => {
});
describe('fetchPage', () => {
it('should commit RECEIVE_SAML_MEMBERS_SUCCESS mutation on correct data', (done) => {
it('should commit RECEIVE_SAML_MEMBERS_SUCCESS mutation on correct data', async () => {
const members = [
{ id: 1, name: 'user 1', group_saml_identity: null },
{ id: 2, name: 'user 2', group_saml_identity: { extern_uid: 'a' } },
......@@ -57,7 +57,7 @@ describe('saml_members actions', () => {
previousPage: 1,
};
testAction(
await testAction(
fetchPage,
undefined,
state,
......@@ -68,16 +68,14 @@ describe('saml_members actions', () => {
},
],
[],
done,
);
});
it('should show flash on wrong data', (done) => {
it('should show flash on wrong data', async () => {
Api.groupMembers.mockReturnValue(Promise.reject(new Error()));
testAction(fetchPage, undefined, state, [], [], () => {
expect(createFlash).toHaveBeenCalledTimes(1);
done();
});
await testAction(fetchPage, undefined, state, [], []);
expect(createFlash).toHaveBeenCalledTimes(1);
});
});
});
......@@ -1648,15 +1648,12 @@ describe('RelatedItemTree', () => {
requestSpy.mockReturnValue([500, '']);
});
it('fails and shows flash message', (done) => {
return actions
.createNewIssue(context, payload)
.then(() => done.fail('expected action to throw error!'))
.catch(() => {
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
expect(context.dispatch).toHaveBeenCalledWith('receiveCreateIssueFailure');
done();
});
it('fails and shows flash message', async () => {
await expect(actions.createNewIssue(context, payload)).rejects.toEqual(
new Error('Request failed with status code 500'),
);
expect(requestSpy).toHaveBeenCalledWith(expectedRequest);
expect(context.dispatch).toHaveBeenCalledWith('receiveCreateIssueFailure');
});
});
});
......
......@@ -17,8 +17,8 @@ describe('pipeling jobs actions', () => {
describe('setPipelineJobsPath', () => {
const pipelineJobsPath = 123;
it('should commit the SET_PIPELINE_JOBS_PATH mutation', (done) => {
testAction(
it('should commit the SET_PIPELINE_JOBS_PATH mutation', async () => {
await testAction(
actions.setPipelineJobsPath,
pipelineJobsPath,
state,
......@@ -29,7 +29,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -37,8 +36,8 @@ describe('pipeling jobs actions', () => {
describe('setProjectId', () => {
const projectId = 123;
it('should commit the SET_PIPELINE_JOBS_PATH mutation', (done) => {
testAction(
it('should commit the SET_PIPELINE_JOBS_PATH mutation', async () => {
await testAction(
actions.setProjectId,
projectId,
state,
......@@ -49,7 +48,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -57,8 +55,8 @@ describe('pipeling jobs actions', () => {
describe('setPipelineId', () => {
const pipelineId = 123;
it('should commit the SET_PIPELINE_ID mutation', (done) => {
testAction(
it('should commit the SET_PIPELINE_ID mutation', async () => {
await testAction(
actions.setPipelineId,
pipelineId,
state,
......@@ -69,7 +67,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -92,8 +89,8 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(200, jobs);
});
it('should commit the request and success mutations', (done) => {
testAction(
it('should commit the request and success mutations', async () => {
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -105,7 +102,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -115,12 +111,12 @@ describe('pipeling jobs actions', () => {
mock.onGet('/api/undefined/projects/123/pipelines/321/jobs').replyOnce(200, jobs);
});
it('should commit the request and success mutations', (done) => {
it('should commit the request and success mutations', async () => {
state.pipelineJobsPath = '';
state.projectId = 123;
state.pipelineId = 321;
testAction(
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -132,7 +128,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -142,10 +137,10 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(200, jobs);
});
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', (done) => {
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', async () => {
state.pipelineJobsPath = '';
testAction(
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -155,7 +150,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -165,12 +159,12 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(200, jobs);
});
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', (done) => {
it('should commit RECEIVE_PIPELINE_JOBS_ERROR mutation', async () => {
state.pipelineJobsPath = '';
state.projectId = undefined;
state.pipelineId = undefined;
testAction(
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -180,7 +174,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......@@ -190,8 +183,8 @@ describe('pipeling jobs actions', () => {
mock.onGet(state.pipelineJobsPath).replyOnce(404);
});
it('should commit REQUEST_PIPELINE_JOBS and RECEIVE_PIPELINE_JOBS_ERROR mutation', (done) => {
testAction(
it('should commit REQUEST_PIPELINE_JOBS and RECEIVE_PIPELINE_JOBS_ERROR mutation', async () => {
await testAction(
actions.fetchPipelineJobs,
{},
state,
......@@ -202,7 +195,6 @@ describe('pipeling jobs actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -45,10 +45,10 @@ describe('EE projectSelector actions', () => {
});
describe('toggleSelectedProject', () => {
it('adds a project to selectedProjects if it does not already exist in the list', (done) => {
it('adds a project to selectedProjects if it does not already exist in the list', async () => {
const payload = getMockProjects(1);
testAction(
await testAction(
actions.toggleSelectedProject,
payload,
state,
......@@ -59,15 +59,14 @@ describe('EE projectSelector actions', () => {
},
],
[],
done,
);
});
it('removes a project from selectedProjects if it already exist in the list', () => {
it('removes a project from selectedProjects if it already exist in the list', async () => {
const payload = getMockProjects(1)[0];
state.selectedProjects = getMockProjects(1);
return testAction(
await testAction(
actions.toggleSelectedProject,
payload,
state,
......@@ -102,12 +101,12 @@ describe('EE projectSelector actions', () => {
});
});
it('dispatches the correct actions when the request is successful', () => {
it('dispatches the correct actions when the request is successful', async () => {
state.projectEndpoints.add = mockAddEndpoint;
mockAxios.onPost(mockAddEndpoint).replyOnce(200, mockResponse);
return testAction(
await testAction(
actions.addProjects,
null,
state,
......
......@@ -43,8 +43,8 @@ describe('projects actions', () => {
});
});
it('should dispatch the request and success actions', (done) => {
testAction(
it('should dispatch the request and success actions', async () => {
await testAction(
actions.fetchProjects,
{},
state,
......@@ -56,7 +56,6 @@ describe('projects actions', () => {
payload: { projects: data },
},
],
done,
);
});
});
......@@ -70,8 +69,8 @@ describe('projects actions', () => {
mock.onGet(state.projectsEndpoint, { page: '2' }).replyOnce(200, [2]);
});
it('should dispatch the request and success actions', (done) => {
testAction(
it('should dispatch the request and success actions', async () => {
await testAction(
actions.fetchProjects,
{},
state,
......@@ -83,7 +82,6 @@ describe('projects actions', () => {
payload: { projects: [1, 2] },
},
],
done,
);
});
});
......@@ -93,14 +91,13 @@ describe('projects actions', () => {
mock.onGet(state.projectsEndpoint).replyOnce(404, {});
});
it('should dispatch the request and error actions', (done) => {
testAction(
it('should dispatch the request and error actions', async () => {
await testAction(
actions.fetchProjects,
{},
state,
[],
[{ type: 'requestProjects' }, { type: 'receiveProjectsError' }],
done,
);
});
});
......@@ -110,17 +107,17 @@ describe('projects actions', () => {
state.projectsEndpoint = '';
});
it('should not do anything', (done) => {
testAction(actions.fetchProjects, {}, state, [], [], done);
it('should not do anything', async () => {
await testAction(actions.fetchProjects, {}, state, [], []);
});
});
});
describe('receiveProjectsSuccess', () => {
it('should commit the success mutation', (done) => {
it('should commit the success mutation', async () => {
const state = createState();
testAction(
await testAction(
actions.receiveProjectsSuccess,
{ projects: data },
state,
......@@ -131,39 +128,37 @@ describe('projects actions', () => {
},
],
[],
done,
);
});
});
describe('receiveProjectsError', () => {
it('should commit the error mutation', (done) => {
it('should commit the error mutation', async () => {
const state = createState();
testAction(
await testAction(
actions.receiveProjectsError,
{},
state,
[{ type: types.RECEIVE_PROJECTS_ERROR }],
[],
done,
);
});
});
describe('requestProjects', () => {
it('should commit the request mutation', (done) => {
it('should commit the request mutation', async () => {
const state = createState();
testAction(actions.requestProjects, {}, state, [{ type: types.REQUEST_PROJECTS }], [], done);
await testAction(actions.requestProjects, {}, state, [{ type: types.REQUEST_PROJECTS }], []);
});
});
describe('setProjectsEndpoint', () => {
it('should commit the correct mutuation', (done) => {
it('should commit the correct mutuation', async () => {
const state = createState();
testAction(
await testAction(
actions.setProjectsEndpoint,
endpoint,
state,
......@@ -174,7 +169,6 @@ describe('projects actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -98,22 +98,20 @@ describe('Status Page actions', () => {
});
describe('receiveStatusPageSettingsUpdateSuccess', () => {
it('should handle successful settings update', (done) => {
testAction(actions.receiveStatusPageSettingsUpdateSuccess, null, null, [], [], () => {
expect(refreshCurrentPage).toHaveBeenCalledTimes(1);
done();
});
it('should handle successful settings update', async () => {
await testAction(actions.receiveStatusPageSettingsUpdateSuccess, null, null, [], []);
expect(refreshCurrentPage).toHaveBeenCalledTimes(1);
});
});
describe('receiveStatusPageSettingsUpdateError', () => {
const error = { response: { data: { message: 'Update error' } } };
it('should handle error update', (done) => {
testAction(actions.receiveStatusPageSettingsUpdateError, error, null, [], [], () => {
it('should handle error update', async () => {
await testAction(actions.receiveStatusPageSettingsUpdateError, error, null, [], [], () => {
expect(createFlash).toHaveBeenCalledWith({
message: `There was an error saving your changes. ${error.response.data.message}`,
});
done();
});
});
});
......
......@@ -4,10 +4,6 @@ import ApprovalsAuth from 'ee/vue_merge_request_widget/components/approvals/appr
const TEST_PASSWORD = 'password';
// For some reason, the `Promise.resolve` needs to be deferred
// or the timing doesn't work.
const waitForTick = (done) => Promise.resolve().then(done).catch(done.fail);
describe('Approval auth component', () => {
let wrapper;
......@@ -22,16 +18,14 @@ describe('Approval auth component', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
const findInput = () => wrapper.find('input[type=password]');
const findErrorMessage = () => wrapper.find('.gl-field-error');
describe('when created', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent();
waitForTick(done);
});
it('password input control is rendered', () => {
......@@ -54,24 +48,21 @@ describe('Approval auth component', () => {
});
describe('when approve clicked', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent();
waitForTick(done);
});
it('emits the approve event', (done) => {
it('emits the approve event', async () => {
findInput().setValue(TEST_PASSWORD);
wrapper.findComponent(GlModal).vm.$emit('ok', { preventDefault: () => null });
waitForTick(done);
expect(wrapper.emitted().approve).toEqual([[TEST_PASSWORD]]);
});
});
describe('when isApproving is true', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent({ isApproving: true });
waitForTick(done);
});
it('disables the approve button', () => {
......@@ -82,9 +73,8 @@ describe('Approval auth component', () => {
});
describe('when hasError is true', () => {
beforeEach((done) => {
beforeEach(() => {
createComponent({ hasError: true });
waitForTick(done);
});
it('shows the invalid password message', () => {
......
......@@ -46,7 +46,7 @@ describe('AddLicenseFormDropdown', () => {
expect(vm.$el.value).toContain(value);
});
it('shows all defined licenses', async (done) => {
it('shows all defined licenses', async () => {
await createComponent();
const element = $(vm.$el);
......@@ -58,7 +58,6 @@ describe('AddLicenseFormDropdown', () => {
options.each((index, optionEl) => {
expect(KNOWN_LICENSES).toContain($(optionEl).text());
});
done();
});
element.select2('open');
......
......@@ -25,8 +25,8 @@ describe('EE api fuzzing report actions', () => {
});
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, (done) => {
testAction(
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, async () => {
await testAction(
actions.updateVulnerability,
issue,
state,
......@@ -37,14 +37,13 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
describe('setDiffEndpoint', () => {
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, (done) => {
testAction(
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, async () => {
await testAction(
actions.setDiffEndpoint,
diffEndpoint,
state,
......@@ -55,20 +54,19 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
describe('requestDiff', () => {
it(`should commit ${types.REQUEST_DIFF}`, (done) => {
testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], [], done);
it(`should commit ${types.REQUEST_DIFF}`, async () => {
await testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], []);
});
});
describe('receiveDiffSuccess', () => {
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, (done) => {
testAction(
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, async () => {
await testAction(
actions.receiveDiffSuccess,
reports,
state,
......@@ -79,14 +77,13 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
describe('receiveDiffError', () => {
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, (done) => {
testAction(
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, async () => {
await testAction(
actions.receiveDiffError,
error,
state,
......@@ -97,7 +94,6 @@ describe('EE api fuzzing report actions', () => {
},
],
[],
done,
);
});
});
......@@ -124,9 +120,9 @@ describe('EE api fuzzing report actions', () => {
.replyOnce(200, reports.enrichData);
});
it('should dispatch the `receiveDiffSuccess` action', (done) => {
it('should dispatch the `receiveDiffSuccess` action', async () => {
const { diff, enrichData } = reports;
testAction(
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
......@@ -141,7 +137,6 @@ describe('EE api fuzzing report actions', () => {
},
},
],
done,
);
});
});
......@@ -152,10 +147,10 @@ describe('EE api fuzzing report actions', () => {
mock.onGet(diffEndpoint).replyOnce(200, reports.diff);
});
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', (done) => {
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', async () => {
const { diff } = reports;
const enrichData = [];
testAction(
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
......@@ -170,7 +165,6 @@ describe('EE api fuzzing report actions', () => {
},
},
],
done,
);
});
});
......@@ -184,14 +178,13 @@ describe('EE api fuzzing report actions', () => {
.replyOnce(404);
});
it('should dispatch the `receiveError` action', (done) => {
testAction(
it('should dispatch the `receiveError` action', async () => {
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
);
});
});
......@@ -205,14 +198,13 @@ describe('EE api fuzzing report actions', () => {
.replyOnce(200, reports.enrichData);
});
it('should dispatch the `receiveDiffError` action', (done) => {
testAction(
it('should dispatch the `receiveDiffError` action', async () => {
await testAction(
actions.fetchDiff,
{},
{ ...rootState, ...state },
[],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
);
});
});
......
......@@ -14,8 +14,8 @@ describe('EE sast report actions', () => {
});
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, (done) => {
testAction(
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, async () => {
await testAction(
actions.updateVulnerability,
issue,
state,
......@@ -26,7 +26,6 @@ describe('EE sast report actions', () => {
},
],
[],
done,
);
});
});
......
......@@ -14,8 +14,8 @@ describe('EE secret detection report actions', () => {
});
describe('updateVulnerability', () => {
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, (done) => {
testAction(
it(`should commit ${types.UPDATE_VULNERABILITY} with the correct response`, async () => {
await testAction(
actions.updateVulnerability,
issue,
state,
......@@ -26,7 +26,6 @@ describe('EE secret detection report actions', () => {
},
],
[],
done,
);
});
});
......
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