summaryrefslogtreecommitdiff
path: root/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_content_spec.js
blob: 8844e1626cd84886a28118f6a2923bd23c491c9d (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
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import SidebarConfidentialityContent from '~/sidebar/components/confidential/sidebar_confidentiality_content.vue';

describe('Sidebar Confidentiality Content', () => {
  let wrapper;

  const findIcon = () => wrapper.findComponent(GlIcon);
  const findText = () => wrapper.find('[data-testid="confidential-text"]');
  const findCollapsedIcon = () => wrapper.find('[data-testid="sidebar-collapsed-icon"]');

  const createComponent = ({ confidential = false, issuableType = 'issue' } = {}) => {
    wrapper = shallowMount(SidebarConfidentialityContent, {
      propsData: {
        confidential,
        issuableType,
      },
    });
  };

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

  it('emits `expandSidebar` event on collapsed icon click', () => {
    createComponent();
    findCollapsedIcon().trigger('click');

    expect(wrapper.emitted('expandSidebar')).toHaveLength(1);
  });

  describe('when issue is non-confidential', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders a non-confidential icon', () => {
      expect(findIcon().props('name')).toBe('eye');
    });

    it('does not add `is-active` class to the icon', () => {
      expect(findIcon().classes()).not.toContain('is-active');
    });

    it('displays a non-confidential text', () => {
      expect(findText().text()).toBe('Not confidential');
    });
  });

  describe('when issue is confidential', () => {
    it('renders a confidential icon', () => {
      createComponent({ confidential: true });
      expect(findIcon().props('name')).toBe('eye-slash');
    });

    it('adds `is-active` class to the icon', () => {
      createComponent({ confidential: true });
      expect(findIcon().classes()).toContain('is-active');
    });

    it('displays a correct confidential text for issue', () => {
      createComponent({ confidential: true });
      expect(findText().text()).toBe('This issue is confidential');
    });

    it('displays a correct confidential text for epic', () => {
      createComponent({ confidential: true, issuableType: 'epic' });
      expect(findText().text()).toBe('This epic is confidential');
    });
  });
});