summaryrefslogtreecommitdiff
path: root/spec/javascripts/groups/groups_spec.js
blob: 47ca90551c75c9371745a556ad51c6a916e572d7 (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
import Vue from 'vue';
import groupFolderComponent from '~/groups/components/group_folder.vue';
import groupItemComponent from '~/groups/components/group_item.vue';
import groupsComponent from '~/groups/components/groups.vue';
import GroupsStore from '~/groups/stores/groups_store';
import { groupsData } from './mock_data';

describe('Groups Component', () => {
  let GroupsComponent;
  let store;
  let component;
  let groups;

  beforeEach((done) => {
    Vue.component('group-folder', groupFolderComponent);
    Vue.component('group-item', groupItemComponent);

    store = new GroupsStore();
    groups = store.setGroups(groupsData.groups);

    store.storePagination(groupsData.pagination);

    GroupsComponent = Vue.extend(groupsComponent);

    component = new GroupsComponent({
      propsData: {
        groups: store.state.groups,
        pageInfo: store.state.pageInfo,
      },
    }).$mount();

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

  describe('with data', () => {
    it('should render a list of groups', () => {
      expect(component.$el.classList.contains('groups-list-tree-container')).toBe(true);
      expect(component.$el.querySelector('#group-12')).toBeDefined();
      expect(component.$el.querySelector('#group-1119')).toBeDefined();
      expect(component.$el.querySelector('#group-1120')).toBeDefined();
    });

    it('should render group and its subgroup', () => {
      const lists = component.$el.querySelectorAll('.group-list-tree');

      expect(lists.length).toBe(3); // one parent and two subgroups

      expect(lists[0].querySelector('#group-1119').classList.contains('is-open')).toBe(true);
      expect(lists[0].querySelector('#group-1119').classList.contains('is-expandable')).toBe(true);

      expect(lists[2].querySelector('#group-1120').textContent).toContain(groups[1119].subGroups[1120].name);
    });

    it('should remove prefix of parent group', () => {
      expect(component.$el.querySelector('#group-12 #group-1128 .title').textContent).toContain('level2 / level3 / level4');
    });
  });
});