debian-mirror-gitlab/spec/frontend/sidebar/components/incidents/escalation_status_spec.js

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

84 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-05-07 20:08:51 +05:30
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
2022-08-27 11:52:29 +05:30
import { nextTick } from 'vue';
2022-06-21 17:19:12 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2022-05-07 20:08:51 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
import EscalationStatus from '~/sidebar/components/incidents/escalation_status.vue';
2023-03-04 22:38:38 +05:30
import { STATUS_LABELS, STATUS_TRIGGERED, STATUS_ACKNOWLEDGED } from '~/sidebar/constants';
2022-05-07 20:08:51 +05:30
describe('EscalationStatus', () => {
let wrapper;
function createComponent(props) {
wrapper = mountExtended(EscalationStatus, {
propsData: {
value: STATUS_TRIGGERED,
...props,
},
});
}
const findDropdownComponent = () => wrapper.findComponent(GlDropdown);
const findDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
2022-06-21 17:19:12 +05:30
const findDropdownMenu = () => findDropdownComponent().find('.dropdown-menu');
const toggleDropdown = async () => {
await findDropdownComponent().findComponent('button').trigger('click');
await waitForPromises();
};
2022-05-07 20:08:51 +05:30
describe('status', () => {
it('shows the current status', () => {
createComponent({ value: STATUS_ACKNOWLEDGED });
expect(findDropdownComponent().props('text')).toBe(STATUS_LABELS[STATUS_ACKNOWLEDGED]);
});
it('shows the None option when status is null', () => {
createComponent({ value: null });
expect(findDropdownComponent().props('text')).toBe('None');
});
});
describe('events', () => {
it('selects an item', async () => {
createComponent();
await findDropdownItems().at(1).vm.$emit('click');
expect(wrapper.emitted().input[0][0]).toBe(STATUS_ACKNOWLEDGED);
});
});
2022-06-21 17:19:12 +05:30
describe('close behavior', () => {
it('allows the dropdown to be closed by default', async () => {
createComponent();
// Open dropdown
await toggleDropdown();
2022-08-27 11:52:29 +05:30
jest.runOnlyPendingTimers();
await nextTick();
2022-06-21 17:19:12 +05:30
expect(findDropdownMenu().classes('show')).toBe(true);
// Attempt to close dropdown
await toggleDropdown();
expect(findDropdownMenu().classes('show')).toBe(false);
});
it('preventDropdownClose prevents the dropdown from closing', async () => {
createComponent({ preventDropdownClose: true });
// Open dropdown
await toggleDropdown();
2022-08-27 11:52:29 +05:30
jest.runOnlyPendingTimers();
await nextTick();
2022-06-21 17:19:12 +05:30
expect(findDropdownMenu().classes('show')).toBe(true);
// Attempt to close dropdown
await toggleDropdown();
expect(findDropdownMenu().classes('show')).toBe(true);
});
});
2022-05-07 20:08:51 +05:30
});