debian-mirror-gitlab/spec/frontend/jobs/components/sidebar_spec.js

168 lines
5.4 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import { shallowMount } from '@vue/test-utils';
import Sidebar, { forwardDeploymentFailureModalId } from '~/jobs/components/sidebar.vue';
import StagesDropdown from '~/jobs/components/stages_dropdown.vue';
import JobsContainer from '~/jobs/components/jobs_container.vue';
import JobRetryForwardDeploymentModal from '~/jobs/components/job_retry_forward_deployment_modal.vue';
import JobRetryButton from '~/jobs/components/job_sidebar_retry_button.vue';
2018-12-05 23:21:45 +05:30
import createStore from '~/jobs/store';
2019-09-04 21:01:54 +05:30
import job, { jobsInStage } from '../mock_data';
2021-01-29 00:20:46 +05:30
import { extendedWrapper } from '../../helpers/vue_test_utils_helper';
2018-12-05 23:21:45 +05:30
describe('Sidebar details block', () => {
let store;
2021-01-29 00:20:46 +05:30
let wrapper;
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
const forwardDeploymentFailure = 'forward_deployment_failure';
const findModal = () => wrapper.find(JobRetryForwardDeploymentModal);
const findCancelButton = () => wrapper.findByTestId('cancel-button');
const findNewIssueButton = () => wrapper.findByTestId('job-new-issue');
const findRetryButton = () => wrapper.find(JobRetryButton);
const findTerminalLink = () => wrapper.findByTestId('terminal-link');
const createWrapper = ({ props = {} } = {}) => {
2018-12-05 23:21:45 +05:30
store = createStore();
2021-01-29 00:20:46 +05:30
wrapper = extendedWrapper(
shallowMount(Sidebar, {
...props,
store,
}),
);
};
2018-12-05 23:21:45 +05:30
afterEach(() => {
2021-01-29 00:20:46 +05:30
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
2018-12-05 23:21:45 +05:30
});
describe('when there is no retry path retry', () => {
2021-01-29 00:20:46 +05:30
it('should not render a retry button', async () => {
createWrapper();
const copy = { ...job, retry_path: null };
await store.dispatch('receiveJobSuccess', copy);
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
expect(findRetryButton().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
});
describe('without terminal path', () => {
2021-01-29 00:20:46 +05:30
it('does not render terminal link', async () => {
createWrapper();
await store.dispatch('receiveJobSuccess', job);
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
expect(findTerminalLink().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
});
describe('with terminal path', () => {
2021-01-29 00:20:46 +05:30
it('renders terminal link', async () => {
createWrapper();
await store.dispatch('receiveJobSuccess', { ...job, terminal_path: 'job/43123/terminal' });
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
expect(findTerminalLink().exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
});
describe('actions', () => {
2021-01-29 00:20:46 +05:30
beforeEach(() => {
createWrapper();
return store.dispatch('receiveJobSuccess', job);
});
2018-12-13 13:39:08 +05:30
2021-01-29 00:20:46 +05:30
it('should render link to new issue', () => {
expect(findNewIssueButton().attributes('href')).toBe(job.new_issue_path);
expect(findNewIssueButton().text()).toBe('New issue');
2018-12-05 23:21:45 +05:30
});
2021-01-29 00:20:46 +05:30
it('should render the retry button', () => {
expect(findRetryButton().props('href')).toBe(job.retry_path);
2018-12-05 23:21:45 +05:30
});
it('should render link to cancel job', () => {
2021-01-29 00:20:46 +05:30
expect(findCancelButton().text()).toMatch('Cancel');
expect(findCancelButton().attributes('href')).toBe(job.cancel_path);
2018-12-05 23:21:45 +05:30
});
});
2021-01-29 00:20:46 +05:30
describe('forward deployment failure', () => {
describe('when the relevant data is missing', () => {
it.each`
retryPath | failureReason
${null} | ${null}
${''} | ${''}
${job.retry_path} | ${''}
${''} | ${forwardDeploymentFailure}
${job.retry_path} | ${'unmet_prerequisites'}
`(
'should not render the modal when path and failure are $retryPath, $failureReason',
async ({ retryPath, failureReason }) => {
createWrapper();
await store.dispatch('receiveJobSuccess', {
...job,
failure_reason: failureReason,
retry_path: retryPath,
});
expect(findModal().exists()).toBe(false);
},
2018-12-05 23:21:45 +05:30
);
});
2021-01-29 00:20:46 +05:30
describe('when there is the relevant error', () => {
beforeEach(() => {
createWrapper();
return store.dispatch('receiveJobSuccess', {
...job,
failure_reason: forwardDeploymentFailure,
});
});
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
it('should render the modal', () => {
expect(findModal().exists()).toBe(true);
});
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
it('should provide the modal id to the button and modal', () => {
expect(findRetryButton().props('modalId')).toBe(forwardDeploymentFailureModalId);
expect(findModal().props('modalId')).toBe(forwardDeploymentFailureModalId);
});
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
it('should provide the retry path to the button and modal', () => {
expect(findRetryButton().props('href')).toBe(job.retry_path);
expect(findModal().props('href')).toBe(job.retry_path);
});
2018-12-05 23:21:45 +05:30
});
});
describe('stages dropdown', () => {
beforeEach(() => {
2021-01-29 00:20:46 +05:30
createWrapper();
return store.dispatch('receiveJobSuccess', { ...job, stage: 'aStage' });
2018-12-05 23:21:45 +05:30
});
describe('with stages', () => {
it('renders value provided as selectedStage as selected', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.find(StagesDropdown).props('selectedStage')).toBe('aStage');
2018-12-05 23:21:45 +05:30
});
});
describe('without jobs for stages', () => {
2021-01-29 00:20:46 +05:30
beforeEach(() => store.dispatch('receiveJobSuccess', job));
2018-12-05 23:21:45 +05:30
2021-01-29 00:20:46 +05:30
it('does not render jobs container', () => {
expect(wrapper.find(JobsContainer).exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
});
describe('with jobs for stages', () => {
2021-01-29 00:20:46 +05:30
beforeEach(async () => {
await store.dispatch('receiveJobSuccess', job);
await store.dispatch('receiveJobsForStageSuccess', jobsInStage.latest_statuses);
2018-12-05 23:21:45 +05:30
});
it('renders list of jobs', () => {
2021-01-29 00:20:46 +05:30
expect(wrapper.find(JobsContainer).exists()).toBe(true);
2018-12-05 23:21:45 +05:30
});
});
});
});