summaryrefslogtreecommitdiff
path: root/spec/frontend/google_cloud/components/service_accounts_list_spec.js
blob: f7051c8a53d931883f9776d84404bf9c279583dc (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
import { mount } from '@vue/test-utils';
import { GlAlert, GlButton, GlEmptyState, GlTable } from '@gitlab/ui';
import ServiceAccountsList from '~/google_cloud/components/service_accounts_list.vue';

describe('ServiceAccounts component', () => {
  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: [{}, {}, {}],
        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('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);
    });
  });
});