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

integration_status_spec.js « components « agents « clusters « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 28a5939157886deaad02b473b6e81b0b896656bd (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
import { GlCollapse, GlButton, GlIcon } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import IntegrationStatus from '~/clusters/agents/components/integration_status.vue';
import AgentIntegrationStatusRow from '~/clusters/agents/components/agent_integration_status_row.vue';
import { ACTIVE_CONNECTION_TIME } from '~/clusters_list/constants';
import {
  INTEGRATION_STATUS_VALID_TOKEN,
  INTEGRATION_STATUS_NO_TOKEN,
  INTEGRATION_STATUS_RESTRICTED_CI_CD,
} from '~/clusters/agents/constants';

const connectedTimeNow = new Date();
const connectedTimeInactive = new Date(connectedTimeNow.getTime() - ACTIVE_CONNECTION_TIME);

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

  const createWrapper = (tokens = []) => {
    wrapper = shallowMountExtended(IntegrationStatus, {
      propsData: { tokens },
    });
  };

  const findCollapseButton = () => wrapper.findComponent(GlButton);
  const findCollapse = () => wrapper.findComponent(GlCollapse);
  const findStatusIcon = () => wrapper.findComponent(GlIcon);
  const findAgentStatus = () => wrapper.findByTestId('agent-status');
  const findAgentIntegrationStatusRows = () => wrapper.findAllComponents(AgentIntegrationStatusRow);

  it.each`
    lastUsedAt               | status               | iconName
    ${null}                  | ${'Never connected'} | ${'status-neutral'}
    ${connectedTimeNow}      | ${'Connected'}       | ${'status-success'}
    ${connectedTimeInactive} | ${'Not connected'}   | ${'status-alert'}
  `(
    'displays correct text and icon when agent connection status is "$status"',
    ({ lastUsedAt, status, iconName }) => {
      const tokens = [{ lastUsedAt }];
      createWrapper(tokens);

      expect(findStatusIcon().props('name')).toBe(iconName);
      expect(findAgentStatus().text()).toBe(status);
    },
  );

  describe('default', () => {
    beforeEach(() => {
      createWrapper();
    });

    it('shows the collapse toggle button', () => {
      expect(findCollapseButton().text()).toBe(wrapper.vm.$options.i18n.title);
      expect(findCollapseButton().attributes()).toMatchObject({
        variant: 'link',
        icon: 'chevron-right',
        size: 'small',
      });
    });

    it('sets collapse component as invisible by default', () => {
      expect(findCollapse().props('visible')).toBeUndefined();
    });
  });

  describe('when user clicks collapse toggle', () => {
    beforeEach(() => {
      createWrapper();
      findCollapseButton().vm.$emit('click');
    });

    it('changes the collapse button icon', () => {
      expect(findCollapseButton().props('icon')).toBe('chevron-down');
    });

    it('sets collapse component as visible', () => {
      expect(findCollapse().attributes('visible')).toBe('true');
    });
  });

  describe('integration status details', () => {
    it.each`
      agentStatus   | tokens                                     | integrationStatuses
      ${'active'}   | ${[{ lastUsedAt: connectedTimeNow }]}      | ${[INTEGRATION_STATUS_VALID_TOKEN, INTEGRATION_STATUS_RESTRICTED_CI_CD]}
      ${'inactive'} | ${[{ lastUsedAt: connectedTimeInactive }]} | ${[INTEGRATION_STATUS_RESTRICTED_CI_CD]}
      ${'inactive'} | ${[]}                                      | ${[INTEGRATION_STATUS_NO_TOKEN, INTEGRATION_STATUS_RESTRICTED_CI_CD]}
      ${'unused'}   | ${[{ lastUsedAt: null }]}                  | ${[INTEGRATION_STATUS_RESTRICTED_CI_CD]}
      ${'unused'}   | ${[]}                                      | ${[INTEGRATION_STATUS_NO_TOKEN, INTEGRATION_STATUS_RESTRICTED_CI_CD]}
    `(
      'displays AgentIntegrationStatusRow component with correct properties when agent status is $agentStatus and agent has $tokens.length tokens',
      ({ tokens, integrationStatuses }) => {
        createWrapper(tokens);

        expect(findAgentIntegrationStatusRows().length).toBe(integrationStatuses.length);

        integrationStatuses.forEach((integrationStatus, index) => {
          expect(findAgentIntegrationStatusRows().at(index).props()).toMatchObject({
            icon: integrationStatus.icon,
            iconClass: integrationStatus.iconClass,
            text: integrationStatus.text,
            helpUrl: integrationStatus.helpUrl || null,
            featureName: integrationStatus.featureName || null,
          });
        });
      },
    );
  });
});