Commit 3657cb4e authored by Phil Hughes's avatar Phil Hughes

Merge branch 'tr-allow-alert-errors-to-reappear' into 'master'

Allow alert error to reappear

See merge request gitlab-org/gitlab!37900
parents fe5abe2f 4ffac0f8
...@@ -168,7 +168,7 @@ export default { ...@@ -168,7 +168,7 @@ export default {
}; };
}, },
error() { error() {
this.errored = true; this.hasError = true;
}, },
}, },
alertsCount: { alertsCount: {
...@@ -187,10 +187,9 @@ export default { ...@@ -187,10 +187,9 @@ export default {
data() { data() {
return { return {
searchTerm: '', searchTerm: '',
errored: false, hasError: false,
errorMessage: '', errorMessage: '',
isAlertDismissed: false, isAlertDismissed: false,
isErrorAlertDismissed: false,
sort: 'STARTED_AT_DESC', sort: 'STARTED_AT_DESC',
statusFilter: [], statusFilter: [],
filteredByStatus: '', filteredByStatus: '',
...@@ -203,16 +202,13 @@ export default { ...@@ -203,16 +202,13 @@ export default {
computed: { computed: {
showNoAlertsMsg() { showNoAlertsMsg() {
return ( return (
!this.errored && !this.hasError &&
!this.loading && !this.loading &&
this.alertsCount?.all === 0 && this.alertsCount?.all === 0 &&
!this.searchTerm && !this.searchTerm &&
!this.isAlertDismissed !this.isAlertDismissed
); );
}, },
showErrorMsg() {
return this.errored && !this.isErrorAlertDismissed;
},
loading() { loading() {
return this.$apollo.queries.alerts.loading; return this.$apollo.queries.alerts.loading;
}, },
...@@ -306,11 +302,11 @@ export default { ...@@ -306,11 +302,11 @@ export default {
}; };
}, },
handleAlertError(errorMessage) { handleAlertError(errorMessage) {
this.errored = true; this.hasError = true;
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
}, },
dismissError() { dismissError() {
this.isErrorAlertDismissed = true; this.hasError = false;
this.errorMessage = ''; this.errorMessage = '';
}, },
}, },
...@@ -332,12 +328,7 @@ export default { ...@@ -332,12 +328,7 @@ export default {
</template> </template>
</gl-sprintf> </gl-sprintf>
</gl-alert> </gl-alert>
<gl-alert <gl-alert v-if="hasError" variant="danger" data-testid="alert-error" @dismiss="dismissError">
v-if="showErrorMsg"
variant="danger"
data-testid="alert-error"
@dismiss="dismissError"
>
<p v-html="errorMessage || $options.i18n.errorMsg"></p> <p v-html="errorMessage || $options.i18n.errorMsg"></p>
</gl-alert> </gl-alert>
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
GlSearchBoxByType, GlSearchBoxByType,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import waitForPromises from 'helpers/wait_for_promises';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import AlertManagementTable from '~/alert_management/components/alert_management_table.vue'; import AlertManagementTable from '~/alert_management/components/alert_management_table.vue';
import { ALERTS_STATUS_TABS, trackAlertStatusUpdateOptions } from '~/alert_management/constants'; import { ALERTS_STATUS_TABS, trackAlertStatusUpdateOptions } from '~/alert_management/constants';
...@@ -44,6 +45,7 @@ describe('AlertManagementTable', () => { ...@@ -44,6 +45,7 @@ describe('AlertManagementTable', () => {
const findPagination = () => wrapper.find(GlPagination); const findPagination = () => wrapper.find(GlPagination);
const findSearch = () => wrapper.find(GlSearchBoxByType); const findSearch = () => wrapper.find(GlSearchBoxByType);
const findIssueFields = () => wrapper.findAll('[data-testid="issueField"]'); const findIssueFields = () => wrapper.findAll('[data-testid="issueField"]');
const findAlertError = () => wrapper.find('[data-testid="alert-error"]');
const alertsCount = { const alertsCount = {
open: 14, open: 14,
triggered: 10, triggered: 10,
...@@ -51,6 +53,11 @@ describe('AlertManagementTable', () => { ...@@ -51,6 +53,11 @@ describe('AlertManagementTable', () => {
resolved: 1, resolved: 1,
all: 16, all: 16,
}; };
const selectFirstStatusOption = () => {
findFirstStatusOption().vm.$emit('click');
return waitForPromises();
};
function mountComponent({ function mountComponent({
props = { props = {
...@@ -138,7 +145,7 @@ describe('AlertManagementTable', () => { ...@@ -138,7 +145,7 @@ describe('AlertManagementTable', () => {
it('error state', () => { it('error state', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { errors: ['error'] }, alertsCount: null, errored: true }, data: { alerts: { errors: ['error'] }, alertsCount: null, hasError: true },
loading: false, loading: false,
}); });
expect(findAlertsTable().exists()).toBe(true); expect(findAlertsTable().exists()).toBe(true);
...@@ -155,7 +162,7 @@ describe('AlertManagementTable', () => { ...@@ -155,7 +162,7 @@ describe('AlertManagementTable', () => {
it('empty state', () => { it('empty state', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: [], pageInfo: {} }, alertsCount: { all: 0 }, errored: false }, data: { alerts: { list: [], pageInfo: {} }, alertsCount: { all: 0 }, hasError: false },
loading: false, loading: false,
}); });
expect(findAlertsTable().exists()).toBe(true); expect(findAlertsTable().exists()).toBe(true);
...@@ -172,7 +179,7 @@ describe('AlertManagementTable', () => { ...@@ -172,7 +179,7 @@ describe('AlertManagementTable', () => {
it('has data state', () => { it('has data state', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
expect(findLoader().exists()).toBe(false); expect(findLoader().exists()).toBe(false);
...@@ -188,7 +195,7 @@ describe('AlertManagementTable', () => { ...@@ -188,7 +195,7 @@ describe('AlertManagementTable', () => {
it('displays status dropdown', () => { it('displays status dropdown', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
expect(findStatusDropdown().exists()).toBe(true); expect(findStatusDropdown().exists()).toBe(true);
...@@ -197,7 +204,7 @@ describe('AlertManagementTable', () => { ...@@ -197,7 +204,7 @@ describe('AlertManagementTable', () => {
it('does not display a dropdown status header', () => { it('does not display a dropdown status header', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
expect(findStatusDropdown().contains('.dropdown-title')).toBe(false); expect(findStatusDropdown().contains('.dropdown-title')).toBe(false);
...@@ -206,7 +213,7 @@ describe('AlertManagementTable', () => { ...@@ -206,7 +213,7 @@ describe('AlertManagementTable', () => {
it('shows correct severity icons', () => { it('shows correct severity icons', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -223,7 +230,7 @@ describe('AlertManagementTable', () => { ...@@ -223,7 +230,7 @@ describe('AlertManagementTable', () => {
it('renders severity text', () => { it('renders severity text', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -237,7 +244,7 @@ describe('AlertManagementTable', () => { ...@@ -237,7 +244,7 @@ describe('AlertManagementTable', () => {
it('renders Unassigned when no assignee(s) present', () => { it('renders Unassigned when no assignee(s) present', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -251,7 +258,7 @@ describe('AlertManagementTable', () => { ...@@ -251,7 +258,7 @@ describe('AlertManagementTable', () => {
it('renders username(s) when assignee(s) present', () => { it('renders username(s) when assignee(s) present', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -265,7 +272,7 @@ describe('AlertManagementTable', () => { ...@@ -265,7 +272,7 @@ describe('AlertManagementTable', () => {
it('navigates to the detail page when alert row is clicked', () => { it('navigates to the detail page when alert row is clicked', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -279,7 +286,7 @@ describe('AlertManagementTable', () => { ...@@ -279,7 +286,7 @@ describe('AlertManagementTable', () => {
beforeEach(() => { beforeEach(() => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
}); });
...@@ -323,7 +330,7 @@ describe('AlertManagementTable', () => { ...@@ -323,7 +330,7 @@ describe('AlertManagementTable', () => {
], ],
}, },
alertsCount, alertsCount,
errored: false, hasError: false,
}, },
loading: false, loading: false,
}); });
...@@ -343,7 +350,7 @@ describe('AlertManagementTable', () => { ...@@ -343,7 +350,7 @@ describe('AlertManagementTable', () => {
}, },
], ],
alertsCount, alertsCount,
errored: false, hasError: false,
}, },
loading: false, loading: false,
}); });
...@@ -358,7 +365,7 @@ describe('AlertManagementTable', () => { ...@@ -358,7 +365,7 @@ describe('AlertManagementTable', () => {
it('should highlight the row when alert is new', () => { it('should highlight the row when alert is new', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: [newAlert] }, alertsCount, errored: false }, data: { alerts: { list: [newAlert] }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -372,7 +379,7 @@ describe('AlertManagementTable', () => { ...@@ -372,7 +379,7 @@ describe('AlertManagementTable', () => {
it('should not highlight the row when alert is not new', () => { it('should not highlight the row when alert is not new', () => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: [oldAlert] }, alertsCount, errored: false }, data: { alerts: { list: [oldAlert] }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
...@@ -392,7 +399,7 @@ describe('AlertManagementTable', () => { ...@@ -392,7 +399,7 @@ describe('AlertManagementTable', () => {
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { data: {
alerts: { list: mockAlerts }, alerts: { list: mockAlerts },
errored: false, hasError: false,
sort: 'STARTED_AT_DESC', sort: 'STARTED_AT_DESC',
alertsCount, alertsCount,
}, },
...@@ -429,7 +436,7 @@ describe('AlertManagementTable', () => { ...@@ -429,7 +436,7 @@ describe('AlertManagementTable', () => {
beforeEach(() => { beforeEach(() => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
}); });
...@@ -448,19 +455,36 @@ describe('AlertManagementTable', () => { ...@@ -448,19 +455,36 @@ describe('AlertManagementTable', () => {
}); });
}); });
it('shows an error when request fails', () => { describe('when a request fails', () => {
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockReturnValue(Promise.reject(new Error())); beforeEach(() => {
findFirstStatusOption().vm.$emit('click'); jest.spyOn(wrapper.vm.$apollo, 'mutate').mockReturnValue(Promise.reject(new Error()));
wrapper.setData({
errored: true,
}); });
return wrapper.vm.$nextTick(() => { it('shows an error', async () => {
expect(wrapper.find('[data-testid="alert-error"]').exists()).toBe(true); await selectFirstStatusOption();
expect(findAlertError().text()).toContain(
'There was an error while updating the status of the alert.',
);
});
it('shows an error when triggered a second time', async () => {
await selectFirstStatusOption();
wrapper.find(GlAlert).vm.$emit('dismiss');
await wrapper.vm.$nextTick();
// Assert that the error has been dismissed in the setup
expect(findAlertError().exists()).toBe(false);
await selectFirstStatusOption();
expect(findAlertError().exists()).toBe(true);
}); });
}); });
it('shows an error when response includes HTML errors', () => { it('shows an error when response includes HTML errors', async () => {
const mockUpdatedMutationErrorResult = { const mockUpdatedMutationErrorResult = {
data: { data: {
updateAlertStatus: { updateAlertStatus: {
...@@ -474,13 +498,11 @@ describe('AlertManagementTable', () => { ...@@ -474,13 +498,11 @@ describe('AlertManagementTable', () => {
}; };
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue(mockUpdatedMutationErrorResult); jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue(mockUpdatedMutationErrorResult);
findFirstStatusOption().vm.$emit('click');
wrapper.setData({ errored: true });
return wrapper.vm.$nextTick(() => { await selectFirstStatusOption();
expect(wrapper.contains('[data-testid="alert-error"]')).toBe(true);
expect(wrapper.contains('[data-testid="htmlError"]')).toBe(true); expect(findAlertError().exists()).toBe(true);
}); expect(findAlertError().contains('[data-testid="htmlError"]')).toBe(true);
}); });
}); });
...@@ -510,7 +532,7 @@ describe('AlertManagementTable', () => { ...@@ -510,7 +532,7 @@ describe('AlertManagementTable', () => {
beforeEach(() => { beforeEach(() => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts, pageInfo: {} }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts, pageInfo: {} }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
}); });
...@@ -570,7 +592,7 @@ describe('AlertManagementTable', () => { ...@@ -570,7 +592,7 @@ describe('AlertManagementTable', () => {
beforeEach(() => { beforeEach(() => {
mountComponent({ mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: mockAlerts }, alertsCount, errored: false }, data: { alerts: { list: mockAlerts }, alertsCount, hasError: false },
loading: false, loading: false,
}); });
}); });
......
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