Commit 17da3034 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'vs/replace-emit-multiarg-in-protected-branches-selector' into 'master'

Replace $emit call with single arg in ProtectedBranchesSelector

See merge request gitlab-org/gitlab!64613
parents d6ab412b e012b4a8
......@@ -105,7 +105,7 @@ export default {
this.$emit('submit', { branches, name, url });
}
},
setBranchApiError(hasErrored, error) {
setBranchApiError({ hasErrored, error }) {
if (!this.branchesApiFailed && error) {
Sentry.captureException(error);
}
......
......@@ -52,11 +52,11 @@ export default {
return Api.projectProtectedBranches(this.projectId, term)
.then((branches) => {
this.$emit('apiError', false);
this.$emit('apiError', { hasErrored: false });
this.branches = excludeAnyBranch ? branches : [ANY_BRANCH, ...branches];
})
.catch((error) => {
this.$emit('apiError', true, error);
this.$emit('apiError', { hasErrored: true, error });
this.branches = excludeAnyBranch ? [] : [ANY_BRANCH];
})
.finally(() => {
......
......@@ -152,7 +152,10 @@ describe('Status checks form', () => {
});
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);
});
......@@ -160,22 +163,34 @@ describe('Status checks form', () => {
it('shows the alert', async () => {
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);
});
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);
await findProtectedBranchesSelector().vm.$emit('apiError', false);
await findProtectedBranchesSelector().vm.$emit('apiError', { hasErrored: false });
expect(findBranchesErrorAlert().exists()).toBe(false);
});
it('only calls sentry once while the branches api is failing', () => {
findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError);
findProtectedBranchesSelector().vm.$emit('apiError', true, sentryError);
findProtectedBranchesSelector().vm.$emit('apiError', {
hasErrored: true,
error: sentryError,
});
findProtectedBranchesSelector().vm.$emit('apiError', {
hasErrored: true,
error: sentryError,
});
expect(Sentry.captureException.mock.calls).toEqual([[sentryError]]);
});
......
......@@ -82,7 +82,7 @@ describe('Protected Branches Selector', () => {
expect(findDropdown().props('loading')).toBe(true);
await waitForPromises();
expect(wrapper.emitted('apiError')).toStrictEqual([[false]]);
expect(wrapper.emitted('apiError')).toStrictEqual([[{ hasErrored: false }]]);
expect(findDropdownItems()).toHaveLength(branchNames().length);
expect(findDropdown().props('loading')).toBe(false);
});
......@@ -94,7 +94,7 @@ describe('Protected Branches Selector', () => {
});
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', () => {
......@@ -119,7 +119,10 @@ describe('Protected Branches Selector', () => {
await waitForPromises();
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);
});
......@@ -146,7 +149,10 @@ describe('Protected Branches Selector', () => {
});
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', () => {
......@@ -163,7 +169,10 @@ describe('Protected Branches Selector', () => {
});
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', () => {
......
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