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

alerts_integrations_list_spec.js « alerts_settings « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a7392f64f7dbb522e4b964650dc0a2c6653abba (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { GlTable, GlIcon, GlButton } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { useMockIntersectionObserver } from 'helpers/mock_dom_observer';
import Tracking from '~/tracking';
import AlertIntegrationsList, {
  i18n,
} from '~/alerts_settings/components/alerts_integrations_list.vue';
import { trackAlertIntegrationsViewsOptions } from '~/alerts_settings/constants';

const mockIntegrations = [
  {
    id: '1',
    active: true,
    name: 'Integration 1',
    type: 'HTTP endpoint',
  },
  {
    id: '2',
    active: false,
    name: 'Integration 2',
    type: 'HTTP endpoint',
  },
];

describe('AlertIntegrationsList', () => {
  let wrapper;
  const { trigger: triggerIntersection } = useMockIntersectionObserver();

  function mountComponent({ data = {}, props = {} } = {}) {
    wrapper = mount(AlertIntegrationsList, {
      data() {
        return { ...data };
      },
      propsData: {
        integrations: mockIntegrations,
        ...props,
      },
      stubs: {
        GlIcon: true,
        GlButton: true,
      },
    });
  }

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

  beforeEach(() => {
    mountComponent();
  });

  const findTableComponent = () => wrapper.find(GlTable);
  const findTableComponentRows = () => wrapper.find(GlTable).findAll('table tbody tr');
  const finsStatusCell = () => wrapper.findAll('[data-testid="integration-activated-status"]');

  it('renders a table', () => {
    expect(findTableComponent().exists()).toBe(true);
  });

  it('renders an empty state when no integrations provided', () => {
    mountComponent({ props: { integrations: [] } });
    expect(findTableComponent().text()).toContain(i18n.emptyState);
  });

  it('renders an an edit and delete button for each integration', () => {
    expect(findTableComponent().findAll(GlButton).length).toBe(4);
  });

  it('renders an highlighted row when a current integration is selected to edit', () => {
    mountComponent({ data: { currentIntegration: { id: '1' } } });
    expect(
      findTableComponentRows()
        .at(0)
        .classes(),
    ).toContain('gl-bg-blue-50');
  });

  describe('integration status', () => {
    it('enabled', () => {
      const cell = finsStatusCell().at(0);
      const activatedIcon = cell.find(GlIcon);
      expect(cell.text()).toBe(i18n.status.enabled.name);
      expect(activatedIcon.attributes('name')).toBe('check-circle-filled');
      expect(activatedIcon.attributes('title')).toBe(i18n.status.enabled.tooltip);
    });

    it('disabled', () => {
      const cell = finsStatusCell().at(1);
      const notActivatedIcon = cell.find(GlIcon);
      expect(cell.text()).toBe(i18n.status.disabled.name);
      expect(notActivatedIcon.attributes('name')).toBe('warning-solid');
      expect(notActivatedIcon.attributes('title')).toBe(i18n.status.disabled.tooltip);
    });
  });

  describe('Snowplow tracking', () => {
    beforeEach(() => {
      mountComponent();
      jest.spyOn(Tracking, 'event');
    });

    it('should NOT track alert list page views when list is collapsed', () => {
      triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: false } });

      expect(Tracking.event).not.toHaveBeenCalled();
    });

    it('should track alert list page views only once when list is expanded', () => {
      triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
      triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });
      triggerIntersection(wrapper.vm.$el, { entry: { isIntersecting: true } });

      const { category, action } = trackAlertIntegrationsViewsOptions;
      expect(Tracking.event).toHaveBeenCalledTimes(1);
      expect(Tracking.event).toHaveBeenCalledWith(category, action);
    });
  });
});