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

menu_section_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: 288e317d4c6e4f3d7130e036eabad2031c387f83 (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
152
153
154
155
156
157
import { GlCollapse } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import MenuSection from '~/super_sidebar/components/menu_section.vue';
import NavItem from '~/super_sidebar/components/nav_item.vue';
import FlyoutMenu from '~/super_sidebar/components/flyout_menu.vue';
import { stubComponent } from 'helpers/stub_component';

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

  const findButton = () => wrapper.find('button');
  const findCollapse = () => wrapper.getComponent(GlCollapse);
  const findFlyout = () => wrapper.findComponent(FlyoutMenu);
  const findNavItems = () => wrapper.findAllComponents(NavItem);
  const createWrapper = (item, otherProps) => {
    wrapper = shallowMountExtended(MenuSection, {
      propsData: { item: { items: [], ...item }, ...otherProps },
      stubs: {
        GlCollapse: stubComponent(GlCollapse, {
          props: ['visible'],
        }),
      },
    });
  };

  it('renders its title', () => {
    createWrapper({ title: 'Asdf' });
    expect(findButton().text()).toBe('Asdf');
  });

  it('renders all its subitems', () => {
    createWrapper({
      title: 'Asdf',
      items: [
        { title: 'Item1', href: '/item1' },
        { title: 'Item2', href: '/item2' },
      ],
    });
    expect(findNavItems().length).toBe(2);
  });

  it('associates button with list with aria-controls', () => {
    createWrapper({ title: 'Asdf' });
    expect(findButton().attributes('aria-controls')).toBe('asdf');
    expect(findCollapse().attributes('id')).toBe('asdf');
  });

  describe('collapse behavior', () => {
    describe('when active', () => {
      it('is expanded', () => {
        createWrapper({ title: 'Asdf', is_active: true });
        expect(findCollapse().props('visible')).toBe(true);
      });
    });

    describe('when set to expanded', () => {
      it('is expanded', () => {
        createWrapper({ title: 'Asdf' }, { expanded: true });
        expect(findButton().attributes('aria-expanded')).toBe('true');
        expect(findCollapse().props('visible')).toBe(true);
      });
    });

    describe('when not active nor set to expanded', () => {
      it('is not expanded', () => {
        createWrapper({ title: 'Asdf' });
        expect(findButton().attributes('aria-expanded')).toBe('false');
        expect(findCollapse().props('visible')).toBe(false);
      });
    });
  });

  describe('flyout behavior', () => {
    describe('when hasFlyout is false', () => {
      it('is not rendered', () => {
        createWrapper({ title: 'Asdf' }, { 'has-flyout': false });
        expect(findFlyout().exists()).toBe(false);
      });
    });

    describe('when hasFlyout is true', () => {
      it('is rendered', () => {
        createWrapper({ title: 'Asdf' }, { 'has-flyout': true });
        expect(findFlyout().exists()).toBe(true);
      });

      describe('on mouse hover', () => {
        describe('when section is expanded', () => {
          it('is not shown', async () => {
            createWrapper({ title: 'Asdf' }, { 'has-flyout': true, expanded: true });
            await findButton().trigger('pointerover', { pointerType: 'mouse' });
            expect(findFlyout().isVisible()).toBe(false);
          });
        });

        describe('when section is not expanded', () => {
          it('is shown', async () => {
            createWrapper({ title: 'Asdf' }, { 'has-flyout': true, expanded: false });
            await findButton().trigger('pointerover', { pointerType: 'mouse' });
            expect(findFlyout().isVisible()).toBe(true);
          });
        });
      });

      describe('when section gets closed', () => {
        beforeEach(async () => {
          createWrapper({ title: 'Asdf' }, { expanded: true, 'has-flyout': true });
          await findButton().trigger('click');
          await findButton().trigger('pointerover', { pointerType: 'mouse' });
        });

        it('shows the flyout only after section title gets hovered out and in again', async () => {
          expect(findCollapse().props('visible')).toBe(false);
          expect(findFlyout().isVisible()).toBe(false);

          await findButton().trigger('pointerleave');
          await findButton().trigger('pointerover', { pointerType: 'mouse' });

          expect(findCollapse().props('visible')).toBe(false);
          expect(findFlyout().isVisible()).toBe(true);
        });
      });
    });
  });

  describe('`separated` prop', () => {
    describe('by default (false)', () => {
      it('does not render a separator', () => {
        createWrapper({ title: 'Asdf' });
        expect(wrapper.find('hr').exists()).toBe(false);
      });
    });

    describe('when set to true', () => {
      it('does render a separator', () => {
        createWrapper({ title: 'Asdf' }, { separated: true });
        expect(wrapper.find('hr').exists()).toBe(true);
      });
    });
  });

  describe('`tag` prop', () => {
    describe('by default', () => {
      it('renders as <div> tag', () => {
        createWrapper({ title: 'Asdf' });
        expect(wrapper.element.tagName).toBe('DIV');
      });
    });

    describe('when set to "li"', () => {
      it('renders as <li> tag', () => {
        createWrapper({ title: 'Asdf' }, { tag: 'li' });
        expect(wrapper.element.tagName).toBe('LI');
      });
    });
  });
});