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

describe('GcpRegions component', () => {
  describe('when the project does not have any configured regions', () => {
    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(GcpRegionsList, { 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('Configure regions');
      expect(button.attributes('href')).toBe('#create-url');
    });
  });

  describe('when three gcp regions 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);

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

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

    it('shows the description', () => {
      expect(findDescription().text()).toBe(
        'Configure your environments to be deployed to specific geographical regions',
      );
    });

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

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

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