BigW Consortium Gitlab

async_button_spec.js 1.6 KB
Newer Older
1
import Vue from 'vue';
2
import asyncButtonComp from '~/pipelines/components/async_button.vue';
3
import eventHub from '~/pipelines/event_hub';
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

describe('Pipelines Async Button', () => {
  let component;
  let AsyncButtonComponent;

  beforeEach(() => {
    AsyncButtonComponent = Vue.extend(asyncButtonComp);

    component = new AsyncButtonComponent({
      propsData: {
        endpoint: '/foo',
        title: 'Foo',
        icon: 'fa fa-foo',
        cssClass: 'bar',
      },
    }).$mount();
  });

  it('should render a button', () => {
    expect(component.$el.tagName).toEqual('BUTTON');
  });

  it('should render the provided icon', () => {
    expect(component.$el.querySelector('i').getAttribute('class')).toContain('fa fa-foo');
  });

  it('should render the provided title', () => {
31
    expect(component.$el.getAttribute('data-original-title')).toContain('Foo');
32 33 34 35 36 37 38 39 40 41
    expect(component.$el.getAttribute('aria-label')).toContain('Foo');
  });

  it('should render the provided cssClass', () => {
    expect(component.$el.getAttribute('class')).toContain('bar');
  });

  describe('With confirm dialog', () => {
    it('should call the service when confimation is positive', () => {
      spyOn(window, 'confirm').and.returnValue(true);
42 43 44
      eventHub.$on('postAction', (endpoint) => {
        expect(endpoint).toEqual('/foo');
      });
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

      component = new AsyncButtonComponent({
        propsData: {
          endpoint: '/foo',
          title: 'Foo',
          icon: 'fa fa-foo',
          cssClass: 'bar',
          confirmActionMessage: 'bar',
        },
      }).$mount();

      component.$el.click();
    });
  });
});