debian-mirror-gitlab/spec/frontend/sidebar/components/severity/sidebar_severity_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

158 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlDropdown, GlDropdownItem, GlLoadingIcon, GlTooltip, GlSprintf } from '@gitlab/ui';
2021-10-27 15:23:28 +05:30
import { nextTick } from 'vue';
2023-04-23 21:23:45 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
2020-11-24 15:15:51 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2022-11-25 23:54:43 +05:30
import { createAlert } from '~/flash';
2023-03-04 22:38:38 +05:30
import { INCIDENT_SEVERITY, ISSUABLE_TYPES } from '~/sidebar/constants';
import updateIssuableSeverity from '~/sidebar/queries/update_issuable_severity.mutation.graphql';
2021-03-11 19:13:27 +05:30
import SeverityToken from '~/sidebar/components/severity/severity.vue';
2023-04-23 21:23:45 +05:30
import SidebarSeverityWidget from '~/sidebar/components/severity/sidebar_severity_widget.vue';
2020-11-24 15:15:51 +05:30
jest.mock('~/flash');
describe('SidebarSeverity', () => {
let wrapper;
let mutate;
const projectPath = 'gitlab-org/gitlab-test';
const iid = '1';
const severity = 'CRITICAL';
2021-10-27 15:23:28 +05:30
let canUpdate = true;
2020-11-24 15:15:51 +05:30
function createComponent(props = {}) {
const propsData = {
projectPath,
iid,
issuableType: ISSUABLE_TYPES.INCIDENT,
initialSeverity: severity,
...props,
};
mutate = jest.fn();
2023-04-23 21:23:45 +05:30
wrapper = mountExtended(SidebarSeverityWidget, {
2020-11-24 15:15:51 +05:30
propsData,
2021-10-27 15:23:28 +05:30
provide: {
canUpdate,
},
2020-11-24 15:15:51 +05:30
mocks: {
$apollo: {
mutate,
},
},
stubs: {
GlSprintf,
},
});
}
beforeEach(() => {
createComponent();
});
afterEach(() => {
2023-04-23 21:23:45 +05:30
wrapper.destroy();
2020-11-24 15:15:51 +05:30
});
2021-10-27 15:23:28 +05:30
const findSeverityToken = () => wrapper.findAllComponents(SeverityToken);
2023-04-23 21:23:45 +05:30
const findEditBtn = () => wrapper.findByTestId('edit-button');
2021-10-27 15:23:28 +05:30
const findDropdown = () => wrapper.findComponent(GlDropdown);
const findCriticalSeverityDropdownItem = () => wrapper.findComponent(GlDropdownItem);
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
const findTooltip = () => wrapper.findComponent(GlTooltip);
2022-11-25 23:54:43 +05:30
const findCollapsedSeverity = () => wrapper.findComponent({ ref: 'severity' });
2020-11-24 15:15:51 +05:30
2021-10-27 15:23:28 +05:30
describe('Severity widget', () => {
it('renders severity dropdown and token', () => {
expect(findSeverityToken().exists()).toBe(true);
expect(findDropdown().exists()).toBe(true);
});
describe('edit button', () => {
it('is rendered when `canUpdate` provided as `true`', () => {
expect(findEditBtn().exists()).toBe(true);
});
it('is NOT rendered when `canUpdate` provided as `false`', () => {
canUpdate = false;
createComponent();
expect(findEditBtn().exists()).toBe(false);
});
});
2020-11-24 15:15:51 +05:30
});
describe('Update severity', () => {
it('calls `$apollo.mutate` with `updateIssuableSeverity`', () => {
jest
.spyOn(wrapper.vm.$apollo, 'mutate')
.mockResolvedValueOnce({ data: { issueSetSeverity: { issue: { severity } } } });
findCriticalSeverityDropdownItem().vm.$emit('click');
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
mutation: updateIssuableSeverity,
variables: {
iid,
projectPath,
severity,
},
});
});
2022-10-11 01:57:18 +05:30
it('shows error alert when severity update fails', async () => {
2020-11-24 15:15:51 +05:30
const errorMsg = 'Something went wrong';
jest.spyOn(wrapper.vm.$apollo, 'mutate').mockRejectedValueOnce(errorMsg);
findCriticalSeverityDropdownItem().vm.$emit('click');
2022-04-04 11:22:00 +05:30
await waitForPromises();
2022-11-25 23:54:43 +05:30
expect(createAlert).toHaveBeenCalled();
2020-11-24 15:15:51 +05:30
});
it('shows loading icon while updating', async () => {
let resolvePromise;
wrapper.vm.$apollo.mutate = jest.fn(
() =>
2021-03-08 18:12:59 +05:30
new Promise((resolve) => {
2020-11-24 15:15:51 +05:30
resolvePromise = resolve;
}),
);
findCriticalSeverityDropdownItem().vm.$emit('click');
2021-10-27 15:23:28 +05:30
await nextTick();
2020-11-24 15:15:51 +05:30
expect(findLoadingIcon().exists()).toBe(true);
resolvePromise();
await waitForPromises();
expect(findLoadingIcon().exists()).toBe(false);
});
});
describe('Switch between collapsed/expanded view of the sidebar', () => {
describe('collapsed', () => {
it('should have collapsed icon class', () => {
expect(findCollapsedSeverity().classes('sidebar-collapsed-icon')).toBe(true);
});
it('should display only icon with a tooltip', () => {
2023-04-23 21:23:45 +05:30
expect(findSeverityToken().exists()).toBe(true);
expect(findTooltip().text()).toContain(INCIDENT_SEVERITY[severity].label);
expect(findEditBtn().exists()).toBe(false);
2020-11-24 15:15:51 +05:30
});
});
describe('expanded', () => {
it('toggles dropdown with edit button', async () => {
2021-10-27 15:23:28 +05:30
canUpdate = true;
createComponent();
await nextTick();
2023-04-23 21:23:45 +05:30
expect(findDropdown().isVisible()).toBe(false);
2020-11-24 15:15:51 +05:30
findEditBtn().vm.$emit('click');
2021-10-27 15:23:28 +05:30
await nextTick();
2023-04-23 21:23:45 +05:30
expect(findDropdown().isVisible()).toBe(true);
2020-11-24 15:15:51 +05:30
findEditBtn().vm.$emit('click');
2021-10-27 15:23:28 +05:30
await nextTick();
2023-04-23 21:23:45 +05:30
expect(findDropdown().isVisible()).toBe(false);
2020-11-24 15:15:51 +05:30
});
});
});
});