2019-12-26 22:10:19 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import ActionComponent from '~/pipelines/components/graph/action_component.vue';
|
|
|
|
|
|
|
|
describe('pipeline graph action component', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mock;
|
2020-04-22 19:07:51 +05:30
|
|
|
const findButton = () => wrapper.find('button');
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
|
|
|
mock.onPost('foo.json').reply(200);
|
|
|
|
|
|
|
|
wrapper = mount(ActionComponent, {
|
|
|
|
propsData: {
|
|
|
|
tooltipText: 'bar',
|
|
|
|
link: 'foo',
|
|
|
|
actionIcon: 'cancel',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the provided title as a bootstrap tooltip', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(wrapper.attributes('title')).toBe('bar');
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should update bootstrap tooltip when title changes', done => {
|
|
|
|
wrapper.setProps({ tooltipText: 'changed' });
|
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(wrapper.attributes('title')).toBe('changed');
|
2019-12-26 22:10:19 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render an svg', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(wrapper.find('.ci-action-icon-wrapper').exists()).toBe(true);
|
|
|
|
expect(wrapper.find('svg').exists()).toBe(true);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('on click', () => {
|
|
|
|
it('emits `pipelineActionRequestComplete` after a successful request', done => {
|
|
|
|
jest.spyOn(wrapper.vm, '$emit');
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
findButton().trigger('click');
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
waitForPromises()
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.vm.$emit).toHaveBeenCalledWith('pipelineActionRequestComplete');
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a loading icon while waiting for request', done => {
|
2020-04-22 19:07:51 +05:30
|
|
|
findButton().trigger('click');
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.find('.js-action-icon-loading').exists()).toBe(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|