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

scope_navigation_spec.js « components « sidebar « search « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 23c158239dc8c714e38e5ff0966d8d1e295445f6 (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 { GlNav, GlNavItem, GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import { MOCK_QUERY, MOCK_NAVIGATION } from 'jest/search/mock_data';
import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue';

Vue.use(Vuex);

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

  const actionSpies = {
    fetchSidebarCount: jest.fn(),
  };

  const createComponent = (initialState) => {
    const store = new Vuex.Store({
      state: {
        urlQuery: MOCK_QUERY,
        navigation: MOCK_NAVIGATION,
        ...initialState,
      },
      actions: actionSpies,
    });

    wrapper = shallowMount(ScopeNavigation, {
      store,
    });
  };

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

  const findNavElement = () => wrapper.find('nav');
  const findGlNav = () => wrapper.findComponent(GlNav);
  const findGlNavItems = () => wrapper.findAllComponents(GlNavItem);
  const findGlNavItemActive = () => findGlNavItems().wrappers.filter((w) => w.attributes('active'));
  const findGlNavItemActiveLabel = () => findGlNavItemActive().at(0).findAll('span').at(0).text();
  const findGlNavItemActiveCount = () => findGlNavItemActive().at(0).findAll('span').at(1);

  describe('scope navigation', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders section', () => {
      expect(findNavElement().exists()).toBe(true);
    });

    it('renders nav component', () => {
      expect(findGlNav().exists()).toBe(true);
    });

    it('renders all nav item components', () => {
      expect(findGlNavItems()).toHaveLength(9);
    });

    it('has all proper links', () => {
      const linkAtPosition = 3;
      const { link } = MOCK_NAVIGATION[Object.keys(MOCK_NAVIGATION)[linkAtPosition]];

      expect(findGlNavItems().at(linkAtPosition).attributes('href')).toBe(link);
    });
  });

  describe('scope navigation sets proper state with url scope set', () => {
    beforeEach(() => {
      createComponent();
    });

    it('has correct active item', () => {
      expect(findGlNavItemActive()).toHaveLength(1);
      expect(findGlNavItemActiveLabel()).toBe('Issues');
    });

    it('has correct active item count', () => {
      expect(findGlNavItemActiveCount().text()).toBe('2.4K');
    });

    it('does not have plus sign after count text', () => {
      expect(findGlNavItemActive().at(0).findComponent(GlIcon).exists()).toBe(false);
    });

    it('has count is highlighted correctly', () => {
      expect(findGlNavItemActiveCount().classes('gl-text-gray-900')).toBe(true);
    });
  });

  describe('scope navigation sets proper state with NO url scope set', () => {
    beforeEach(() => {
      createComponent({
        urlQuery: {},
      });
    });

    it('has correct active item', () => {
      expect(findGlNavItems().at(0).attributes('active')).toBe('true');
      expect(findGlNavItemActiveLabel()).toBe('Projects');
    });

    it('has correct active item count', () => {
      expect(findGlNavItemActiveCount().text()).toBe('10K');
    });

    it('has correct active item count and over limit sign', () => {
      expect(findGlNavItemActive().at(0).findComponent(GlIcon).exists()).toBe(true);
    });
  });
});