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

list_spec.js « service_accounts « google_cloud « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c2bd2005b5d5a4bae8be12ee47cc68b7bf7dbb58 (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
import { mount } from '@vue/test-utils';
import { GlAlert, GlButton, GlEmptyState, GlLink, GlTable } from '@gitlab/ui';
import ServiceAccountsList from '~/google_cloud/service_accounts/list.vue';

describe('google_cloud/service_accounts/list', () => {
  describe('when the project does not have any service accounts', () => {
    let wrapper;

    const findEmptyState = () => wrapper.findComponent(GlEmptyState);
    const findButtonInEmptyState = () => findEmptyState().findComponent(GlButton);

    beforeEach(() => {
      const propsData = {
        list: [],
        createUrl: '#create-url',
        emptyIllustrationUrl: '#empty-illustration-url',
      };
      wrapper = mount(ServiceAccountsList, { propsData });
    });

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

    it('shows the empty state component', () => {
      expect(findEmptyState().exists()).toBe(true);
    });
    it('shows the link to create new service accounts', () => {
      const button = findButtonInEmptyState();
      expect(button.exists()).toBe(true);
      expect(button.text()).toBe(ServiceAccountsList.i18n.createServiceAccount);
      expect(button.attributes('href')).toBe('#create-url');
    });
  });

  describe('when three service accounts are passed via props', () => {
    let wrapper;

    const findTitle = () => wrapper.find('h2');
    const findDescription = () => wrapper.find('p');
    const findTable = () => wrapper.findComponent(GlTable);
    const findRows = () => findTable().findAll('tr');
    const findButton = () => wrapper.findComponent(GlButton);
    const findSecretManagerTip = () => wrapper.findComponent(GlAlert);

    beforeEach(() => {
      const propsData = {
        list: [
          {
            ref: '*',
            gcp_project: 'gcp-project-123',
            service_account_exists: true,
            service_account_key_exists: true,
          },
          {
            ref: 'prod',
            gcp_project: 'gcp-project-456',
            service_account_exists: true,
            service_account_key_exists: true,
          },
          {
            ref: 'stag',
            gcp_project: 'gcp-project-789',
            service_account_exists: true,
            service_account_key_exists: true,
          },
        ],
        createUrl: '#create-url',
        emptyIllustrationUrl: '#empty-illustration-url',
      };
      wrapper = mount(ServiceAccountsList, { propsData });
    });

    it('shows the title', () => {
      expect(findTitle().text()).toBe(ServiceAccountsList.i18n.serviceAccountsTitle);
    });

    it('shows the description', () => {
      expect(findDescription().text()).toBe(ServiceAccountsList.i18n.serviceAccountsDescription);
    });

    it('shows the table', () => {
      expect(findTable().exists()).toBe(true);
    });

    it('table must have three rows + header row', () => {
      expect(findRows().length).toBe(4);
    });

    it('table row must contain link to the google cloud console', () => {
      expect(findRows().at(1).findComponent(GlLink).attributes('href')).toBe(
        `${ServiceAccountsList.GOOGLE_CONSOLE_URL}?project=gcp-project-123`,
      );
    });

    it('shows the link to create new service accounts', () => {
      const button = findButton();
      expect(button.exists()).toBe(true);
      expect(button.text()).toBe(ServiceAccountsList.i18n.createServiceAccount);
      expect(button.attributes('href')).toBe('#create-url');
    });

    it('must contain secret managers tip', () => {
      const tip = findSecretManagerTip();
      const expectedText = ServiceAccountsList.i18n.secretManagersDescription.substr(0, 48);
      expect(tip.text()).toContain(expectedText);
    });
  });
});