summaryrefslogtreecommitdiff
path: root/spec/frontend/projects/settings/branch_rules/components/view/protection_spec.js
blob: e2fbb4f5bbb05d00364936a5f8b2813e59fafc45 (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
import { GlCard, GlLink } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Protection, { i18n } from '~/projects/settings/branch_rules/components/view/protection.vue';
import ProtectionRow from '~/projects/settings/branch_rules/components/view/protection_row.vue';
import { protectionPropsMock } from './mock_data';

describe('Branch rule protection', () => {
  let wrapper;

  const createComponent = () => {
    wrapper = shallowMountExtended(Protection, {
      propsData: protectionPropsMock,
      stubs: { GlCard },
    });
  };

  beforeEach(() => createComponent());

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

  const findCard = () => wrapper.findComponent(GlCard);
  const findHeader = () => wrapper.findByText(protectionPropsMock.header);
  const findLink = () => wrapper.findComponent(GlLink);
  const findProtectionRows = () => wrapper.findAllComponents(ProtectionRow);

  it('renders a card component', () => {
    expect(findCard().exists()).toBe(true);
  });

  it('renders a header with a link', () => {
    expect(findHeader().exists()).toBe(true);
    expect(findLink().text()).toBe(protectionPropsMock.headerLinkTitle);
    expect(findLink().attributes('href')).toBe(protectionPropsMock.headerLinkHref);
  });

  it('renders a protection row for roles', () => {
    expect(findProtectionRows().at(0).props()).toMatchObject({
      accessLevels: protectionPropsMock.roles,
      showDivider: false,
      title: i18n.rolesTitle,
    });
  });

  it('renders a protection row for users', () => {
    expect(findProtectionRows().at(1).props()).toMatchObject({
      users: protectionPropsMock.users,
      showDivider: true,
      title: i18n.usersTitle,
    });
  });

  it('renders a protection row for groups', () => {
    expect(findProtectionRows().at(2).props()).toMatchObject({
      accessLevels: protectionPropsMock.groups,
      showDivider: true,
      title: i18n.groupsTitle,
    });
  });

  it('renders a protection row for approvals', () => {
    const approval = protectionPropsMock.approvals[0];
    expect(findProtectionRows().at(3).props()).toMatchObject({
      title: approval.name,
      users: approval.eligibleApprovers.nodes,
      approvalsRequired: approval.approvalsRequired,
    });
  });
});