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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
3.3 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';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
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;
2022-10-11 01:57:18 +05:30
const findButton = () => wrapper.findComponent(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
2023-04-23 21:23:45 +05:30
const defaultProps = {
tooltipText: 'bar',
link: 'foo',
actionIcon: 'cancel',
};
2019-12-26 22:10:19 +05:30
2023-04-23 21:23:45 +05:30
const createComponent = ({ props } = {}) => {
2019-12-26 22:10:19 +05:30
wrapper = mount(ActionComponent, {
2023-04-23 21:23:45 +05:30
propsData: { ...defaultProps, ...props },
2019-12-26 22:10:19 +05:30
});
2023-04-23 21:23:45 +05:30
};
beforeEach(() => {
mock = new MockAdapter(axios);
mock.onPost('foo.json').reply(HTTP_STATUS_OK);
2019-12-26 22:10:19 +05:30
});
afterEach(() => {
mock.restore();
});
2023-04-23 21:23:45 +05:30
describe('render', () => {
beforeEach(() => {
createComponent();
});
2019-12-26 22:10:19 +05:30
2023-04-23 21:23:45 +05:30
it('should render the provided title as a bootstrap tooltip', () => {
expect(findTooltipWrapper().attributes('title')).toBe('bar');
});
2019-12-26 22:10:19 +05:30
2023-04-23 21:23:45 +05:30
it('should update bootstrap tooltip when title changes', async () => {
wrapper.setProps({ tooltipText: 'changed' });
2019-12-26 22:10:19 +05:30
2023-04-23 21:23:45 +05:30
await nextTick();
expect(findTooltipWrapper().attributes('title')).toBe('changed');
});
it('should render an svg', () => {
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', () => {
2023-04-23 21:23:45 +05:30
beforeEach(() => {
createComponent();
});
2019-12-26 22:10:19 +05:30
2023-04-23 21:23:45 +05:30
it('emits `pipelineActionRequestComplete` after a successful request', async () => {
2020-04-22 19:07:51 +05:30
findButton().trigger('click');
2019-12-26 22:10:19 +05:30
2022-06-21 17:19:12 +05:30
await waitForPromises();
2023-04-23 21:23:45 +05:30
expect(wrapper.emitted().pipelineActionRequestComplete).toHaveLength(1);
2019-12-26 22:10:19 +05:30
});
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
});
});
2023-04-23 21:23:45 +05:30
describe('when has a confirmation modal', () => {
beforeEach(() => {
createComponent({ props: { withConfirmationModal: true, shouldTriggerClick: false } });
});
describe('and a first click is initiated', () => {
beforeEach(async () => {
findButton().trigger('click');
await waitForPromises();
});
it('emits `showActionConfirmationModal` event', () => {
expect(wrapper.emitted().showActionConfirmationModal).toHaveLength(1);
});
it('does not emit `pipelineActionRequestComplete` event', () => {
expect(wrapper.emitted().pipelineActionRequestComplete).toBeUndefined();
});
});
describe('and the `shouldTriggerClick` value becomes true', () => {
beforeEach(async () => {
await wrapper.setProps({ shouldTriggerClick: true });
});
it('does not emit `showActionConfirmationModal` event', () => {
expect(wrapper.emitted().showActionConfirmationModal).toBeUndefined();
});
it('emits `actionButtonClicked` event', () => {
expect(wrapper.emitted().actionButtonClicked).toHaveLength(1);
});
});
});
2019-12-26 22:10:19 +05:30
});