Welcome to mirror list, hosted at ThFree Co, Russian Federation.

escalation_status_spec.js « incidents « components « sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a78ce4ddeecfde57049d5ba284461ae51089aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { nextTick } from 'vue';
import waitForPromises from 'helpers/wait_for_promises';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import EscalationStatus from '~/sidebar/components/incidents/escalation_status.vue';
import { STATUS_LABELS, STATUS_TRIGGERED, STATUS_ACKNOWLEDGED } from '~/sidebar/constants';

describe('EscalationStatus', () => {
  let wrapper;

  function createComponent(props) {
    wrapper = mountExtended(EscalationStatus, {
      propsData: {
        value: STATUS_TRIGGERED,
        ...props,
      },
    });
  }

  afterEach(() => {
    wrapper.destroy();
  });

  const findDropdownComponent = () => wrapper.findComponent(GlDropdown);
  const findDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
  const findDropdownMenu = () => findDropdownComponent().find('.dropdown-menu');
  const toggleDropdown = async () => {
    await findDropdownComponent().findComponent('button').trigger('click');
    await waitForPromises();
  };

  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);
    });
  });

  describe('close behavior', () => {
    it('allows the dropdown to be closed by default', async () => {
      createComponent();
      // Open dropdown
      await toggleDropdown();
      jest.runOnlyPendingTimers();
      await nextTick();

      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();
      jest.runOnlyPendingTimers();
      await nextTick();

      expect(findDropdownMenu().classes('show')).toBe(true);

      // Attempt to close dropdown
      await toggleDropdown();

      expect(findDropdownMenu().classes('show')).toBe(true);
    });
  });
});