Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sidebar_confidentiality_content_spec.js « confidential « components « sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81354d64a90adfd3ed1c0a9d0c97151ecb9d2dbe (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
import { GlIcon, GlAlert } 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 });

      const alertEl = findText().findComponent(GlAlert);

      expect(alertEl.props()).toMatchObject({
        showIcon: false,
        dismissible: false,
        variant: 'warning',
      });
      expect(alertEl.text()).toBe(
        'Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.',
      );
    });

    it('displays a correct confidential text for epic', () => {
      createComponent({ confidential: true, issuableType: 'epic' });
      expect(findText().findComponent(GlAlert).text()).toBe(
        'Only group members with at least the Reporter role can view or be notified about this epic.',
      );
    });
  });
});