Commit e012b4a8 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Replace $emit call with single arg in ProtectedBranchesSelector

See https://gitlab.com/groups/gitlab-org/-/epics/3334
parent 0a36b1ce
...@@ -105,7 +105,7 @@ export default { ...@@ -105,7 +105,7 @@ export default {
this.$emit('submit', { branches, name, url }); this.$emit('submit', { branches, name, url });
} }
}, },
setBranchApiError(hasErrored, error) { setBranchApiError({ hasErrored, error }) {
if (!this.branchesApiFailed && error) { if (!this.branchesApiFailed && error) {
Sentry.captureException(error); Sentry.captureException(error);
} }
......
...@@ -52,11 +52,11 @@ export default { ...@@ -52,11 +52,11 @@ export default {
return Api.projectProtectedBranches(this.projectId, term) return Api.projectProtectedBranches(this.projectId, term)
.then((branches) => { .then((branches) => {
this.$emit('apiError', false); this.$emit('apiError', { hasErrored: false });
this.branches = excludeAnyBranch ? branches : [ANY_BRANCH, ...branches]; this.branches = excludeAnyBranch ? branches : [ANY_BRANCH, ...branches];
}) })
.catch((error) => { .catch((error) => {
this.$emit('apiError', true, error); this.$emit('apiError', { hasErrored: true, error });
this.branches = excludeAnyBranch ? [] : [ANY_BRANCH]; this.branches = excludeAnyBranch ? [] : [ANY_BRANCH];
}) })
.finally(() => { .finally(() => {
......
...@@ -152,7 +152,10 @@ describe('Status checks form', () => { ...@@ -152,7 +152,10 @@ describe('Status checks form', () => {
}); });
it('sends the error to sentry', () => { it('sends the error to sentry', () => {
findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError); findProtectedBranchesSelector().vm.$emit('apiError', {
hasErrored: true,
error: sentryError,
});
expect(Sentry.captureException.mock.calls[0][0]).toStrictEqual(sentryError); expect(Sentry.captureException.mock.calls[0][0]).toStrictEqual(sentryError);
}); });
...@@ -160,22 +163,34 @@ describe('Status checks form', () => { ...@@ -160,22 +163,34 @@ describe('Status checks form', () => {
it('shows the alert', async () => { it('shows the alert', async () => {
expect(findBranchesErrorAlert().exists()).toBe(false); expect(findBranchesErrorAlert().exists()).toBe(false);
await findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError); await findProtectedBranchesSelector().vm.$emit('apiError', {
hasErrored: true,
error: sentryError,
});
expect(findBranchesErrorAlert().exists()).toBe(true); expect(findBranchesErrorAlert().exists()).toBe(true);
}); });
it('hides the alert if the apiError is reset', async () => { it('hides the alert if the apiError is reset', async () => {
await findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError); await findProtectedBranchesSelector().vm.$emit('apiError', {
hasErrored: true,
error: sentryError,
});
expect(findBranchesErrorAlert().exists()).toBe(true); expect(findBranchesErrorAlert().exists()).toBe(true);
await findProtectedBranchesSelector().vm.$emit('apiError', false); await findProtectedBranchesSelector().vm.$emit('apiError', { hasErrored: false });
expect(findBranchesErrorAlert().exists()).toBe(false); expect(findBranchesErrorAlert().exists()).toBe(false);
}); });
it('only calls sentry once while the branches api is failing', () => { it('only calls sentry once while the branches api is failing', () => {
findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError); findProtectedBranchesSelector().vm.$emit('apiError', {
findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError); hasErrored: true,
error: sentryError,
});
findProtectedBranchesSelector().vm.$emit('apiError', {
hasErrored: true,
error: sentryError,
});
expect(Sentry.captureException.mock.calls).toEqual([[sentryError]]); expect(Sentry.captureException.mock.calls).toEqual([[sentryError]]);
}); });
......
...@@ -82,7 +82,7 @@ describe('Protected Branches Selector', () => { ...@@ -82,7 +82,7 @@ describe('Protected Branches Selector', () => {
expect(findDropdown().props('loading')).toBe(true); expect(findDropdown().props('loading')).toBe(true);
await waitForPromises(); await waitForPromises();
expect(wrapper.emitted('apiError')).toStrictEqual([[false]]); expect(wrapper.emitted('apiError')).toStrictEqual([[{ hasErrored: false }]]);
expect(findDropdownItems()).toHaveLength(branchNames().length); expect(findDropdownItems()).toHaveLength(branchNames().length);
expect(findDropdown().props('loading')).toBe(false); expect(findDropdown().props('loading')).toBe(false);
}); });
...@@ -94,7 +94,7 @@ describe('Protected Branches Selector', () => { ...@@ -94,7 +94,7 @@ describe('Protected Branches Selector', () => {
}); });
it('emits the `apiError` event', () => { it('emits the `apiError` event', () => {
expect(wrapper.emitted('apiError')).toStrictEqual([[true, error]]); expect(wrapper.emitted('apiError')).toStrictEqual([[{ hasErrored: true, error }]]);
}); });
it('returns just the any branch dropdown items', () => { it('returns just the any branch dropdown items', () => {
...@@ -119,7 +119,10 @@ describe('Protected Branches Selector', () => { ...@@ -119,7 +119,10 @@ describe('Protected Branches Selector', () => {
await waitForPromises(); await waitForPromises();
expect(Api.projectProtectedBranches).toHaveBeenCalledWith(TEST_PROJECT_ID, term); expect(Api.projectProtectedBranches).toHaveBeenCalledWith(TEST_PROJECT_ID, term);
expect(wrapper.emitted('apiError')).toStrictEqual([[false], [false]]); expect(wrapper.emitted('apiError')).toStrictEqual([
[{ hasErrored: false }],
[{ hasErrored: false }],
]);
expect(findSearch().props('isLoading')).toBe(false); expect(findSearch().props('isLoading')).toBe(false);
}); });
...@@ -146,7 +149,10 @@ describe('Protected Branches Selector', () => { ...@@ -146,7 +149,10 @@ describe('Protected Branches Selector', () => {
}); });
it('emits the `apiError` event', () => { it('emits the `apiError` event', () => {
expect(wrapper.emitted('apiError')).toStrictEqual([[false], [true, error]]); expect(wrapper.emitted('apiError')).toStrictEqual([
[{ hasErrored: false }],
[{ hasErrored: true, error }],
]);
}); });
it('returns no dropdown items', () => { it('returns no dropdown items', () => {
...@@ -163,7 +169,10 @@ describe('Protected Branches Selector', () => { ...@@ -163,7 +169,10 @@ describe('Protected Branches Selector', () => {
}); });
it('emits the `apiError` event', () => { it('emits the `apiError` event', () => {
expect(wrapper.emitted('apiError')).toStrictEqual([[false], [true, error]]); expect(wrapper.emitted('apiError')).toStrictEqual([
[{ hasErrored: false }],
[{ hasErrored: true, error }],
]);
}); });
it('returns just the any branch dropdown item', () => { it('returns just the any branch dropdown item', () => {
......
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