2020-09-23 14:10:15 -04:00
|
|
|
import { GlModal, GlLoadingIcon } from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-02-01 10:08:56 -05:00
|
|
|
import HeaderComponent from '~/pipelines/components/header_component.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import cancelPipelineMutation from '~/pipelines/graphql/mutations/cancel_pipeline.mutation.graphql';
|
2021-02-01 10:08:56 -05:00
|
|
|
import deletePipelineMutation from '~/pipelines/graphql/mutations/delete_pipeline.mutation.graphql';
|
|
|
|
import retryPipelineMutation from '~/pipelines/graphql/mutations/retry_pipeline.mutation.graphql';
|
2020-09-23 14:10:15 -04:00
|
|
|
import {
|
|
|
|
mockCancelledPipelineHeader,
|
|
|
|
mockFailedPipelineHeader,
|
|
|
|
mockRunningPipelineHeader,
|
|
|
|
mockSuccessfulPipelineHeader,
|
|
|
|
} from './mock_data';
|
2020-05-06 14:09:38 -04:00
|
|
|
|
|
|
|
describe('Pipeline details header', () => {
|
|
|
|
let wrapper;
|
|
|
|
let glModalDirective;
|
|
|
|
|
|
|
|
const findDeleteModal = () => wrapper.find(GlModal);
|
2020-09-23 14:10:15 -04:00
|
|
|
const findRetryButton = () => wrapper.find('[data-testid="retryPipeline"]');
|
|
|
|
const findCancelButton = () => wrapper.find('[data-testid="cancelPipeline"]');
|
|
|
|
const findDeleteButton = () => wrapper.find('[data-testid="deletePipeline"]');
|
|
|
|
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
|
|
|
|
|
|
|
|
const defaultProvideOptions = {
|
|
|
|
pipelineId: 14,
|
|
|
|
pipelineIid: 1,
|
|
|
|
paths: {
|
2020-11-09 19:08:52 -05:00
|
|
|
pipelinesPath: '/namespace/my-project/-/pipelines',
|
2020-09-23 14:10:15 -04:00
|
|
|
fullProject: '/namespace/my-project',
|
2020-05-06 14:09:38 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
const createComponent = (pipelineMock = mockRunningPipelineHeader, { isLoading } = false) => {
|
2020-05-06 14:09:38 -04:00
|
|
|
glModalDirective = jest.fn();
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
const $apollo = {
|
|
|
|
queries: {
|
|
|
|
pipeline: {
|
|
|
|
loading: isLoading,
|
|
|
|
stopPolling: jest.fn(),
|
|
|
|
startPolling: jest.fn(),
|
|
|
|
},
|
|
|
|
},
|
2020-11-09 19:08:52 -05:00
|
|
|
mutate: jest.fn(),
|
2020-09-23 14:10:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return shallowMount(HeaderComponent, {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
pipeline: pipelineMock,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
...defaultProvideOptions,
|
2020-05-06 14:09:38 -04:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
glModal: {
|
2020-09-23 14:10:15 -04:00
|
|
|
bind(_, { value }) {
|
2020-05-06 14:09:38 -04:00
|
|
|
glModalDirective(value);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-09-23 14:10:15 -04:00
|
|
|
mocks: { $apollo },
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
describe('initial loading', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent(null, { isLoading: true });
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
it('shows a loading state while graphQL is fetching initial data', () => {
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
2020-09-23 14:10:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('visible state', () => {
|
|
|
|
it.each`
|
|
|
|
state | pipelineData | retryValue | cancelValue
|
|
|
|
${'cancelled'} | ${mockCancelledPipelineHeader} | ${true} | ${false}
|
|
|
|
${'failed'} | ${mockFailedPipelineHeader} | ${true} | ${false}
|
|
|
|
${'running'} | ${mockRunningPipelineHeader} | ${false} | ${true}
|
|
|
|
${'successful'} | ${mockSuccessfulPipelineHeader} | ${false} | ${false}
|
|
|
|
`(
|
|
|
|
'with a $state pipeline, it will show actions: retry $retryValue and cancel $cancelValue',
|
|
|
|
({ pipelineData, retryValue, cancelValue }) => {
|
|
|
|
wrapper = createComponent(pipelineData);
|
|
|
|
|
|
|
|
expect(findRetryButton().exists()).toBe(retryValue);
|
|
|
|
expect(findCancelButton().exists()).toBe(cancelValue);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2020-05-06 14:09:38 -04:00
|
|
|
|
2020-11-13 10:09:24 -05:00
|
|
|
describe('polling', () => {
|
|
|
|
it('is stopped when pipeline is finished', async () => {
|
|
|
|
wrapper = createComponent({ ...mockRunningPipelineHeader });
|
|
|
|
|
|
|
|
await wrapper.setData({
|
|
|
|
pipeline: { ...mockCancelledPipelineHeader },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.queries.pipeline.stopPolling).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is not stopped when pipeline is not finished', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$apollo.queries.pipeline.stopPolling).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
describe('actions', () => {
|
|
|
|
describe('Retry action', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent(mockCancelledPipelineHeader);
|
|
|
|
});
|
2020-05-06 14:09:38 -04:00
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
it('should call retryPipeline Mutation with pipeline id', () => {
|
2020-09-23 14:10:15 -04:00
|
|
|
findRetryButton().vm.$emit('click');
|
2020-05-06 14:09:38 -04:00
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: retryPipelineMutation,
|
|
|
|
variables: { id: mockCancelledPipelineHeader.id },
|
|
|
|
});
|
2020-09-23 14:10:15 -04:00
|
|
|
});
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
describe('Cancel action', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent(mockRunningPipelineHeader);
|
|
|
|
});
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
it('should call cancelPipeline Mutation with pipeline id', () => {
|
2020-09-23 14:10:15 -04:00
|
|
|
findCancelButton().vm.$emit('click');
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: cancelPipelineMutation,
|
|
|
|
variables: { id: mockRunningPipelineHeader.id },
|
|
|
|
});
|
2020-09-23 14:10:15 -04:00
|
|
|
});
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
|
|
|
|
2020-09-23 14:10:15 -04:00
|
|
|
describe('Delete action', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent(mockFailedPipelineHeader);
|
|
|
|
});
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
it('displays delete modal when clicking on delete and does not call the delete action', () => {
|
2020-09-23 14:10:15 -04:00
|
|
|
findDeleteButton().vm.$emit('click');
|
|
|
|
|
2020-05-06 14:09:38 -04:00
|
|
|
expect(findDeleteModal().props('modalId')).toBe(wrapper.vm.$options.DELETE_MODAL_ID);
|
|
|
|
expect(glModalDirective).toHaveBeenCalledWith(wrapper.vm.$options.DELETE_MODAL_ID);
|
2020-11-09 19:08:52 -05:00
|
|
|
expect(wrapper.vm.$apollo.mutate).not.toHaveBeenCalled();
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
it('should call deletePipeline Mutation with pipeline id when modal is submitted', () => {
|
2020-05-06 14:09:38 -04:00
|
|
|
findDeleteModal().vm.$emit('ok');
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
expect(wrapper.vm.$apollo.mutate).toHaveBeenCalledWith({
|
|
|
|
mutation: deletePipelineMutation,
|
|
|
|
variables: { id: mockFailedPipelineHeader.id },
|
|
|
|
});
|
2020-05-06 14:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|