summaryrefslogtreecommitdiff
path: root/spec/javascripts/groups/group_item_spec.js
blob: 64b0f31e435342105709cee6c089d6551f8b3c7c (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 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();
      });
    });

    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-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('.description').textContent).toContain(group.description);
      expect(component.$el.querySelector('.edit-group')).toBeDefined();
      expect(component.$el.querySelector('.leave-group')).toBeDefined();
    });
  });

  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();
      });
    });

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