summaryrefslogtreecommitdiff
path: root/spec/frontend/analytics/devops_reports/components/service_ping_disabled_spec.js
blob: c62bfb11f7b280cfd8c20a2860573693da603bfb (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
import { GlEmptyState, GlSprintf } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import ServicePingDisabled from '~/analytics/devops_reports/components/service_ping_disabled.vue';

describe('~/analytics/devops_reports/components/service_ping_disabled.vue', () => {
  let wrapper;

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

  const createWrapper = ({ isAdmin = false } = {}) => {
    wrapper = mountExtended(ServicePingDisabled, {
      provide: {
        isAdmin,
        svgPath: TEST_HOST,
        primaryButtonPath: TEST_HOST,
      },
    });
  };

  const findEmptyState = () => wrapper.findComponent(GlEmptyState);
  const findMessageForRegularUsers = () => wrapper.findComponent(GlSprintf);
  const findDocsLink = () => wrapper.findByRole('link', { name: 'service ping' });
  const findPowerOnButton = () => wrapper.findByRole('link', { name: 'Turn on service ping' });

  it('renders empty state with provided SVG path', () => {
    createWrapper();

    expect(findEmptyState().props('svgPath')).toBe(TEST_HOST);
  });

  describe('for regular users', () => {
    beforeEach(() => {
      createWrapper({ isAdmin: false });
    });

    it('renders message without power-on button', () => {
      expect(findMessageForRegularUsers().exists()).toBe(true);
      expect(findPowerOnButton().exists()).toBe(false);
    });

    it('renders docs link', () => {
      expect(findDocsLink().exists()).toBe(true);
      expect(findDocsLink().attributes('href')).toBe('/help/development/service_ping/index.md');
    });
  });

  describe('for admins', () => {
    beforeEach(() => {
      createWrapper({ isAdmin: true });
    });

    it('renders power-on button', () => {
      expect(findPowerOnButton().exists()).toBe(true);
    });
  });
});