summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/pipelines_actions_spec.js
blob: c89dacbcd931b93c770cfc256ad64bcc4cd80b41 (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
import Vue from 'vue';
import pipelinesActionsComp from '~/pipelines/components/pipelines_actions';

describe('Pipelines Actions dropdown', () => {
  let component;
  let spy;
  let actions;
  let ActionsComponent;

  beforeEach(() => {
    ActionsComponent = Vue.extend(pipelinesActionsComp);

    actions = [
      {
        name: 'stop_review',
        path: '/root/review-app/builds/1893/play',
      },
      {
        name: 'foo',
        path: '#',
        playable: false,
      },
    ];

    spy = jasmine.createSpy('spy').and.returnValue(Promise.resolve());

    component = new ActionsComponent({
      propsData: {
        actions,
        service: {
          postAction: spy,
        },
      },
    }).$mount();
  });

  it('should render a dropdown with the provided actions', () => {
    expect(
      component.$el.querySelectorAll('.dropdown-menu li').length,
    ).toEqual(actions.length);
  });

  it('should call the service when an action is clicked', () => {
    component.$el.querySelector('.js-pipeline-dropdown-manual-actions').click();
    component.$el.querySelector('.js-pipeline-action-link').click();

    expect(spy).toHaveBeenCalledWith(actions[0].path);
  });

  it('should hide loading if request fails', () => {
    spy = jasmine.createSpy('spy').and.returnValue(Promise.reject());

    component = new ActionsComponent({
      propsData: {
        actions,
        service: {
          postAction: spy,
        },
      },
    }).$mount();

    component.$el.querySelector('.js-pipeline-dropdown-manual-actions').click();
    component.$el.querySelector('.js-pipeline-action-link').click();

    expect(component.$el.querySelector('.fa-spinner')).toEqual(null);
  });

  it('should render a disabled action when it\'s not playable', () => {
    expect(
      component.$el.querySelector('.dropdown-menu li:last-child button').getAttribute('disabled'),
    ).toEqual('disabled');

    expect(
      component.$el.querySelector('.dropdown-menu li:last-child button').classList.contains('disabled'),
    ).toEqual(true);
  });
});