summaryrefslogtreecommitdiff
path: root/spec/frontend/jobs/bridge/components/sidebar_spec.js
blob: ba4018753affd440ba8d442d89494144815d4c35 (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
import { GlButton, GlDropdown } from '@gitlab/ui';
import { GlBreakpointInstance } from '@gitlab/ui/dist/utils';
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
import BridgeSidebar from '~/jobs/bridge/components/sidebar.vue';
import { BUILD_NAME } from '../mock_data';

describe('Bridge Sidebar', () => {
  let wrapper;

  const createComponent = () => {
    wrapper = shallowMount(BridgeSidebar, {
      provide: {
        buildName: BUILD_NAME,
      },
    });
  };

  const findSidebar = () => wrapper.find('aside');
  const findRetryDropdown = () => wrapper.find(GlDropdown);
  const findToggle = () => wrapper.find(GlButton);

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

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

    it('renders retry dropdown', () => {
      expect(findRetryDropdown().exists()).toBe(true);
    });
  });

  describe('sidebar expansion', () => {
    beforeEach(() => {
      createComponent();
    });

    it('toggles expansion on button click', async () => {
      expect(findSidebar().classes()).not.toContain('gl-display-none');

      findToggle().vm.$emit('click');
      await nextTick();

      expect(findSidebar().classes()).toContain('gl-display-none');
    });

    describe('on resize', () => {
      it.each`
        breakpoint | isSidebarExpanded
        ${'xs'}    | ${false}
        ${'sm'}    | ${false}
        ${'md'}    | ${true}
        ${'lg'}    | ${true}
        ${'xl'}    | ${true}
      `(
        'sets isSidebarExpanded to `$isSidebarExpanded` when the breakpoint is "$breakpoint"',
        async ({ breakpoint, isSidebarExpanded }) => {
          jest.spyOn(GlBreakpointInstance, 'getBreakpointSize').mockReturnValue(breakpoint);

          window.dispatchEvent(new Event('resize'));
          await nextTick();

          if (isSidebarExpanded) {
            expect(findSidebar().classes()).not.toContain('gl-display-none');
          } else {
            expect(findSidebar().classes()).toContain('gl-display-none');
          }
        },
      );
    });
  });
});