summaryrefslogtreecommitdiff
path: root/spec/javascripts/groups/group_item_spec.js
blob: 78eeface95cc0d8957991e5cc4754c6a1e314eab (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import Vue from 'vue';
import groupItemComponent from '~/groups/components/group_item.vue';
import GroupsStore from '~/groups/stores/groups_store';
import { group1 } from './mock_data';

describe('Groups Component', () => {
  let GroupItemComponent;
  let component;
  let store;
  let group;

  describe('group with default data', () => {
    beforeEach((done) => {
      GroupItemComponent = Vue.extend(groupItemComponent);
      store = new GroupsStore();
      group = store.decorateGroup(group1);

      component = new GroupItemComponent({
        propsData: {
          group,
        },
      }).$mount();

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

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

    it('should render the group item correctly', () => {
      expect(component.$el.classList.contains('group-row')).toBe(true);
      expect(component.$el.classList.contains('.no-description')).toBe(false);
      expect(component.$el.querySelector('.number-subgroups').textContent).toContain(group.subGroupCount);
      expect(component.$el.querySelector('.number-projects').textContent).toContain(group.numberProjects);
      expect(component.$el.querySelector('.number-users').textContent).toContain(group.numberUsers);
      expect(component.$el.querySelector('.group-visibility')).toBeDefined();
      expect(component.$el.querySelector('.avatar-container')).toBeDefined();
      expect(component.$el.querySelector('.title').textContent).toContain(group.name);
      expect(component.$el.querySelector('.access-type').textContent).toContain(group.permissions.humanGroupAccess);
      expect(component.$el.querySelector('.description').textContent).toContain(group.description);
      expect(component.$el.querySelector('.edit-group')).toBeDefined();
      expect(component.$el.querySelector('.leave-group')).toBeDefined();
    });

    it('should render tooltips on group item correctly', () => {
      expect(component.$el.querySelector('.number-subgroups').dataset.originalTitle).toContain('Subgroups');
      expect(component.$el.querySelector('.number-projects').dataset.originalTitle).toContain('Projects');
      expect(component.$el.querySelector('.number-users').dataset.originalTitle).toContain('Members');
      expect(component.$el.querySelector('.group-visibility').dataset.originalTitle).toContain('Public');
    });
  });

  describe('group without description', () => {
    beforeEach((done) => {
      GroupItemComponent = Vue.extend(groupItemComponent);
      store = new GroupsStore();
      group1.description = '';
      group = store.decorateGroup(group1);

      component = new GroupItemComponent({
        propsData: {
          group,
        },
      }).$mount();

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

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

    it('should render group item correctly', () => {
      expect(component.$el.querySelector('.description')).toBe(null);
      expect(component.$el.classList.contains('.no-description')).toBe(false);
    });
  });

  describe('user has not access to group', () => {
    beforeEach((done) => {
      GroupItemComponent = Vue.extend(groupItemComponent);
      store = new GroupsStore();
      group1.permissions.human_group_access = null;
      group = store.decorateGroup(group1);

      component = new GroupItemComponent({
        propsData: {
          group,
        },
      }).$mount();

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

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

    it('should not display access type', () => {
      expect(component.$el.querySelector('.access-type')).toBeNull();
    });
  });

  describe('group with projects', () => {
    beforeEach((done) => {
      GroupItemComponent = Vue.extend(groupItemComponent);
      store = new GroupsStore();
      group1.permissions.human_group_access = null;
      group = store.decorateGroup(group1);
      group.isOpen = true;

      component = new GroupItemComponent({
        propsData: {
          group,
        },
      }).$mount();

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

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

    it('should render projects list correctly', () => {
      expect(component.$el.querySelector('.group-list-tree.project-list')).toBeDefined();
      expect(component.$el.querySelectorAll('.group-list-tree.project-list .project-row').length).toBe(1);
    });
  });
});