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

triggers_list_spec.js « components « ci_settings_pipeline_triggers « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6bf28a6730053bd677491d9eb4e0374ff558a211 (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
import { GlTable, GlBadge } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import TriggersList from '~/ci_settings_pipeline_triggers/components/triggers_list.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';

import { triggers } from '../mock_data';

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

  const createComponent = (props = {}) => {
    wrapper = mount(TriggersList, {
      propsData: { triggers, ...props },
    });
  };

  const findTable = () => wrapper.find(GlTable);
  const findHeaderAt = (i) => wrapper.findAll('thead th').at(i);
  const findRows = () => wrapper.findAll('tbody tr');
  const findRowAt = (i) => findRows().at(i);
  const findCell = (i, col) => findRowAt(i).findAll('td').at(col);
  const findClipboardBtn = (i) => findCell(i, 0).find(ClipboardButton);
  const findInvalidBadge = (i) => findCell(i, 0).find(GlBadge);
  const findEditBtn = (i) => findRowAt(i).find('[data-testid="edit-btn"]');
  const findRevokeBtn = (i) => findRowAt(i).find('[data-testid="trigger_revoke_button"]');

  beforeEach(async () => {
    createComponent();

    await nextTick();
  });

  it('displays a table with expected headers', () => {
    const headers = ['Token', 'Description', 'Owner', 'Last Used', ''];
    headers.forEach((header, i) => {
      expect(findHeaderAt(i).text()).toBe(header);
    });
  });

  it('displays a table with rows', () => {
    expect(findRows()).toHaveLength(triggers.length);

    const [trigger] = triggers;

    expect(findCell(0, 0).text()).toBe(trigger.token);
    expect(findCell(0, 1).text()).toBe(trigger.description);
    expect(findCell(0, 2).text()).toContain(trigger.owner.name);
  });

  it('displays a "copy to cliboard" button for exposed tokens', () => {
    expect(findClipboardBtn(0).exists()).toBe(true);
    expect(findClipboardBtn(0).props('text')).toBe(triggers[0].token);

    expect(findClipboardBtn(1).exists()).toBe(false);
  });

  it('displays an "invalid" label for tokens without access', () => {
    expect(findInvalidBadge(0).exists()).toBe(false);

    expect(findInvalidBadge(1).exists()).toBe(true);
  });

  it('displays a time ago label when last used', () => {
    expect(findCell(0, 3).text()).toBe('Never');

    expect(findCell(1, 3).find(TimeAgoTooltip).props('time')).toBe(triggers[1].lastUsed);
  });

  it('displays actions in a rows', () => {
    const [data] = triggers;

    expect(findEditBtn(0).attributes('href')).toBe(data.editProjectTriggerPath);

    expect(findRevokeBtn(0).attributes('href')).toBe(data.projectTriggerPath);
    expect(findRevokeBtn(0).attributes('data-method')).toBe('delete');
    expect(findRevokeBtn(0).attributes('data-confirm')).toBeTruthy();
  });

  describe('when there are no triggers set', () => {
    beforeEach(() => {
      createComponent({ triggers: [] });
    });

    it('does not display a table', () => {
      expect(findTable().exists()).toBe(false);
    });

    it('displays a message', () => {
      expect(wrapper.text()).toBe(
        'No triggers have been created yet. Add one using the form above.',
      );
    });
  });
});