summaryrefslogtreecommitdiff
path: root/spec/frontend/clusters_list/components/clusters_empty_state_spec.js
blob: f7e1791d0f744a23f35258b1dcd82b97bab44d01 (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
import { GlEmptyState, GlButton } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ClustersEmptyState from '~/clusters_list/components/clusters_empty_state.vue';
import ClusterStore from '~/clusters_list/store';

const clustersEmptyStateImage = 'path/to/svg';
const newClusterPath = '/path/to/connect/cluster';
const emptyStateHelpText = 'empty state text';
const canAddCluster = true;

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

  const propsData = {
    isChildComponent: false,
  };

  const provideData = {
    clustersEmptyStateImage,
    emptyStateHelpText: null,
    newClusterPath,
  };

  const entryData = {
    canAddCluster,
  };

  const findButton = () => wrapper.findComponent(GlButton);
  const findEmptyStateText = () => wrapper.findByTestId('clusters-empty-state-text');

  beforeEach(() => {
    wrapper = shallowMountExtended(ClustersEmptyState, {
      store: ClusterStore(entryData),
      propsData,
      provide: provideData,
      stubs: { GlEmptyState },
    });
  });

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

  describe('when the component is loaded independently', () => {
    it('should render the action button', () => {
      expect(findButton().exists()).toBe(true);
    });
  });

  describe('when the help text is not provided', () => {
    it('should not render the empty state text', () => {
      expect(findEmptyStateText().exists()).toBe(false);
    });
  });

  describe('when the component is loaded as a child component', () => {
    beforeEach(() => {
      propsData.isChildComponent = true;
      wrapper = shallowMountExtended(ClustersEmptyState, {
        store: ClusterStore(entryData),
        propsData,
        provide: provideData,
      });
    });

    afterEach(() => {
      propsData.isChildComponent = false;
    });

    it('should not render the action button', () => {
      expect(findButton().exists()).toBe(false);
    });
  });

  describe('when the help text is provided', () => {
    beforeEach(() => {
      provideData.emptyStateHelpText = emptyStateHelpText;
      wrapper = shallowMountExtended(ClustersEmptyState, {
        store: ClusterStore(entryData),
        propsData,
        provide: provideData,
      });
    });

    it('should show the empty state text', () => {
      expect(findEmptyStateText().text()).toBe(emptyStateHelpText);
    });
  });

  describe('when the user cannot add clusters', () => {
    entryData.canAddCluster = false;
    beforeEach(() => {
      wrapper = shallowMountExtended(ClustersEmptyState, {
        store: ClusterStore(entryData),
        propsData,
        provide: provideData,
        stubs: { GlEmptyState },
      });
    });
    it('should disable the button', () => {
      expect(findButton().props('disabled')).toBe(true);
    });
  });
});