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

issuable_tabs_spec.js « components « list « issuable « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27985895c62b6d973cd9f0de3ab49087b9c5a488 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { GlTab, GlBadge } from '@gitlab/ui';
import { nextTick } from 'vue';
import { mount, shallowMount } from '@vue/test-utils';
import { setLanguage } from 'helpers/locale_helper';

import IssuableTabs from '~/vue_shared/issuable/list/components/issuable_tabs.vue';

import { mockIssuableListProps } from '../mock_data';

const createComponent = ({
  tabs = mockIssuableListProps.tabs,
  tabCounts = mockIssuableListProps.tabCounts,
  currentTab = mockIssuableListProps.currentTab,
  truncateCounts = false,
  mountFn = shallowMount,
} = {}) =>
  mountFn(IssuableTabs, {
    propsData: {
      tabs,
      tabCounts,
      currentTab,
      truncateCounts,
    },
    slots: {
      'nav-actions': `<button class="js-new-issuable">New issuable</button>`,
    },
  });

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

  beforeEach(() => {
    setLanguage('en');
  });

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

  const findAllGlBadges = () => wrapper.findAllComponents(GlBadge);
  const findAllGlTabs = () => wrapper.findAllComponents(GlTab);

  describe('tabs', () => {
    it.each`
      currentTab  | returnValue
      ${'opened'} | ${'true'}
      ${'closed'} | ${undefined}
    `(
      'when "$currentTab" is the selected tab, the Open tab is active=$returnValue',
      ({ currentTab, returnValue }) => {
        wrapper = createComponent({ currentTab });

        const openTab = findAllGlTabs().at(0);

        expect(openTab.attributes('active')).toBe(returnValue);
      },
    );
  });

  describe('template', () => {
    it('renders gl-tab for each tab within `tabs` array', () => {
      wrapper = createComponent();

      const tabs = findAllGlTabs();

      expect(tabs).toHaveLength(mockIssuableListProps.tabs.length);
    });

    it('renders gl-badge component within a tab', async () => {
      wrapper = createComponent({ mountFn: mount });
      await nextTick();

      const badges = findAllGlBadges();

      // Does not render `All` badge since it has an undefined count
      expect(badges).toHaveLength(2);
      expect(badges.at(0).text()).toBe('5,678');
      expect(badges.at(1).text()).toBe(`${mockIssuableListProps.tabCounts.closed}`);
    });

    it('renders contents for slot "nav-actions"', () => {
      wrapper = createComponent();

      const button = wrapper.find('button.js-new-issuable');

      expect(button.text()).toBe('New issuable');
    });
  });

  describe('counts', () => {
    it('can display as truncated', async () => {
      wrapper = createComponent({ truncateCounts: true, mountFn: mount });
      await nextTick();

      expect(findAllGlBadges().at(0).text()).toBe('5.7k');
    });
  });

  describe('events', () => {
    it('gl-tab component emits `click` event on `click` event', () => {
      wrapper = createComponent();

      const openTab = findAllGlTabs().at(0);

      openTab.vm.$emit('click', 'opened');

      expect(wrapper.emitted('click')).toEqual([['opened']]);
    });
  });
});