summaryrefslogtreecommitdiff
path: root/spec/javascripts/jobs/components/commit_block_spec.js
blob: c02f564d01a8d23028ac353a97ce928df02d693f (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
import Vue from 'vue';
import component from '~/jobs/components/commit_block.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('Commit block', () => {
  const Component = Vue.extend(component);
  let vm;

  const props = {
    commit: {
      short_id: '1f0fb84f',
      id: '1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
      commit_path: 'commit/1f0fb84fb6770d74d97eee58118fd3909cd4f48c',
      title: 'Update README.md',
    },
    mergeRequest: {
      iid: '!21244',
      path: 'merge_requests/21244',
    },
    isLastBlock: true,
  };

  afterEach(() => {
    vm.$destroy();
  });

  describe('pipeline short sha', () => {
    beforeEach(() => {
      vm = mountComponent(Component, {
        ...props,
      });
    });

    it('renders pipeline short sha link', () => {
      expect(vm.$el.querySelector('.js-commit-sha').getAttribute('href')).toEqual(
        props.commit.commit_path,
      );

      expect(vm.$el.querySelector('.js-commit-sha').textContent.trim()).toEqual(
        props.commit.short_id,
      );
    });

    it('renders clipboard button', () => {
      expect(vm.$el.querySelector('button').getAttribute('data-clipboard-text')).toEqual(
        props.commit.id,
      );
    });
  });

  describe('with merge request', () => {
    it('renders merge request link and reference', () => {
      vm = mountComponent(Component, {
        ...props,
      });

      expect(vm.$el.querySelector('.js-link-commit').getAttribute('href')).toEqual(
        props.mergeRequest.path,
      );

      expect(vm.$el.querySelector('.js-link-commit').textContent.trim()).toEqual(
        `!${props.mergeRequest.iid}`,
      );
    });
  });

  describe('without merge request', () => {
    it('does not render merge request', () => {
      const copyProps = Object.assign({}, props);
      delete copyProps.mergeRequest;

      vm = mountComponent(Component, {
        ...copyProps,
      });

      expect(vm.$el.querySelector('.js-link-commit')).toBeNull();
    });
  });

  describe('git commit title', () => {
    it('renders git commit title', () => {
      vm = mountComponent(Component, {
        ...props,
      });

      expect(vm.$el.textContent).toContain(props.commit.title);
    });
  });
});