summaryrefslogtreecommitdiff
path: root/spec/frontend/environments/empty_state_spec.js
blob: 02cf2dc3c68f7bb4bd9421e0c6dfedaa02a31c38 (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
import { mountExtended } from 'helpers/vue_test_utils_helper';
import { s__ } from '~/locale';
import EmptyState from '~/environments/components/empty_state.vue';
import { ENVIRONMENTS_SCOPE } from '~/environments/constants';

const HELP_PATH = '/help';
const NEW_PATH = '/new';

describe('~/environments/components/empty_state.vue', () => {
  let wrapper;

  const findNewEnvironmentLink = () =>
    wrapper.findByRole('link', {
      name: s__('Environments|New environment'),
    });

  const findDocsLink = () =>
    wrapper.findByRole('link', {
      name: s__('Environments|How do I create an environment?'),
    });

  const createWrapper = ({ propsData = {} } = {}) =>
    mountExtended(EmptyState, {
      propsData: {
        scope: ENVIRONMENTS_SCOPE.AVAILABLE,
        helpPath: HELP_PATH,
        ...propsData,
      },
      provide: { newEnvironmentPath: NEW_PATH },
    });

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

  it('shows an empty state for available environments', () => {
    wrapper = createWrapper();

    const title = wrapper.findByRole('heading', {
      name: s__("Environments|You don't have any environments."),
    });

    expect(title.exists()).toBe(true);
  });

  it('shows an empty state for stopped environments', () => {
    wrapper = createWrapper({ propsData: { scope: ENVIRONMENTS_SCOPE.STOPPED } });

    const title = wrapper.findByRole('heading', {
      name: s__("Environments|You don't have any stopped environments."),
    });

    expect(title.exists()).toBe(true);
  });

  it('shows a link to the the help path', () => {
    wrapper = createWrapper();

    const link = findDocsLink();

    expect(link.attributes('href')).toBe(HELP_PATH);
  });

  it('hides a link to creating a new environment', () => {
    const link = findNewEnvironmentLink();

    expect(link.exists()).toBe(false);
  });

  describe('with search term', () => {
    beforeEach(() => {
      wrapper = createWrapper({ propsData: { hasTerm: true } });
    });

    it('should show text about searching', () => {
      const header = wrapper.findByRole('heading', {
        name: s__('Environments|No results found'),
      });

      expect(header.exists()).toBe(true);

      const text = wrapper.findByText(s__('Environments|Edit your search and try again'));

      expect(text.exists()).toBe(true);
    });

    it('hides the documentation link', () => {
      const link = findDocsLink();

      expect(link.exists()).toBe(false);
    });

    it('shows a link to create a new environment', () => {
      const link = findNewEnvironmentLink();

      expect(link.attributes('href')).toBe(NEW_PATH);
    });
  });
});