summaryrefslogtreecommitdiff
path: root/spec/javascripts/groups/components/item_stats_value_spec.js
blob: 5e35ae4d36cf89a149439ab07d6ea3c2dd6351fe (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
import Vue from 'vue';

import itemStatsValueComponent from '~/groups/components/item_stats_value.vue';

import mountComponent from 'spec/helpers/vue_mount_component_helper';

const createComponent = ({ title, cssClass, iconName, tooltipPlacement, value }) => {
  const Component = Vue.extend(itemStatsValueComponent);

  return mountComponent(Component, {
    title,
    cssClass,
    iconName,
    tooltipPlacement,
    value,
  });
};

describe('ItemStatsValueComponent', () => {
  describe('computed', () => {
    let vm;
    const itemConfig = {
      title: 'Subgroups',
      cssClass: 'number-subgroups',
      iconName: 'folder',
      tooltipPlacement: 'left',
    };

    describe('isValuePresent', () => {
      it('returns true if non-empty `value` is present', () => {
        vm = createComponent(Object.assign({}, itemConfig, { value: 10 }));
        expect(vm.isValuePresent).toBeTruthy();
      });

      it('returns false if empty `value` is present', () => {
        vm = createComponent(itemConfig);
        expect(vm.isValuePresent).toBeFalsy();
      });

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

  describe('template', () => {
    let vm;
    beforeEach(() => {
      vm = createComponent({
        title: 'Subgroups',
        cssClass: 'number-subgroups',
        iconName: 'folder',
        tooltipPlacement: 'left',
        value: 10,
      });
    });

    it('renders component element correctly', () => {
      expect(vm.$el.classList.contains('number-subgroups')).toBeTruthy();
      expect(vm.$el.querySelectorAll('svg').length > 0).toBeTruthy();
      expect(vm.$el.querySelectorAll('.stat-value').length > 0).toBeTruthy();
    });

    it('renders element tooltip correctly', () => {
      expect(vm.$el.dataset.originalTitle).toBe('Subgroups');
      expect(vm.$el.dataset.placement).toBe('left');
    });

    it('renders element icon correctly', () => {
      expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('folder');
    });

    it('renders value count correctly', () => {
      expect(vm.$el.querySelector('.stat-value').innerText.trim()).toContain('10');
    });

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