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

sidebar_menu_spec.js « components « super_sidebar « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 26b146f0c8ba1cd227598430e7580bf0b9d2a96f (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { mountExtended } from 'helpers/vue_test_utils_helper';
import SidebarMenu from '~/super_sidebar/components/sidebar_menu.vue';
import { PANELS_WITH_PINS } from '~/super_sidebar/constants';
import { sidebarData } from '../mock_data';

describe('SidebarMenu component', () => {
  let wrapper;

  const createWrapper = (mockData) => {
    wrapper = mountExtended(SidebarMenu, {
      propsData: {
        items: mockData.current_menu_items,
        pinnedItemIds: mockData.pinned_items,
        panelType: mockData.panel_type,
        updatePinsUrl: mockData.update_pins_url,
      },
    });
  };

  describe('computed', () => {
    const menuItems = [
      { id: 1, title: 'No subitems' },
      { id: 2, title: 'With subitems', items: [{ id: 21, title: 'Pinned subitem' }] },
      { id: 3, title: 'Empty subitems array', items: [] },
      { id: 4, title: 'Also with subitems', items: [{ id: 41, title: 'Subitem' }] },
    ];

    describe('supportsPins', () => {
      it('is true for the project sidebar', () => {
        createWrapper({ ...sidebarData, panel_type: 'project' });
        expect(wrapper.vm.supportsPins).toBe(true);
      });

      it('is true for the group sidebar', () => {
        createWrapper({ ...sidebarData, panel_type: 'group' });
        expect(wrapper.vm.supportsPins).toBe(true);
      });

      it('is false for any other sidebar', () => {
        createWrapper({ ...sidebarData, panel_type: 'your_work' });
        expect(wrapper.vm.supportsPins).toEqual(false);
      });
    });

    describe('flatPinnableItems', () => {
      it('returns all subitems in a flat array', () => {
        createWrapper({ ...sidebarData, current_menu_items: menuItems });
        expect(wrapper.vm.flatPinnableItems).toEqual([
          { id: 21, title: 'Pinned subitem' },
          { id: 41, title: 'Subitem' },
        ]);
      });
    });

    describe('staticItems', () => {
      describe('when the sidebar supports pins', () => {
        beforeEach(() => {
          createWrapper({
            ...sidebarData,
            current_menu_items: menuItems,
            panel_type: PANELS_WITH_PINS[0],
          });
        });

        it('makes everything that has no subitems a static item', () => {
          expect(wrapper.vm.staticItems.map((i) => i.title)).toEqual([
            'No subitems',
            'Empty subitems array',
          ]);
        });
      });

      describe('when the sidebar does not support pins', () => {
        beforeEach(() => {
          createWrapper({
            ...sidebarData,
            current_menu_items: menuItems,
            panel_type: 'explore',
          });
        });

        it('returns an empty array', () => {
          expect(wrapper.vm.staticItems.map((i) => i.title)).toEqual([]);
        });
      });
    });

    describe('nonStaticItems', () => {
      describe('when the sidebar supports pins', () => {
        beforeEach(() => {
          createWrapper({
            ...sidebarData,
            current_menu_items: menuItems,
            panel_type: PANELS_WITH_PINS[0],
          });
        });

        it('keeps items that have subitems (aka "sections") as non-static', () => {
          expect(wrapper.vm.nonStaticItems.map((i) => i.title)).toEqual([
            'With subitems',
            'Also with subitems',
          ]);
        });
      });

      describe('when the sidebar does not support pins', () => {
        beforeEach(() => {
          createWrapper({
            ...sidebarData,
            current_menu_items: menuItems,
            panel_type: 'explore',
          });
        });

        it('keeps all items as non-static', () => {
          expect(wrapper.vm.nonStaticItems).toEqual(menuItems);
        });
      });
    });

    describe('pinnedItems', () => {
      describe('when user has no pinned item ids stored', () => {
        beforeEach(() => {
          createWrapper({
            ...sidebarData,
            current_menu_items: menuItems,
            pinned_items: [],
          });
        });

        it('returns an empty array', () => {
          expect(wrapper.vm.pinnedItems).toEqual([]);
        });
      });

      describe('when user has some pinned item ids stored', () => {
        beforeEach(() => {
          createWrapper({
            ...sidebarData,
            current_menu_items: menuItems,
            pinned_items: [21],
          });
        });

        it('returns the items matching the pinned ids', () => {
          expect(wrapper.vm.pinnedItems).toEqual([{ id: 21, title: 'Pinned subitem' }]);
        });
      });
    });
  });
});