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

protection_row_spec.js « view « components « branch_rules « settings « projects « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0a69bedd3e0a691f87891d7ed8a01ba5a37ca85 (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 { GlAvatarsInline, GlAvatar, GlAvatarLink } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ProtectionRow, {
  MAX_VISIBLE_AVATARS,
  AVATAR_SIZE,
} from '~/projects/settings/branch_rules/components/view/protection_row.vue';
import { protectionRowPropsMock } from './mock_data';

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

  const createComponent = () => {
    wrapper = shallowMountExtended(ProtectionRow, {
      propsData: protectionRowPropsMock,
      stubs: { GlAvatarsInline },
    });
  };

  beforeEach(() => createComponent());

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

  const findTitle = () => wrapper.findByText(protectionRowPropsMock.title);
  const findAvatarsInline = () => wrapper.findComponent(GlAvatarsInline);
  const findAvatarLinks = () => wrapper.findAllComponents(GlAvatarLink);
  const findAvatars = () => wrapper.findAllComponents(GlAvatar);
  const findAccessLevels = () => wrapper.findAllByTestId('access-level');
  const findApprovalsRequired = () =>
    wrapper.findByText(`${protectionRowPropsMock.approvalsRequired} approvals required`);

  it('renders a title', () => {
    expect(findTitle().exists()).toBe(true);
  });

  it('renders an avatars-inline component', () => {
    expect(findAvatarsInline().props('avatars')).toMatchObject(protectionRowPropsMock.users);
    expect(findAvatarsInline().props('badgeSrOnlyText')).toBe('1 additional user');
  });

  it('renders avatar-link components', () => {
    expect(findAvatarLinks().length).toBe(MAX_VISIBLE_AVATARS);

    expect(findAvatarLinks().at(1).attributes('href')).toBe(protectionRowPropsMock.users[1].webUrl);
    expect(findAvatarLinks().at(1).attributes('title')).toBe(protectionRowPropsMock.users[1].name);
  });

  it('renders avatar components', () => {
    expect(findAvatars().length).toBe(MAX_VISIBLE_AVATARS);

    expect(findAvatars().at(1).attributes('src')).toBe(protectionRowPropsMock.users[1].avatarUrl);
    expect(findAvatars().at(1).attributes('label')).toBe(protectionRowPropsMock.users[1].name);
    expect(findAvatars().at(1).props('size')).toBe(AVATAR_SIZE);
  });

  it('renders access level descriptions', () => {
    expect(findAccessLevels().length).toBe(protectionRowPropsMock.accessLevels.length);

    expect(findAccessLevels().at(0).text()).toBe(
      protectionRowPropsMock.accessLevels[0].accessLevelDescription,
    );
    expect(findAccessLevels().at(1).text()).toContain(',');

    expect(findAccessLevels().at(1).text()).toContain(
      protectionRowPropsMock.accessLevels[1].accessLevelDescription,
    );
  });

  it('renders the number of approvals required', () => {
    expect(findApprovalsRequired().exists()).toBe(true);
  });
});