Commit 14123f51 authored by Tom Quirk's avatar Tom Quirk

Use GlAlert for integrations table errors

Changelog: fixed
parent cbc1b00b
<script> <script>
import { GlLink, GlLoadingIcon, GlPagination, GlTable } from '@gitlab/ui'; import { GlLink, GlLoadingIcon, GlPagination, GlTable, GlAlert } from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
import { DEFAULT_PER_PAGE } from '~/api'; import { DEFAULT_PER_PAGE } from '~/api';
import createFlash from '~/flash';
import { fetchOverrides } from '~/integrations/overrides/api'; import { fetchOverrides } from '~/integrations/overrides/api';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
import { truncateNamespace } from '~/lib/utils/text_utility'; import { truncateNamespace } from '~/lib/utils/text_utility';
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
GlLoadingIcon, GlLoadingIcon,
GlPagination, GlPagination,
GlTable, GlTable,
GlAlert,
ProjectAvatar, ProjectAvatar,
}, },
props: { props: {
...@@ -36,6 +37,7 @@ export default { ...@@ -36,6 +37,7 @@ export default {
overrides: [], overrides: [],
page: 1, page: 1,
totalItems: 0, totalItems: 0,
errorMessage: null,
}; };
}, },
computed: { computed: {
...@@ -49,6 +51,7 @@ export default { ...@@ -49,6 +51,7 @@ export default {
methods: { methods: {
loadOverrides(page = this.page) { loadOverrides(page = this.page) {
this.isLoading = true; this.isLoading = true;
this.errorMessage = null;
fetchOverrides(this.overridesPath, { fetchOverrides(this.overridesPath, {
page, page,
...@@ -61,11 +64,9 @@ export default { ...@@ -61,11 +64,9 @@ export default {
this.overrides = data; this.overrides = data;
}) })
.catch((error) => { .catch((error) => {
createFlash({ this.errorMessage = this.$options.i18n.defaultErrorMessage;
message: this.$options.i18n.defaultErrorMessage,
error, Sentry.captureException(error);
captureError: true,
});
}) })
.finally(() => { .finally(() => {
this.isLoading = false; this.isLoading = false;
...@@ -85,7 +86,11 @@ export default { ...@@ -85,7 +86,11 @@ export default {
<template> <template>
<div> <div>
<gl-alert v-if="errorMessage" variant="danger" :dismissible="false">
{{ errorMessage }}
</gl-alert>
<gl-table <gl-table
v-else
:items="overrides" :items="overrides"
:fields="$options.fields" :fields="$options.fields"
:busy="isLoading" :busy="isLoading"
......
import { GlTable, GlLink, GlPagination } from '@gitlab/ui'; import { GlTable, GlLink, GlPagination, GlAlert } from '@gitlab/ui';
import * as Sentry from '@sentry/browser';
import { shallowMount, mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { DEFAULT_PER_PAGE } from '~/api'; import { DEFAULT_PER_PAGE } from '~/api';
import createFlash from '~/flash';
import IntegrationOverrides from '~/integrations/overrides/components/integration_overrides.vue'; import IntegrationOverrides from '~/integrations/overrides/components/integration_overrides.vue';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import httpStatus from '~/lib/utils/http_status'; import httpStatus from '~/lib/utils/http_status';
import ProjectAvatar from '~/vue_shared/components/project_avatar.vue'; import ProjectAvatar from '~/vue_shared/components/project_avatar.vue';
jest.mock('~/flash');
const mockOverrides = Array(DEFAULT_PER_PAGE * 3) const mockOverrides = Array(DEFAULT_PER_PAGE * 3)
.fill(1) .fill(1)
.map((_, index) => ({ .map((_, index) => ({
...@@ -62,6 +60,7 @@ describe('IntegrationOverrides', () => { ...@@ -62,6 +60,7 @@ describe('IntegrationOverrides', () => {
text: link.text(), text: link.text(),
}; };
}); });
const findAlert = () => wrapper.findComponent(GlAlert);
describe('while loading', () => { describe('while loading', () => {
it('sets GlTable `busy` attribute to `true`', () => { it('sets GlTable `busy` attribute to `true`', () => {
...@@ -104,18 +103,26 @@ describe('IntegrationOverrides', () => { ...@@ -104,18 +103,26 @@ describe('IntegrationOverrides', () => {
describe('when request fails', () => { describe('when request fails', () => {
beforeEach(async () => { beforeEach(async () => {
jest.spyOn(Sentry, 'captureException');
mockAxios.onGet(defaultProps.overridesPath).reply(httpStatus.INTERNAL_SERVER_ERROR); mockAxios.onGet(defaultProps.overridesPath).reply(httpStatus.INTERNAL_SERVER_ERROR);
createComponent(); createComponent();
await waitForPromises(); await waitForPromises();
}); });
it('calls createFlash', () => { it('displays error alert', () => {
expect(createFlash).toHaveBeenCalledTimes(1); const alert = findAlert();
expect(createFlash).toHaveBeenCalledWith({ expect(alert.exists()).toBe(true);
message: IntegrationOverrides.i18n.defaultErrorMessage, expect(alert.text()).toBe(IntegrationOverrides.i18n.defaultErrorMessage);
captureError: true, });
error: expect.any(Error),
it('hides overrides table', () => {
const table = findGlTable();
expect(table.exists()).toBe(false);
}); });
it('captures exception in Sentry', () => {
expect(Sentry.captureException).toHaveBeenCalledWith(expect.any(Error));
}); });
}); });
......
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