Commit c7e8d1d9 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '330543-update-alert-status-sidebar-components' into 'master'

Add additional alert status tests

See merge request gitlab-org/gitlab!64028
parents b83e962f 2db2a8a1
<script> <script>
import { GlIcon, GlLoadingIcon, GlTooltip, GlSprintf } from '@gitlab/ui'; import { GlButton, GlIcon, GlLoadingIcon, GlTooltip, GlSprintf } from '@gitlab/ui';
import { PAGE_CONFIG } from '../../constants'; import { PAGE_CONFIG } from '../../constants';
import AlertStatus from '../alert_status.vue'; import AlertStatus from '../alert_status.vue';
export default { export default {
components: { components: {
GlIcon, GlIcon,
GlButton,
GlLoadingIcon, GlLoadingIcon,
GlTooltip, GlTooltip,
GlSprintf, GlSprintf,
...@@ -96,16 +97,15 @@ export default { ...@@ -96,16 +97,15 @@ export default {
class="gl-text-gray-900 gl-mb-2 gl-line-height-20 gl-display-flex gl-justify-content-space-between" class="gl-text-gray-900 gl-mb-2 gl-line-height-20 gl-display-flex gl-justify-content-space-between"
> >
{{ s__('AlertManagement|Status') }} {{ s__('AlertManagement|Status') }}
<a <gl-button
v-if="isEditable" v-if="isEditable"
ref="editButton" class="gl-text-black-normal!"
class="btn-link" variant="link"
href="#"
@click="toggleFormDropdown" @click="toggleFormDropdown"
@keydown.esc="hideDropdown" @keydown.esc="hideDropdown"
> >
{{ s__('AlertManagement|Edit') }} {{ s__('AlertManagement|Edit') }}
</a> </gl-button>
</p> </p>
<alert-status <alert-status
......
import { GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import updateAlertStatusMutation from '~/graphql_shared//mutations/alert_status_update.mutation.graphql'; import updateAlertStatusMutation from '~/graphql_shared//mutations/alert_status_update.mutation.graphql';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
...@@ -10,9 +10,10 @@ const mockAlert = mockAlerts[0]; ...@@ -10,9 +10,10 @@ const mockAlert = mockAlerts[0];
describe('AlertManagementStatus', () => { describe('AlertManagementStatus', () => {
let wrapper; let wrapper;
const findStatusDropdown = () => wrapper.find(GlDropdown); const findStatusDropdown = () => wrapper.findComponent(GlDropdown);
const findFirstStatusOption = () => findStatusDropdown().find(GlDropdownItem); const findFirstStatusOption = () => findStatusDropdown().findComponent(GlDropdownItem);
const findAllStatusOptions = () => findStatusDropdown().findAll(GlDropdownItem); const findAllStatusOptions = () => findStatusDropdown().findAll(GlDropdownItem);
const findStatusDropdownHeader = () => wrapper.findByTestId('dropdown-header');
const selectFirstStatusOption = () => { const selectFirstStatusOption = () => {
findFirstStatusOption().vm.$emit('click'); findFirstStatusOption().vm.$emit('click');
...@@ -21,7 +22,7 @@ describe('AlertManagementStatus', () => { ...@@ -21,7 +22,7 @@ describe('AlertManagementStatus', () => {
}; };
function mountComponent({ props = {}, provide = {}, loading = false, stubs = {} } = {}) { function mountComponent({ props = {}, provide = {}, loading = false, stubs = {} } = {}) {
wrapper = shallowMount(AlertManagementStatus, { wrapper = shallowMountExtended(AlertManagementStatus, {
propsData: { propsData: {
alert: { ...mockAlert }, alert: { ...mockAlert },
projectPath: 'gitlab-org/gitlab', projectPath: 'gitlab-org/gitlab',
...@@ -43,17 +44,29 @@ describe('AlertManagementStatus', () => { ...@@ -43,17 +44,29 @@ describe('AlertManagementStatus', () => {
}); });
} }
beforeEach(() => {
mountComponent();
});
afterEach(() => { afterEach(() => {
if (wrapper) { if (wrapper) {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
} }
}); });
describe('sidebar', () => {
it('displays the dropdown status header', () => {
mountComponent({ props: { isSidebar: true } });
expect(findStatusDropdownHeader().exists()).toBe(true);
});
it('hides the dropdown by default', () => {
mountComponent({ props: { isSidebar: true } });
expect(wrapper.classes()).toContain('gl-display-none');
});
it('shows the dropdown', () => {
mountComponent({ props: { isSidebar: true, isDropdownShowing: true } });
expect(wrapper.classes()).toContain('show');
});
});
describe('updating the alert status', () => { describe('updating the alert status', () => {
const iid = '1527542'; const iid = '1527542';
const mockUpdatedMutationResult = { const mockUpdatedMutationResult = {
...@@ -99,6 +112,13 @@ describe('AlertManagementStatus', () => { ...@@ -99,6 +112,13 @@ describe('AlertManagementStatus', () => {
]); ]);
}); });
it('emits an update event at the start and ending of the updating', async () => {
await selectFirstStatusOption();
expect(wrapper.emitted('handle-updating').length > 1).toBe(true);
expect(wrapper.emitted('handle-updating')[0]).toEqual([true]);
expect(wrapper.emitted('handle-updating')[1]).toEqual([false]);
});
it('emits an error when triggered a second time', async () => { it('emits an error when triggered a second time', async () => {
await selectFirstStatusOption(); await selectFirstStatusOption();
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
......
import { GlDropdown, GlDropdownItem, GlLoadingIcon } from '@gitlab/ui'; import { GlDropdown, GlLoadingIcon } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import updateAlertStatusMutation from '~/graphql_shared/mutations/alert_status_update.mutation.graphql';
import AlertStatus from '~/vue_shared/alert_details/components/alert_status.vue'; import AlertStatus from '~/vue_shared/alert_details/components/alert_status.vue';
import AlertSidebarStatus from '~/vue_shared/alert_details/components/sidebar/sidebar_status.vue'; import AlertSidebarStatus from '~/vue_shared/alert_details/components/sidebar/sidebar_status.vue';
import { PAGE_CONFIG } from '~/vue_shared/alert_details/constants'; import { PAGE_CONFIG } from '~/vue_shared/alert_details/constants';
...@@ -11,9 +10,7 @@ const mockAlert = mockAlerts[0]; ...@@ -11,9 +10,7 @@ const mockAlert = mockAlerts[0];
describe('Alert Details Sidebar Status', () => { describe('Alert Details Sidebar Status', () => {
let wrapper; let wrapper;
const findStatusDropdown = () => wrapper.findComponent(GlDropdown); const findStatusDropdown = () => wrapper.findComponent(GlDropdown);
const findStatusDropdownItem = () => wrapper.findComponent(GlDropdownItem);
const findStatusLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); const findStatusLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findStatusDropdownHeader = () => wrapper.findByTestId('dropdown-header');
const findAlertStatus = () => wrapper.findComponent(AlertStatus); const findAlertStatus = () => wrapper.findComponent(AlertStatus);
const findStatus = () => wrapper.findByTestId('status'); const findStatus = () => wrapper.findByTestId('status');
const findSidebarIcon = () => wrapper.findByTestId('status-icon'); const findSidebarIcon = () => wrapper.findByTestId('status-icon');
...@@ -25,7 +22,7 @@ describe('Alert Details Sidebar Status', () => { ...@@ -25,7 +22,7 @@ describe('Alert Details Sidebar Status', () => {
stubs = {}, stubs = {},
provide = {}, provide = {},
} = {}) { } = {}) {
wrapper = mountExtended(AlertSidebarStatus, { wrapper = shallowMountExtended(AlertSidebarStatus, {
propsData: { propsData: {
alert: { ...mockAlert }, alert: { ...mockAlert },
...data, ...data,
...@@ -63,11 +60,7 @@ describe('Alert Details Sidebar Status', () => { ...@@ -63,11 +60,7 @@ describe('Alert Details Sidebar Status', () => {
}); });
it('displays status dropdown', () => { it('displays status dropdown', () => {
expect(findStatusDropdown().exists()).toBe(true); expect(findAlertStatus().exists()).toBe(true);
});
it('displays the dropdown status header', () => {
expect(findStatusDropdownHeader().exists()).toBe(true);
}); });
it('does not display the collapsed sidebar icon', () => { it('does not display the collapsed sidebar icon', () => {
...@@ -75,42 +68,24 @@ describe('Alert Details Sidebar Status', () => { ...@@ -75,42 +68,24 @@ describe('Alert Details Sidebar Status', () => {
}); });
describe('updating the alert status', () => { describe('updating the alert status', () => {
const mockUpdatedMutationResult = { it('ensures dropdown is hidden when loading', async () => {
data: {
updateAlertStatus: {
errors: [],
alert: {
status: 'acknowledged',
},
},
},
};
beforeEach(() => {
mountComponent({ mountComponent({
data: { alert: mockAlert }, data: { alert: mockAlert },
sidebarCollapsed: false, sidebarCollapsed: false,
loading: false, loading: false,
}); });
}); findAlertStatus().vm.$emit('handle-updating', true);
await wrapper.vm.$nextTick();
it('calls `$apollo.mutate` with `updateAlertStatus` mutation and variables containing `iid`, `status`, & `projectPath`', () => { expect(findStatusLoadingIcon().exists()).toBe(true);
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockResolvedValue(mockUpdatedMutationResult);
findStatusDropdownItem().vm.$emit('click');
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
mutation: updateAlertStatusMutation,
variables: {
iid: '1527542',
status: 'TRIGGERED',
projectPath: 'projectPath',
},
});
}); });
it('stops updating when the request fails', () => { it('stops updating when the request fails', () => {
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockReturnValue(Promise.reject(new Error())); mountComponent({
findStatusDropdownItem().vm.$emit('click'); data: { alert: mockAlert },
sidebarCollapsed: false,
loading: false,
});
findAlertStatus().vm.$emit('handle-updating', false);
expect(findStatusLoadingIcon().exists()).toBe(false); expect(findStatusLoadingIcon().exists()).toBe(false);
expect(findStatus().text()).toBe('Triggered'); expect(findStatus().text()).toBe('Triggered');
}); });
......
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