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

group_folder_spec.js « components « groups « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d8e10479b6467f8d9f2a05471ee3c70530a7206 (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
import Vue from 'vue';

import groupFolderComponent from '~/groups/components/group_folder.vue';
import groupItemComponent from '~/groups/components/group_item.vue';
import { mockGroups, mockParentGroupItem } from '../mock_data';

const createComponent = (groups = mockGroups, parentGroup = mockParentGroupItem) => {
  const Component = Vue.extend(groupFolderComponent);

  return new Component({
    propsData: {
      groups,
      parentGroup,
    },
  });
};

describe('GroupFolderComponent', () => {
  let vm;

  beforeEach(() => {
    Vue.component('GroupItem', groupItemComponent);

    vm = createComponent();
    vm.$mount();

    return Vue.nextTick();
  });

  afterEach(() => {
    vm.$destroy();
  });

  describe('computed', () => {
    describe('hasMoreChildren', () => {
      it('should return false when childrenCount of group is less than MAX_CHILDREN_COUNT', () => {
        expect(vm.hasMoreChildren).toBeFalsy();
      });
    });

    describe('moreChildrenStats', () => {
      it('should return message with count of excess children over MAX_CHILDREN_COUNT limit', () => {
        expect(vm.moreChildrenStats).toBe('3 more items');
      });
    });
  });

  describe('template', () => {
    it('should render component template correctly', () => {
      expect(vm.$el.classList.contains('group-list-tree')).toBeTruthy();
      expect(vm.$el.querySelectorAll('li.group-row').length).toBe(7);
    });

    it('should render more children link when groups list has children over MAX_CHILDREN_COUNT limit', () => {
      const parentGroup = { ...mockParentGroupItem };
      parentGroup.childrenCount = 21;

      const newVm = createComponent(mockGroups, parentGroup);
      newVm.$mount();

      expect(newVm.$el.querySelector('li.group-row a.has-more-items')).toBeDefined();
      newVm.$destroy();
    });
  });
});