Welcome to mirror list, hosted at ThFree Co, Russian Federation.

item_stats_value_spec.js « components « groups « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b9db83c7dd7d0ae3e909ba48aadbcda0af64ec25 (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
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import ItemStatsValue from '~/groups/components/item_stats_value.vue';

describe('ItemStatsValue', () => {
  let wrapper;

  const defaultProps = {
    title: 'Subgroups',
    cssClass: 'number-subgroups',
    iconName: 'folder',
    tooltipPlacement: 'left',
  };

  const createComponent = (props = {}) => {
    wrapper = shallowMount(ItemStatsValue, {
      propsData: { ...defaultProps, ...props },
    });
  };

  afterEach(() => {
    if (wrapper) {
      wrapper.destroy();
      wrapper = null;
    }
  });

  const findGlIcon = () => wrapper.findComponent(GlIcon);
  const findStatValue = () => wrapper.find('[data-testid="itemStatValue"]');

  describe('template', () => {
    describe('when `value` is not provided', () => {
      it('does not render value count', () => {
        createComponent();

        expect(findStatValue().exists()).toBe(false);
      });
    });

    describe('when `value` is provided', () => {
      beforeEach(() => {
        createComponent({
          value: 10,
        });
      });

      it('renders component element correctly', () => {
        expect(wrapper.classes()).toContain('number-subgroups');
      });

      it('renders element tooltip correctly', () => {
        expect(wrapper.attributes('title')).toBe('Subgroups');
        expect(wrapper.attributes('data-placement')).toBe('left');
      });

      it('renders element icon correctly', () => {
        expect(findGlIcon().exists()).toBe(true);
        expect(findGlIcon().props('name')).toBe('folder');
      });

      it('renders value count correctly', () => {
        expect(findStatValue().classes()).toContain('stat-value');
        expect(findStatValue().text()).toBe('10');
      });
    });
  });
});