BigW Consortium Gitlab

group_item_spec.js 3.04 KB
Newer Older
1 2 3 4 5
import Vue from 'vue';
import groupItemComponent from '~/groups/components/group_item.vue';
import GroupsStore from '~/groups/stores/groups_store';
import { group1 } from './mock_data';

Alfredo Sumaran committed
6
describe('Groups Component', () => {
7 8
  let GroupItemComponent;
  let component;
9
  let store;
10 11
  let group;

Alfredo Sumaran committed
12 13 14 15 16
  describe('group with default data', () => {
    beforeEach((done) => {
      GroupItemComponent = Vue.extend(groupItemComponent);
      store = new GroupsStore();
      group = store.decorateGroup(group1);
17

Alfredo Sumaran committed
18 19 20 21 22
      component = new GroupItemComponent({
        propsData: {
          group,
        },
      }).$mount();
23

Alfredo Sumaran committed
24 25 26
      Vue.nextTick(() => {
        done();
      });
27 28
    });

Alfredo Sumaran committed
29 30 31 32
    afterEach(() => {
      component.$destroy();
    });

Alfredo Sumaran committed
33 34 35 36 37 38 39 40
    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);
41
      expect(component.$el.querySelector('.access-type').textContent).toContain(group.permissions.humanGroupAccess);
Alfredo Sumaran committed
42 43 44 45
      expect(component.$el.querySelector('.description').textContent).toContain(group.description);
      expect(component.$el.querySelector('.edit-group')).toBeDefined();
      expect(component.$el.querySelector('.leave-group')).toBeDefined();
    });
46 47
  });

Alfredo Sumaran committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  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();
      });
    });

66 67 68 69
    afterEach(() => {
      component.$destroy();
    });

Alfredo Sumaran committed
70 71 72 73 74
    it('should render group item correctly', () => {
      expect(component.$el.querySelector('.description').textContent).toBe('');
      expect(component.$el.classList.contains('.no-description')).toBe(false);
    });
  });
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

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