debian-mirror-gitlab/spec/frontend/pipelines/graph/action_component_spec.js

72 lines
2 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { GlButton } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mount } from '@vue/test-utils';
2019-12-26 22:10:19 +05:30
import MockAdapter from 'axios-mock-adapter';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2019-12-26 22:10:19 +05:30
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
2021-04-29 21:17:54 +05:30
import ActionComponent from '~/pipelines/components/jobs_shared/action_component.vue';
2019-12-26 22:10:19 +05:30
describe('pipeline graph action component', () => {
let wrapper;
let mock;
2020-10-24 23:57:45 +05:30
const findButton = () => wrapper.find(GlButton);
2022-04-04 11:22:00 +05:30
const findTooltipWrapper = () => wrapper.find('[data-testid="ci-action-icon-tooltip-wrapper"]');
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', () => {
2022-04-04 11:22:00 +05:30
expect(findTooltipWrapper().attributes('title')).toBe('bar');
2019-12-26 22:10:19 +05:30
});
2022-04-04 11:22:00 +05:30
it('should update bootstrap tooltip when title changes', async () => {
2019-12-26 22:10:19 +05:30
wrapper.setProps({ tooltipText: 'changed' });
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findTooltipWrapper().attributes('title')).toBe('changed');
2019-12-26 22:10:19 +05:30
});
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', () => {
2021-03-08 18:12:59 +05:30
it('emits `pipelineActionRequestComplete` after a successful request', (done) => {
2019-12-26 22:10:19 +05:30
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);
});
2022-04-04 11:22:00 +05:30
it('renders a loading icon while waiting for request', async () => {
2020-04-22 19:07:51 +05:30
findButton().trigger('click');
2019-12-26 22:10:19 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.find('.js-action-icon-loading').exists()).toBe(true);
2019-12-26 22:10:19 +05:30
});
});
});