Commit 3a6b6f16 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '296717-move-alert-details-to-shared' into 'master'

Move alert_details components to vue_shared

See merge request gitlab-org/gitlab!51508
parents d41191bb 0a3835db
...@@ -23,14 +23,10 @@ import { ...@@ -23,14 +23,10 @@ import {
} from '~/vue_shared/components/paginated_table_with_search_and_tabs/constants'; } from '~/vue_shared/components/paginated_table_with_search_and_tabs/constants';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
import { convertToSnakeCase } from '~/lib/utils/text_utility'; import { convertToSnakeCase } from '~/lib/utils/text_utility';
import AlertStatus from '~/vue_shared/alert_details/components/alert_status.vue';
import getAlertsQuery from '~/graphql_shared/queries/get_alerts.query.graphql'; import getAlertsQuery from '~/graphql_shared/queries/get_alerts.query.graphql';
import getAlertsCountByStatus from '../graphql/queries/get_count_by_status.query.graphql'; import getAlertsCountByStatus from '../graphql/queries/get_count_by_status.query.graphql';
import { import { ALERTS_STATUS_TABS, SEVERITY_LEVELS, trackAlertListViewsOptions } from '../constants';
ALERTS_STATUS_TABS,
ALERTS_SEVERITY_LABELS,
trackAlertListViewsOptions,
} from '../constants';
import AlertStatus from './alert_status.vue';
const TH_TEST_ID = { 'data-testid': 'alert-management-severity-sort' }; const TH_TEST_ID = { 'data-testid': 'alert-management-severity-sort' };
...@@ -96,7 +92,7 @@ export default { ...@@ -96,7 +92,7 @@ export default {
sortable: true, sortable: true,
}, },
], ],
severityLabels: ALERTS_SEVERITY_LABELS, severityLabels: SEVERITY_LEVELS,
statusTabs: ALERTS_STATUS_TABS, statusTabs: ALERTS_STATUS_TABS,
components: { components: {
GlAlert, GlAlert,
......
import { s__ } from '~/locale'; import { s__ } from '~/locale';
export const ALERTS_SEVERITY_LABELS = { export const SEVERITY_LEVELS = {
CRITICAL: s__('AlertManagement|Critical'), CRITICAL: s__('severity|Critical'),
HIGH: s__('AlertManagement|High'), HIGH: s__('severity|High'),
MEDIUM: s__('AlertManagement|Medium'), MEDIUM: s__('severity|Medium'),
LOW: s__('AlertManagement|Low'), LOW: s__('severity|Low'),
INFO: s__('AlertManagement|Info'), INFO: s__('severity|Info'),
UNKNOWN: s__('AlertManagement|Unknown'), UNKNOWN: s__('severity|Unknown'),
}; };
export const ALERTS_STATUS_TABS = [ export const ALERTS_STATUS_TABS = [
...@@ -46,20 +46,3 @@ export const trackAlertListViewsOptions = { ...@@ -46,20 +46,3 @@ export const trackAlertListViewsOptions = {
category: 'Alert Management', category: 'Alert Management',
action: 'view_alerts_list', action: 'view_alerts_list',
}; };
/**
* Tracks snowplow event when user views alert details
*/
export const trackAlertsDetailsViewsOptions = {
category: 'Alert Management',
action: 'view_alert_details',
};
/**
* Tracks snowplow event when alert status is updated
*/
export const trackAlertStatusUpdateOptions = {
category: 'Alert Management',
action: 'update_alert_status',
label: 'Status',
};
...@@ -3,6 +3,7 @@ import VueApollo from 'vue-apollo'; ...@@ -3,6 +3,7 @@ import VueApollo from 'vue-apollo';
import { defaultDataIdFromObject } from 'apollo-cache-inmemory'; import { defaultDataIdFromObject } from 'apollo-cache-inmemory';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import { PAGE_CONFIG } from '~/vue_shared/alert_details/constants';
import AlertManagementList from './components/alert_management_list_wrapper.vue'; import AlertManagementList from './components/alert_management_list_wrapper.vue';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -59,6 +60,7 @@ export default () => { ...@@ -59,6 +60,7 @@ export default () => {
populatingAlertsHelpUrl, populatingAlertsHelpUrl,
emptyAlertSvgPath, emptyAlertSvgPath,
alertManagementEnabled: parseBoolean(alertManagementEnabled), alertManagementEnabled: parseBoolean(alertManagementEnabled),
trackAlertStatusUpdateOptions: PAGE_CONFIG.OPERATIONS.TRACK_ALERT_STATUS_UPDATE_OPTIONS,
userCanEnableAlertManagement: parseBoolean(userCanEnableAlertManagement), userCanEnableAlertManagement: parseBoolean(userCanEnableAlertManagement),
}, },
apolloProvider, apolloProvider,
......
#import "~/graphql_shared/fragments/author.fragment.graphql" #import "./author.fragment.graphql"
fragment AlertNote on Note { fragment AlertNote on Note {
id id
......
#import "~/graphql_shared/fragments/alert_note.fragment.graphql" #import "../fragments/alert_note.fragment.graphql"
mutation updateAlertStatus($projectPath: ID!, $status: AlertManagementStatus!, $iid: String!) { mutation updateAlertStatus($projectPath: ID!, $status: AlertManagementStatus!, $iid: String!) {
updateAlertStatus(input: { iid: $iid, status: $status, projectPath: $projectPath }) { updateAlertStatus(input: { iid: $iid, status: $status, projectPath: $projectPath }) {
......
import AlertDetails from '~/alert_management/details'; import AlertDetails from '~/vue_shared/alert_details';
AlertDetails('#js-alert_details'); AlertDetails('#js-alert_details');
...@@ -21,11 +21,11 @@ import { visitUrl, joinPaths } from '~/lib/utils/url_utility'; ...@@ -21,11 +21,11 @@ import { visitUrl, joinPaths } from '~/lib/utils/url_utility';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { toggleContainerClasses } from '~/lib/utils/dom_utils'; import { toggleContainerClasses } from '~/lib/utils/dom_utils';
import AlertDetailsTable from '~/vue_shared/components/alert_details_table.vue'; import AlertDetailsTable from '~/vue_shared/components/alert_details_table.vue';
import alertQuery from '../graphql/queries/details.query.graphql'; import alertQuery from '../graphql/queries/alert_details.query.graphql';
import sidebarStatusQuery from '../graphql/queries/sidebar_status.query.graphql'; import sidebarStatusQuery from '../graphql/queries/alert_sidebar_status.query.graphql';
import { ALERTS_SEVERITY_LABELS, trackAlertsDetailsViewsOptions } from '../constants'; import { SEVERITY_LEVELS } from '../constants';
import createIssueMutation from '../graphql/mutations/create_issue_from_alert.mutation.graphql'; import createIssueMutation from '../graphql/mutations/alert_issue_create.mutation.graphql';
import toggleSidebarStatusMutation from '../graphql/mutations/toggle_sidebar_status.mutation.graphql'; import toggleSidebarStatusMutation from '../graphql/mutations/alert_sidebar_status.mutation.graphql';
import SystemNote from './system_notes/system_note.vue'; import SystemNote from './system_notes/system_note.vue';
import AlertSidebar from './alert_sidebar.vue'; import AlertSidebar from './alert_sidebar.vue';
import AlertMetrics from './alert_metrics.vue'; import AlertMetrics from './alert_metrics.vue';
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
directives: { directives: {
SafeHtml: GlSafeHtmlDirective, SafeHtml: GlSafeHtmlDirective,
}, },
severityLabels: ALERTS_SEVERITY_LABELS, severityLabels: SEVERITY_LEVELS,
tabsConfig: [ tabsConfig: [
{ {
id: 'overview', id: 'overview',
...@@ -89,6 +89,9 @@ export default { ...@@ -89,6 +89,9 @@ export default {
projectIssuesPath: { projectIssuesPath: {
default: '', default: '',
}, },
trackAlertsDetailsViewsOptions: {
default: null,
},
}, },
apollo: { apollo: {
alert: { alert: {
...@@ -155,7 +158,9 @@ export default { ...@@ -155,7 +158,9 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.trackAlertsDetailsViewsOptions) {
this.trackPageViews(); this.trackPageViews();
}
toggleContainerClasses(containerEl, { toggleContainerClasses(containerEl, {
'issuable-bulk-update-sidebar': true, 'issuable-bulk-update-sidebar': true,
'right-sidebar-expanded': true, 'right-sidebar-expanded': true,
...@@ -217,7 +222,7 @@ export default { ...@@ -217,7 +222,7 @@ export default {
return joinPaths(this.projectIssuesPath, issueId); return joinPaths(this.projectIssuesPath, issueId);
}, },
trackPageViews() { trackPageViews() {
const { category, action } = trackAlertsDetailsViewsOptions; const { category, action } = this.trackAlertsDetailsViewsOptions;
Tracking.event(category, action); Tracking.event(category, action);
}, },
}, },
......
<script> <script>
import sidebarStatusQuery from '../graphql/queries/sidebar_status.query.graphql'; import sidebarStatusQuery from '../graphql/queries/alert_sidebar_status.query.graphql';
import SidebarHeader from './sidebar/sidebar_header.vue'; import SidebarHeader from './sidebar/sidebar_header.vue';
import SidebarTodo from './sidebar/sidebar_todo.vue'; import SidebarTodo from './sidebar/sidebar_todo.vue';
import SidebarStatus from './sidebar/sidebar_status.vue'; import SidebarStatus from './sidebar/sidebar_status.vue';
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import updateAlertStatusMutation from '~/graphql_shared/mutations/update_alert_status.mutation.graphql'; import updateAlertStatusMutation from '~/graphql_shared/mutations/alert_status_update.mutation.graphql';
import { trackAlertStatusUpdateOptions } from '../constants';
export default { export default {
i18n: { i18n: {
...@@ -21,6 +20,11 @@ export default { ...@@ -21,6 +20,11 @@ export default {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
}, },
inject: {
trackAlertStatusUpdateOptions: {
default: null,
},
},
props: { props: {
projectPath: { projectPath: {
type: String, type: String,
...@@ -58,7 +62,9 @@ export default { ...@@ -58,7 +62,9 @@ export default {
}, },
}) })
.then((resp) => { .then((resp) => {
if (this.trackAlertStatusUpdateOptions) {
this.trackStatusUpdate(status); this.trackStatusUpdate(status);
}
const errors = resp.data?.updateAlertStatus?.errors || []; const errors = resp.data?.updateAlertStatus?.errors || [];
if (errors[0]) { if (errors[0]) {
...@@ -81,7 +87,7 @@ export default { ...@@ -81,7 +87,7 @@ export default {
}); });
}, },
trackStatusUpdate(status) { trackStatusUpdate(status) {
const { category, action, label } = trackAlertStatusUpdateOptions; const { category, action, label } = this.trackAlertStatusUpdateOptions;
Tracking.event(category, action, { label, property: status }); Tracking.event(category, action, { label, property: status });
}, },
}, },
......
...@@ -4,7 +4,7 @@ import { s__ } from '~/locale'; ...@@ -4,7 +4,7 @@ import { s__ } from '~/locale';
import Todo from '~/sidebar/components/todo_toggle/todo.vue'; import Todo from '~/sidebar/components/todo_toggle/todo.vue';
import todoMarkDoneMutation from '~/graphql_shared/mutations/todo_mark_done.mutation.graphql'; import todoMarkDoneMutation from '~/graphql_shared/mutations/todo_mark_done.mutation.graphql';
import createAlertTodoMutation from '../../graphql/mutations/alert_todo_create.mutation.graphql'; import createAlertTodoMutation from '../../graphql/mutations/alert_todo_create.mutation.graphql';
import alertQuery from '../../graphql/queries/details.query.graphql'; import alertQuery from '../../graphql/queries/alert_details.query.graphql';
export default { export default {
i18n: { i18n: {
......
import { s__ } from '~/locale';
export const SEVERITY_LEVELS = {
CRITICAL: s__('severity|Critical'),
HIGH: s__('severity|High'),
MEDIUM: s__('severity|Medium'),
LOW: s__('severity|Low'),
INFO: s__('severity|Info'),
UNKNOWN: s__('severity|Unknown'),
};
export const DEFAULT_PAGE = 'OPERATIONS';
/* eslint-disable @gitlab/require-i18n-strings */
export const PAGE_CONFIG = {
OPERATIONS: {
// Tracks snowplow event when user views alert details
TRACK_ALERTS_DETAILS_VIEWS_OPTIONS: {
category: 'Alert Management',
action: 'view_alert_details',
},
// Tracks snowplow event when alert status is updated
TRACK_ALERT_STATUS_UPDATE_OPTIONS: {
category: 'Alert Management',
action: 'update_alert_status',
label: 'Status',
},
},
};
#import "../fragments/detail_item.fragment.graphql" #import "../fragments/alert_detail_item.fragment.graphql"
mutation alertTodoCreate($projectPath: ID!, $iid: String!) { mutation alertTodoCreate($projectPath: ID!, $iid: String!) {
alertTodoCreate(input: { iid: $iid, projectPath: $projectPath }) { alertTodoCreate(input: { iid: $iid, projectPath: $projectPath }) {
......
#import "../fragments/detail_item.fragment.graphql" #import "../fragments/alert_detail_item.fragment.graphql"
query alertDetails($fullPath: ID!, $alertId: String) { query alertDetails($fullPath: ID!, $alertId: String) {
project(fullPath: $fullPath) { project(fullPath: $fullPath) {
......
...@@ -4,14 +4,15 @@ import Vue from 'vue'; ...@@ -4,14 +4,15 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import AlertDetails from './components/alert_details.vue'; import AlertDetails from './components/alert_details.vue';
import sidebarStatusQuery from './graphql/queries/sidebar_status.query.graphql'; import sidebarStatusQuery from './graphql/queries/alert_sidebar_status.query.graphql';
import createRouter from './router'; import createRouter from './router';
import { DEFAULT_PAGE, PAGE_CONFIG } from './constants';
Vue.use(VueApollo); Vue.use(VueApollo);
export default (selector) => { export default (selector) => {
const domEl = document.querySelector(selector); const domEl = document.querySelector(selector);
const { alertId, projectPath, projectIssuesPath, projectId } = domEl.dataset; const { alertId, projectPath, projectIssuesPath, projectId, page = DEFAULT_PAGE } = domEl.dataset;
const router = createRouter(); const router = createRouter();
const resolvers = { const resolvers = {
...@@ -48,18 +49,28 @@ export default (selector) => { ...@@ -48,18 +49,28 @@ export default (selector) => {
}, },
}); });
const provide = {
projectPath,
alertId,
projectIssuesPath,
projectId,
};
if (page === DEFAULT_PAGE) {
const { TRACK_ALERTS_DETAILS_VIEWS_OPTIONS, TRACK_ALERT_STATUS_UPDATE_OPTIONS } = PAGE_CONFIG[
page
];
provide.trackAlertsDetailsViewsOptions = TRACK_ALERTS_DETAILS_VIEWS_OPTIONS;
provide.trackAlertStatusUpdateOptions = TRACK_ALERT_STATUS_UPDATE_OPTIONS;
}
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el: selector, el: selector,
components: { components: {
AlertDetails, AlertDetails,
}, },
provide: { provide,
projectPath,
alertId,
projectIssuesPath,
projectId,
},
apolloProvider, apolloProvider,
router, router,
render(createElement) { render(createElement) {
......
<script> <script>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import updateAlertStatusMutation from '~/graphql_shared/mutations/update_alert_status.mutation.graphql'; import updateAlertStatusMutation from '~/graphql_shared/mutations/alert_status_update.mutation.graphql';
import { MESSAGES, STATUSES } from './constants'; import { MESSAGES, STATUSES } from './constants';
export default { export default {
......
...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils';
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import AlertStatus from 'ee/threat_monitoring/components/alerts/alert_status.vue'; import AlertStatus from 'ee/threat_monitoring/components/alerts/alert_status.vue';
import updateAlertStatusMutation from '~/graphql_shared/mutations/update_alert_status.mutation.graphql'; import updateAlertStatusMutation from '~/graphql_shared/mutations/alert_status_update.mutation.graphql';
import { mockAlerts } from '../../mock_data'; import { mockAlerts } from '../../mock_data';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
......
...@@ -2483,9 +2483,6 @@ msgstr "" ...@@ -2483,9 +2483,6 @@ msgstr ""
msgid "AlertManagement|Create incident" msgid "AlertManagement|Create incident"
msgstr "" msgstr ""
msgid "AlertManagement|Critical"
msgstr ""
msgid "AlertManagement|Display alerts from all your monitoring tools directly within GitLab. Streamline the investigation of your alerts and the escalation of alerts to incidents." msgid "AlertManagement|Display alerts from all your monitoring tools directly within GitLab. Streamline the investigation of your alerts and the escalation of alerts to incidents."
msgstr "" msgstr ""
...@@ -2498,24 +2495,12 @@ msgstr "" ...@@ -2498,24 +2495,12 @@ msgstr ""
msgid "AlertManagement|Events" msgid "AlertManagement|Events"
msgstr "" msgstr ""
msgid "AlertManagement|High"
msgstr ""
msgid "AlertManagement|Incident" msgid "AlertManagement|Incident"
msgstr "" msgstr ""
msgid "AlertManagement|Info"
msgstr ""
msgid "AlertManagement|Key" msgid "AlertManagement|Key"
msgstr "" msgstr ""
msgid "AlertManagement|Low"
msgstr ""
msgid "AlertManagement|Medium"
msgstr ""
msgid "AlertManagement|Metrics" msgid "AlertManagement|Metrics"
msgstr "" msgstr ""
...@@ -2597,9 +2582,6 @@ msgstr "" ...@@ -2597,9 +2582,6 @@ msgstr ""
msgid "AlertManagement|Triggered" msgid "AlertManagement|Triggered"
msgstr "" msgstr ""
msgid "AlertManagement|Unknown"
msgstr ""
msgid "AlertManagement|Value" msgid "AlertManagement|Value"
msgstr "" msgstr ""
......
...@@ -2,11 +2,11 @@ import { mount } from '@vue/test-utils'; ...@@ -2,11 +2,11 @@ import { mount } from '@vue/test-utils';
import { GlTable, GlAlert, GlLoadingIcon, GlDropdown, GlIcon, GlAvatar } from '@gitlab/ui'; import { GlTable, GlAlert, GlLoadingIcon, GlDropdown, GlIcon, GlAvatar } from '@gitlab/ui';
import axios from 'axios'; import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import mockAlerts from 'jest/vue_shared/alert_details/mocks/alerts.json';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
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 FilteredSearchBar from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue'; import FilteredSearchBar from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue';
import mockAlerts from '../mocks/alerts.json';
import defaultProvideValues from '../mocks/alerts_provide_config.json'; import defaultProvideValues from '../mocks/alerts_provide_config.json';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
......
...@@ -4,17 +4,14 @@ import axios from 'axios'; ...@@ -4,17 +4,14 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import AlertDetails from '~/alert_management/components/alert_details.vue'; import AlertDetails from '~/vue_shared/alert_details/components/alert_details.vue';
import AlertSummaryRow from '~/alert_management/components/alert_summary_row.vue'; import AlertSummaryRow from '~/vue_shared/alert_details/components/alert_summary_row.vue';
import { import { SEVERITY_LEVELS } from '~/vue_shared/alert_details/constants';
ALERTS_SEVERITY_LABELS, import createIssueMutation from '~/vue_shared/alert_details/graphql/mutations/alert_issue_create.mutation.graphql';
trackAlertsDetailsViewsOptions,
} from '~/alert_management/constants';
import createIssueMutation from '~/alert_management/graphql/mutations/create_issue_from_alert.mutation.graphql';
import { joinPaths } from '~/lib/utils/url_utility'; import { joinPaths } from '~/lib/utils/url_utility';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import AlertDetailsTable from '~/vue_shared/components/alert_details_table.vue'; import AlertDetailsTable from '~/vue_shared/components/alert_details_table.vue';
import mockAlerts from '../mocks/alerts.json'; import mockAlerts from './mocks/alerts.json';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
const environmentName = 'Production'; const environmentName = 'Production';
...@@ -29,7 +26,13 @@ describe('AlertDetails', () => { ...@@ -29,7 +26,13 @@ describe('AlertDetails', () => {
const projectId = '1'; const projectId = '1';
const $router = { replace: jest.fn() }; const $router = { replace: jest.fn() };
function mountComponent({ data, loading = false, mountMethod = shallowMount, stubs = {} } = {}) { function mountComponent({
data,
loading = false,
mountMethod = shallowMount,
provide = {},
stubs = {},
} = {}) {
wrapper = extendedWrapper( wrapper = extendedWrapper(
mountMethod(AlertDetails, { mountMethod(AlertDetails, {
provide: { provide: {
...@@ -37,6 +40,7 @@ describe('AlertDetails', () => { ...@@ -37,6 +40,7 @@ describe('AlertDetails', () => {
projectPath, projectPath,
projectIssuesPath, projectIssuesPath,
projectId, projectId,
...provide,
}, },
data() { data() {
return { return {
...@@ -112,9 +116,7 @@ describe('AlertDetails', () => { ...@@ -112,9 +116,7 @@ describe('AlertDetails', () => {
}); });
it('renders severity', () => { it('renders severity', () => {
expect(wrapper.findByTestId('severity').text()).toBe( expect(wrapper.findByTestId('severity').text()).toBe(SEVERITY_LEVELS[mockAlert.severity]);
ALERTS_SEVERITY_LABELS[mockAlert.severity],
);
}); });
it('renders a title', () => { it('renders a title', () => {
...@@ -321,16 +323,27 @@ describe('AlertDetails', () => { ...@@ -321,16 +323,27 @@ describe('AlertDetails', () => {
}); });
describe('Snowplow tracking', () => { describe('Snowplow tracking', () => {
beforeEach(() => { const mountOptions = {
jest.spyOn(Tracking, 'event');
mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alert: mockAlert }, data: { alert: mockAlert },
loading: false, loading: false,
};
beforeEach(() => {
jest.spyOn(Tracking, 'event');
}); });
it('should not track alert details page views when the tracking options do not exist', () => {
mountComponent(mountOptions);
expect(Tracking.event).not.toHaveBeenCalled();
}); });
it('should track alert details page views', () => { it('should track alert details page views when the tracking options exist', () => {
const trackAlertsDetailsViewsOptions = {
category: 'Alert Management',
action: 'view_alert_details',
};
mountComponent({ ...mountOptions, provide: { trackAlertsDetailsViewsOptions } });
const { category, action } = trackAlertsDetailsViewsOptions; const { category, action } = trackAlertsDetailsViewsOptions;
expect(Tracking.event).toHaveBeenCalledWith(category, action); expect(Tracking.event).toHaveBeenCalledWith(category, action);
}); });
......
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import SidebarTodo from '~/alert_management/components/sidebar/sidebar_todo.vue'; import SidebarTodo from '~/vue_shared/alert_details/components/sidebar/sidebar_todo.vue';
import createAlertTodoMutation from '~/alert_management/graphql/mutations/alert_todo_create.mutation.graphql'; import createAlertTodoMutation from '~/vue_shared/alert_details/graphql/mutations/alert_todo_create.mutation.graphql';
import todoMarkDoneMutation from '~/graphql_shared/mutations/todo_mark_done.mutation.graphql'; import todoMarkDoneMutation from '~/graphql_shared/mutations/todo_mark_done.mutation.graphql';
import mockAlerts from '../mocks/alerts.json'; import mockAlerts from './mocks/alerts.json';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
......
...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,7 +2,7 @@ import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from 'axios'; import axios from 'axios';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import AlertMetrics from '~/alert_management/components/alert_metrics.vue'; import AlertMetrics from '~/vue_shared/alert_details/components/alert_metrics.vue';
import MetricEmbed from '~/monitoring/components/embeds/metric_embed.vue'; import MetricEmbed from '~/monitoring/components/embeds/metric_embed.vue';
jest.mock('~/monitoring/stores', () => ({ jest.mock('~/monitoring/stores', () => ({
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { trackAlertStatusUpdateOptions } from '~/alert_management/constants'; import AlertManagementStatus from '~/vue_shared/alert_details/components/alert_status.vue';
import AlertManagementStatus from '~/alert_management/components/alert_status.vue'; import updateAlertStatusMutation from '~/graphql_shared//mutations/alert_status_update.mutation.graphql';
import updateAlertStatusMutation from '~/graphql_shared/mutations/update_alert_status.mutation.graphql';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import mockAlerts from '../mocks/alerts.json'; import mockAlerts from './mocks/alerts.json';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
...@@ -20,7 +19,7 @@ describe('AlertManagementStatus', () => { ...@@ -20,7 +19,7 @@ describe('AlertManagementStatus', () => {
return waitForPromises(); return waitForPromises();
}; };
function mountComponent({ props = {}, loading = false, stubs = {} } = {}) { function mountComponent({ props = {}, provide = {}, loading = false, stubs = {} } = {}) {
wrapper = shallowMount(AlertManagementStatus, { wrapper = shallowMount(AlertManagementStatus, {
propsData: { propsData: {
alert: { ...mockAlert }, alert: { ...mockAlert },
...@@ -28,6 +27,7 @@ describe('AlertManagementStatus', () => { ...@@ -28,6 +27,7 @@ describe('AlertManagementStatus', () => {
isSidebar: false, isSidebar: false,
...props, ...props,
}, },
provide,
mocks: { mocks: {
$apollo: { $apollo: {
mutate: jest.fn(), mutate: jest.fn(),
...@@ -134,10 +134,25 @@ describe('AlertManagementStatus', () => { ...@@ -134,10 +134,25 @@ describe('AlertManagementStatus', () => {
describe('Snowplow tracking', () => { describe('Snowplow tracking', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(Tracking, 'event'); jest.spyOn(Tracking, 'event');
});
it('should not track alert status updates when the tracking options do not exist', () => {
mountComponent({}); mountComponent({});
Tracking.event.mockClear();
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({});
findFirstStatusOption().vm.$emit('click');
setImmediate(() => {
expect(Tracking.event).not.toHaveBeenCalled();
});
}); });
it('should track alert status updates', () => { it('should track alert status updates when the tracking options exist', () => {
const trackAlertStatusUpdateOptions = {
category: 'Alert Management',
action: 'update_alert_status',
label: 'Status',
};
mountComponent({ provide: { trackAlertStatusUpdateOptions } });
Tracking.event.mockClear(); Tracking.event.mockClear();
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({}); jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({});
findFirstStatusOption().vm.$emit('click'); findFirstStatusOption().vm.$emit('click');
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import AlertSummaryRow from '~/alert_management/components/alert_summary_row.vue'; import AlertSummaryRow from '~/vue_shared/alert_details/components/alert_summary_row.vue';
const label = 'a label'; const label = 'a label';
const value = 'a value'; const value = 'a value';
......
...@@ -2,10 +2,10 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,10 +2,10 @@ import { shallowMount } from '@vue/test-utils';
import axios from 'axios'; import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { GlDropdownItem } from '@gitlab/ui'; import { GlDropdownItem } from '@gitlab/ui';
import SidebarAssignee from '~/alert_management/components/sidebar/sidebar_assignee.vue'; import SidebarAssignee from '~/vue_shared/alert_details/components/sidebar/sidebar_assignee.vue';
import SidebarAssignees from '~/alert_management/components/sidebar/sidebar_assignees.vue'; import SidebarAssignees from '~/vue_shared/alert_details/components/sidebar/sidebar_assignees.vue';
import AlertSetAssignees from '~/alert_management/graphql/mutations/alert_set_assignees.mutation.graphql'; import AlertSetAssignees from '~/vue_shared/alert_details/graphql/mutations/alert_set_assignees.mutation.graphql';
import mockAlerts from '../../mocks/alerts.json'; import mockAlerts from '../mocks/alerts.json';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
......
import { shallowMount, mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import axios from 'axios'; import axios from 'axios';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import AlertSidebar from '~/alert_management/components/alert_sidebar.vue'; import AlertSidebar from '~/vue_shared/alert_details/components/alert_sidebar.vue';
import SidebarAssignees from '~/alert_management/components/sidebar/sidebar_assignees.vue'; import SidebarAssignees from '~/vue_shared/alert_details/components/sidebar/sidebar_assignees.vue';
import mockAlerts from '../../mocks/alerts.json'; import mockAlerts from '../mocks/alerts.json';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
......
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { GlDropdown, GlDropdownItem, GlLoadingIcon } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlLoadingIcon } from '@gitlab/ui';
import { trackAlertStatusUpdateOptions } from '~/alert_management/constants'; import AlertSidebarStatus from '~/vue_shared/alert_details/components/sidebar/sidebar_status.vue';
import AlertSidebarStatus from '~/alert_management/components/sidebar/sidebar_status.vue'; import updateAlertStatusMutation from '~/graphql_shared/mutations/alert_status_update.mutation.graphql';
import updateAlertStatusMutation from '~/graphql_shared/mutations/update_alert_status.mutation.graphql'; import mockAlerts from '../mocks/alerts.json';
import Tracking from '~/tracking';
import mockAlerts from '../../mocks/alerts.json';
const mockAlert = mockAlerts[0]; const mockAlert = mockAlerts[0];
...@@ -101,30 +99,5 @@ describe('Alert Details Sidebar Status', () => { ...@@ -101,30 +99,5 @@ describe('Alert Details Sidebar Status', () => {
expect(wrapper.find('[data-testid="status"]').text()).toBe('Triggered'); expect(wrapper.find('[data-testid="status"]').text()).toBe('Triggered');
}); });
}); });
describe('Snowplow tracking', () => {
beforeEach(() => {
jest.spyOn(Tracking, 'event');
mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alert: mockAlert },
loading: false,
});
});
it('should track alert status updates', () => {
Tracking.event.mockClear();
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue({});
findStatusDropdownItem().vm.$emit('click');
const status = findStatusDropdownItem().text();
setImmediate(() => {
const { category, action, label } = trackAlertStatusUpdateOptions;
expect(Tracking.event).toHaveBeenCalledWith(category, action, {
label,
property: status,
});
});
});
});
}); });
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlIcon } from '@gitlab/ui'; import { GlIcon } from '@gitlab/ui';
import SystemNote from '~/alert_management/components/system_notes/system_note.vue'; import SystemNote from '~/vue_shared/alert_details/components/system_notes/system_note.vue';
import mockAlerts from '../../mocks/alerts.json'; import mockAlerts from '../mocks/alerts.json';
const mockAlert = mockAlerts[1]; const mockAlert = mockAlerts[1];
......
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