summaryrefslogtreecommitdiff
path: root/spec/javascripts/groups/components/group_folder_spec.js
blob: 4eb198595fb96a8ac0e378cbaf879b5adde5ddf1 (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
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((done) => {
    Vue.component('group-item', groupItemComponent);

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

    Vue.nextTick(() => {
      done();
    });
  });

  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 = Object.assign({}, 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();
    });
  });
});