Commit a7e73ed0 authored by Tom Quirk's avatar Tom Quirk

Address reviewer feedback

Improve store dispatch mock function
parent 32d6f322
...@@ -22,11 +22,7 @@ const FIXTURE = 'services/edit_service.html'; ...@@ -22,11 +22,7 @@ const FIXTURE = 'services/edit_service.html';
describe('IntegrationSettingsForm', () => { describe('IntegrationSettingsForm', () => {
let integrationSettingsForm; let integrationSettingsForm;
const mockVuexDispatch = () => { const mockStoreDispatch = () => jest.spyOn(integrationSettingsForm.vue.$store, 'dispatch');
const dispatchSpy = jest.fn();
integrationSettingsForm.vue.$store = { dispatch: dispatchSpy };
return dispatchSpy;
};
beforeEach(() => { beforeEach(() => {
loadFixtures(FIXTURE); loadFixtures(FIXTURE);
...@@ -130,7 +126,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -130,7 +126,7 @@ describe('IntegrationSettingsForm', () => {
}); });
it('should always dispatch `setIsTesting` with `false` once request is completed', async () => { it('should always dispatch `setIsTesting` with `false` once request is completed', async () => {
const dispatchSpy = mockVuexDispatch(); const dispatchSpy = mockStoreDispatch();
mockAxios.onPut(integrationSettingsForm.testEndPoint).networkError(); mockAxios.onPut(integrationSettingsForm.testEndPoint).networkError();
eventHub.$emit(TEST_INTEGRATION_EVENT); eventHub.$emit(TEST_INTEGRATION_EVENT);
...@@ -147,7 +143,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -147,7 +143,7 @@ describe('IntegrationSettingsForm', () => {
}); });
it('should dispatch `setIsTesting` with `false` and not call `testSettings`', async () => { it('should dispatch `setIsTesting` with `false` and not call `testSettings`', async () => {
const dispatchSpy = mockVuexDispatch(); const dispatchSpy = mockStoreDispatch();
eventHub.$emit(TEST_INTEGRATION_EVENT); eventHub.$emit(TEST_INTEGRATION_EVENT);
await waitForPromises(); await waitForPromises();
...@@ -160,7 +156,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -160,7 +156,7 @@ describe('IntegrationSettingsForm', () => {
describe('when event hub receives `GET_JIRA_ISSUE_TYPES_EVENT`', () => { describe('when event hub receives `GET_JIRA_ISSUE_TYPES_EVENT`', () => {
it('should always dispatch `requestJiraIssueTypes`', () => { it('should always dispatch `requestJiraIssueTypes`', () => {
const dispatchSpy = mockVuexDispatch(); const dispatchSpy = mockStoreDispatch();
mockAxios.onPut(integrationSettingsForm.testEndPoint).networkError(); mockAxios.onPut(integrationSettingsForm.testEndPoint).networkError();
eventHub.$emit(GET_JIRA_ISSUE_TYPES_EVENT); eventHub.$emit(GET_JIRA_ISSUE_TYPES_EVENT);
...@@ -178,7 +174,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -178,7 +174,7 @@ describe('IntegrationSettingsForm', () => {
}); });
it('should dispatch `receiveJiraIssueTypesSuccess` with the correct payload if ajax request is successful', async () => { it('should dispatch `receiveJiraIssueTypesSuccess` with the correct payload if ajax request is successful', async () => {
const dispatchSpy = mockVuexDispatch(); const dispatchSpy = mockStoreDispatch();
const mockData = ['ISSUE', 'EPIC']; const mockData = ['ISSUE', 'EPIC'];
mockAxios.onPut(integrationSettingsForm.testEndPoint).reply(200, { mockAxios.onPut(integrationSettingsForm.testEndPoint).reply(200, {
error: false, error: false,
...@@ -194,7 +190,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -194,7 +190,7 @@ describe('IntegrationSettingsForm', () => {
it.each(['Custom error message here', undefined])( it.each(['Custom error message here', undefined])(
'should dispatch "receiveJiraIssueTypesError" with a message if the backend responds with error', 'should dispatch "receiveJiraIssueTypesError" with a message if the backend responds with error',
async (responseErrorMessage) => { async (responseErrorMessage) => {
const dispatchSpy = mockVuexDispatch(); const dispatchSpy = mockStoreDispatch();
const expectedErrorMessage = const expectedErrorMessage =
responseErrorMessage || I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE; responseErrorMessage || I18N_FETCH_TEST_SETTINGS_DEFAULT_ERROR_MESSAGE;
...@@ -237,7 +233,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -237,7 +233,7 @@ describe('IntegrationSettingsForm', () => {
}); });
it('should dispatch `setIsSaving` with `false` and not submit form', async () => { it('should dispatch `setIsSaving` with `false` and not submit form', async () => {
const dispatchSpy = mockVuexDispatch(); const dispatchSpy = mockStoreDispatch();
eventHub.$emit(SAVE_INTEGRATION_EVENT); eventHub.$emit(SAVE_INTEGRATION_EVENT);
......
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