summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/header_component_spec.js
blob: cecc7ceb53df4c0f35533bc6aa6067477c1d9421 (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
import Vue from 'vue';
import headerComponent from '~/pipelines/components/header_component.vue';
import eventHub from '~/pipelines/event_hub';

describe('Pipeline details header', () => {
  let HeaderComponent;
  let vm;
  let props;

  beforeEach(() => {
    HeaderComponent = Vue.extend(headerComponent);

    const threeWeeksAgo = new Date();
    threeWeeksAgo.setDate(threeWeeksAgo.getDate() - 21);

    props = {
      pipeline: {
        details: {
          status: {
            group: 'failed',
            icon: 'ci-status-failed',
            label: 'failed',
            text: 'failed',
            details_path: 'path',
          },
        },
        id: 123,
        created_at: threeWeeksAgo.toISOString(),
        user: {
          web_url: 'path',
          name: 'Foo',
          username: 'foobar',
          email: 'foo@bar.com',
          avatar_url: 'link',
        },
        retry_path: 'path',
      },
      isLoading: false,
    };

    vm = new HeaderComponent({ propsData: props }).$mount();
  });

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

  it('should render provided pipeline info', () => {
    expect(
      vm.$el.querySelector('.header-main-content').textContent.replace(/\s+/g, ' ').trim(),
    ).toEqual('failed Pipeline #123 triggered 3 weeks ago by Foo');
  });

  describe('action buttons', () => {
    it('should call postAction when button action is clicked', () => {
      eventHub.$on('headerPostAction', (action) => {
        expect(action.path).toEqual('path');
      });

      vm.$el.querySelector('button').click();
    });
  });
});