pipelines_actions_spec.js 2.02 KB
Newer Older
1
import Vue from 'vue';
2
import pipelinesActionsComp from '~/pipelines/components/pipelines_actions.vue';
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

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',
      },
Filipa Lacerda's avatar
Filipa Lacerda committed
18 19 20 21 22
      {
        name: 'foo',
        path: '#',
        playable: false,
      },
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
    ];

    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);
  });
Filipa Lacerda's avatar
Filipa Lacerda committed
67 68 69 70 71 72 73 74 75 76

  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);
  });
77
});