2020-11-24 15:15:51 +05:30
|
|
|
import { GlIcon, GlLoadingIcon, GlButton } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2020-04-08 14:13:33 +05:30
|
|
|
import {
|
|
|
|
CREATED,
|
|
|
|
RUNNING,
|
|
|
|
DEPLOYING,
|
|
|
|
REDEPLOYING,
|
|
|
|
} from '~/vue_merge_request_widget/components/deployment/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import DeploymentActionButton from '~/vue_merge_request_widget/components/deployment/deployment_action_button.vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { actionButtonMocks } from './deployment_mock_data';
|
|
|
|
|
|
|
|
const baseProps = {
|
|
|
|
actionsConfiguration: actionButtonMocks[DEPLOYING],
|
|
|
|
actionInProgress: null,
|
|
|
|
computedDeploymentStatus: CREATED,
|
2020-11-24 15:15:51 +05:30
|
|
|
icon: 'play',
|
2020-04-08 14:13:33 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
describe('Deployment action button', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const factory = (options = {}) => {
|
|
|
|
wrapper = mount(DeploymentActionButton, {
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('when passed only icon via props', () => {
|
2020-04-08 14:13:33 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: baseProps,
|
2020-11-24 15:15:51 +05:30
|
|
|
slots: {},
|
2020-04-08 14:13:33 +05:30
|
|
|
stubs: {
|
|
|
|
'gl-icon': GlIcon,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('renders prop icon correctly', () => {
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(wrapper.find(GlIcon).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when passed multiple items', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: baseProps,
|
|
|
|
slots: {
|
2020-11-24 15:15:51 +05:30
|
|
|
default: [`<span>${actionButtonMocks[DEPLOYING]}</span>`],
|
2020-04-08 14:13:33 +05:30
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
'gl-icon': GlIcon,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('renders slot and icon prop correctly', () => {
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(wrapper.find(GlIcon).exists()).toBe(true);
|
|
|
|
expect(wrapper.text()).toContain(actionButtonMocks[DEPLOYING]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when its action is in progress', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
...baseProps,
|
|
|
|
actionInProgress: actionButtonMocks[DEPLOYING].actionName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is disabled and shows the loading icon', () => {
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlButton).props('disabled')).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when another action is in progress', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
...baseProps,
|
|
|
|
actionInProgress: actionButtonMocks[REDEPLOYING].actionName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('is disabled and does not show the loading icon', () => {
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlButton).props('disabled')).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when action status is running', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: {
|
|
|
|
...baseProps,
|
|
|
|
actionInProgress: actionButtonMocks[REDEPLOYING].actionName,
|
|
|
|
computedDeploymentStatus: RUNNING,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('is disabled and does not show the loading icon', () => {
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlButton).props('disabled')).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when no action is in progress', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
factory({
|
|
|
|
propsData: baseProps,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('is not disabled nor does it show the loading icon', () => {
|
|
|
|
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlButton).props('disabled')).toBe(false);
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|