item_stats_spec.js 4.31 KB
Newer Older
1 2 3
import Vue from 'vue';

import itemStatsComponent from '~/groups/components/item_stats.vue';
4
import mountComponent from 'spec/helpers/vue_mount_component_helper';
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
import {
  mockParentGroupItem,
  ITEM_TYPE,
  VISIBILITY_TYPE_ICON,
  GROUP_VISIBILITY_TYPE,
  PROJECT_VISIBILITY_TYPE,
} from '../mock_data';

const createComponent = (item = mockParentGroupItem) => {
  const Component = Vue.extend(itemStatsComponent);

  return mountComponent(Component, {
    item,
  });
};

describe('ItemStatsComponent', () => {
  describe('computed', () => {
    describe('visibilityIcon', () => {
      it('should return icon class based on `item.visibility` value', () => {
        Object.keys(VISIBILITY_TYPE_ICON).forEach((visibility) => {
          const item = Object.assign({}, mockParentGroupItem, { visibility });
          const vm = createComponent(item);
          expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]);
          vm.$destroy();
        });
      });
    });

    describe('visibilityTooltip', () => {
      it('should return tooltip string for Group based on `item.visibility` value', () => {
        Object.keys(GROUP_VISIBILITY_TYPE).forEach((visibility) => {
          const item = Object.assign({}, mockParentGroupItem, {
            visibility,
            type: ITEM_TYPE.GROUP,
          });
          const vm = createComponent(item);
          expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]);
          vm.$destroy();
        });
      });

      it('should return tooltip string for Project based on `item.visibility` value', () => {
        Object.keys(PROJECT_VISIBILITY_TYPE).forEach((visibility) => {
          const item = Object.assign({}, mockParentGroupItem, {
            visibility,
            type: ITEM_TYPE.PROJECT,
          });
          const vm = createComponent(item);
          expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]);
          vm.$destroy();
        });
      });
    });

    describe('isProject', () => {
      it('should return boolean value representing whether `item.type` is Project or not', () => {
        let item;
        let vm;

        item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT });
        vm = createComponent(item);
        expect(vm.isProject).toBeTruthy();
        vm.$destroy();

        item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP });
        vm = createComponent(item);
        expect(vm.isProject).toBeFalsy();
        vm.$destroy();
      });
    });

    describe('isGroup', () => {
      it('should return boolean value representing whether `item.type` is Group or not', () => {
        let item;
        let vm;

        item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP });
        vm = createComponent(item);
        expect(vm.isGroup).toBeTruthy();
        vm.$destroy();

        item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT });
        vm = createComponent(item);
        expect(vm.isGroup).toBeFalsy();
        vm.$destroy();
      });
    });
  });

  describe('template', () => {
96
    it('renders component container element correctly', () => {
97 98
      const vm = createComponent();

99
      expect(vm.$el.classList.contains('stats')).toBeTruthy();
100 101 102 103

      vm.$destroy();
    });

104 105 106 107 108 109 110
    it('renders item visibility icon and tooltip correctly', () => {
      const vm = createComponent();

      const visibilityIconEl = vm.$el.querySelector('.item-visibility');
      expect(visibilityIconEl).not.toBe(null);
      expect(visibilityIconEl.dataset.originalTitle).toBe(vm.visibilityTooltip);
      expect(visibilityIconEl.querySelectorAll('svg').length > 0).toBeTruthy();
111 112 113 114

      vm.$destroy();
    });

115
    it('renders start count and last updated information for project item correctly', () => {
116 117 118 119 120 121 122
      const item = Object.assign({}, mockParentGroupItem, {
        type: ITEM_TYPE.PROJECT,
        starCount: 4,
      });
      const vm = createComponent(item);

      const projectStarIconEl = vm.$el.querySelector('.project-stars');
123 124 125 126
      expect(projectStarIconEl).not.toBe(null);
      expect(projectStarIconEl.querySelectorAll('svg').length > 0).toBeTruthy();
      expect(projectStarIconEl.querySelectorAll('.stat-value').length > 0).toBeTruthy();
      expect(vm.$el.querySelectorAll('.last-updated').length > 0).toBeTruthy();
127 128 129 130 131

      vm.$destroy();
    });
  });
});