summaryrefslogtreecommitdiff
path: root/spec/frontend/jobs/bridge/components/sidebar_spec.js
blob: 9debbb14c306679e73f5f792a08aa32deff2e69d (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
import { GlButton, GlDropdown } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import BridgeSidebar from '~/jobs/bridge/components/sidebar.vue';
import CommitBlock from '~/jobs/components/commit_block.vue';
import { mockCommit, mockJob } from '../mock_data';

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

  const createComponent = (props) => {
    wrapper = shallowMount(BridgeSidebar, {
      propsData: {
        bridgeJob: mockJob,
        commit: mockCommit,
        ...props,
      },
    });
  };

  const findJobTitle = () => wrapper.find('h4');
  const findCommitBlock = () => wrapper.findComponent(CommitBlock);
  const findRetryDropdown = () => wrapper.find(GlDropdown);
  const findToggleBtn = () => wrapper.findComponent(GlButton);

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

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

    it('renders job name', () => {
      expect(findJobTitle().text()).toBe(mockJob.name);
    });

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

    it('renders commit information', () => {
      expect(findCommitBlock().exists()).toBe(true);
    });
  });

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

    it('emits toggle sidebar event on button click', async () => {
      expect(wrapper.emitted('toggleSidebar')).toBe(undefined);

      findToggleBtn().vm.$emit('click');

      expect(wrapper.emitted('toggleSidebar')).toHaveLength(1);
    });
  });
});