2020-10-30 14:08:56 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-01-25 07:14:14 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-01-14 19:10:45 -05:00
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
2021-03-22 17:08:59 -04:00
|
|
|
import ArtifactsBlock from '~/jobs/components/artifacts_block.vue';
|
2020-11-10 07:08:57 -05:00
|
|
|
import JobRetryForwardDeploymentModal from '~/jobs/components/job_retry_forward_deployment_modal.vue';
|
|
|
|
import JobRetryButton from '~/jobs/components/job_sidebar_retry_button.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import JobsContainer from '~/jobs/components/jobs_container.vue';
|
|
|
|
import Sidebar, { forwardDeploymentFailureModalId } from '~/jobs/components/sidebar.vue';
|
|
|
|
import StagesDropdown from '~/jobs/components/stages_dropdown.vue';
|
2018-10-03 10:13:20 -04:00
|
|
|
import createStore from '~/jobs/store';
|
2019-05-06 18:49:12 -04:00
|
|
|
import job, { jobsInStage } from '../mock_data';
|
2018-10-03 10:13:20 -04:00
|
|
|
|
|
|
|
describe('Sidebar details block', () => {
|
|
|
|
let store;
|
2020-10-30 14:08:56 -04:00
|
|
|
let wrapper;
|
2018-10-03 10:13:20 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
const forwardDeploymentFailure = 'forward_deployment_failure';
|
|
|
|
const findModal = () => wrapper.find(JobRetryForwardDeploymentModal);
|
2021-03-22 17:08:59 -04:00
|
|
|
const findArtifactsBlock = () => wrapper.findComponent(ArtifactsBlock);
|
2020-11-10 07:08:57 -05:00
|
|
|
const findCancelButton = () => wrapper.findByTestId('cancel-button');
|
|
|
|
const findNewIssueButton = () => wrapper.findByTestId('job-new-issue');
|
|
|
|
const findRetryButton = () => wrapper.find(JobRetryButton);
|
|
|
|
const findTerminalLink = () => wrapper.findByTestId('terminal-link');
|
2022-02-24 10:15:02 -05:00
|
|
|
const findEraseLink = () => wrapper.findByTestId('job-log-erase-link');
|
2020-11-10 07:08:57 -05:00
|
|
|
|
2022-02-24 10:15:02 -05:00
|
|
|
const createWrapper = (props) => {
|
2018-10-03 10:13:20 -04:00
|
|
|
store = createStore();
|
2021-03-22 17:08:59 -04:00
|
|
|
|
|
|
|
store.state.job = job;
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
wrapper = extendedWrapper(
|
|
|
|
shallowMount(Sidebar, {
|
2022-02-24 10:15:02 -05:00
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
store,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
2018-10-03 10:13:20 -04:00
|
|
|
|
|
|
|
afterEach(() => {
|
2022-02-24 10:15:02 -05:00
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when job log is erasable', () => {
|
|
|
|
const path = '/root/ci-project/-/jobs/1447/erase';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper({
|
|
|
|
erasePath: path,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders erase job link', () => {
|
|
|
|
expect(findEraseLink().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('erase job link has correct path', () => {
|
|
|
|
expect(findEraseLink().attributes('href')).toBe(path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when job log is not erasable', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render erase button', () => {
|
|
|
|
expect(findEraseLink().exists()).toBe(false);
|
|
|
|
});
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when there is no retry path retry', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
it('should not render a retry button', async () => {
|
|
|
|
createWrapper();
|
|
|
|
const copy = { ...job, retry_path: null };
|
|
|
|
await store.dispatch('receiveJobSuccess', copy);
|
2018-10-03 10:13:20 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
expect(findRetryButton().exists()).toBe(false);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without terminal path', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
it('does not render terminal link', async () => {
|
|
|
|
createWrapper();
|
|
|
|
await store.dispatch('receiveJobSuccess', job);
|
2018-10-03 10:13:20 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
expect(findTerminalLink().exists()).toBe(false);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with terminal path', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
it('renders terminal link', async () => {
|
|
|
|
createWrapper();
|
|
|
|
await store.dispatch('receiveJobSuccess', { ...job, terminal_path: 'job/43123/terminal' });
|
2018-10-03 10:13:20 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
expect(findTerminalLink().exists()).toBe(true);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
return store.dispatch('receiveJobSuccess', job);
|
|
|
|
});
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
it('should render link to new issue', () => {
|
2020-11-10 07:08:57 -05:00
|
|
|
expect(findNewIssueButton().attributes('href')).toBe(job.new_issue_path);
|
|
|
|
expect(findNewIssueButton().text()).toBe('New issue');
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
it('should render the retry button', () => {
|
|
|
|
expect(findRetryButton().props('href')).toBe(job.retry_path);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render link to cancel job', () => {
|
2022-02-24 10:15:02 -05:00
|
|
|
expect(findCancelButton().props('icon')).toBe('cancel');
|
2020-11-10 07:08:57 -05:00
|
|
|
expect(findCancelButton().attributes('href')).toBe(job.cancel_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when there is the relevant error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
return store.dispatch('receiveJobSuccess', {
|
|
|
|
...job,
|
|
|
|
failure_reason: forwardDeploymentFailure,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the modal', () => {
|
|
|
|
expect(findModal().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should provide the modal id to the button and modal', () => {
|
|
|
|
expect(findRetryButton().props('modalId')).toBe(forwardDeploymentFailureModalId);
|
|
|
|
expect(findModal().props('modalId')).toBe(forwardDeploymentFailureModalId);
|
|
|
|
});
|
|
|
|
|
|
|
|
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-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stages dropdown', () => {
|
|
|
|
beforeEach(() => {
|
2020-10-30 14:08:56 -04:00
|
|
|
createWrapper();
|
|
|
|
return store.dispatch('receiveJobSuccess', { ...job, stage: 'aStage' });
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with stages', () => {
|
2018-10-12 13:13:41 -04:00
|
|
|
it('renders value provided as selectedStage as selected', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
expect(wrapper.find(StagesDropdown).props('selectedStage')).toBe('aStage');
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('without jobs for stages', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
beforeEach(() => store.dispatch('receiveJobSuccess', job));
|
2018-10-03 10:13:20 -04:00
|
|
|
|
2020-11-10 07:08:57 -05:00
|
|
|
it('does not render jobs container', () => {
|
|
|
|
expect(wrapper.find(JobsContainer).exists()).toBe(false);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with jobs for stages', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
beforeEach(async () => {
|
|
|
|
await store.dispatch('receiveJobSuccess', job);
|
|
|
|
await store.dispatch('receiveJobsForStageSuccess', jobsInStage.latest_statuses);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders list of jobs', () => {
|
2020-10-30 14:08:56 -04:00
|
|
|
expect(wrapper.find(JobsContainer).exists()).toBe(true);
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-03-22 17:08:59 -04:00
|
|
|
|
|
|
|
describe('artifacts', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('artifacts are not shown if there are no properties other than locked', () => {
|
|
|
|
expect(findArtifactsBlock().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('artifacts are shown if present', async () => {
|
|
|
|
store.state.job.artifact = {
|
|
|
|
download_path: '/root/ci-project/-/jobs/1960/artifacts/download',
|
|
|
|
browse_path: '/root/ci-project/-/jobs/1960/artifacts/browse',
|
|
|
|
keep_path: '/root/ci-project/-/jobs/1960/artifacts/keep',
|
|
|
|
expire_at: '2021-03-23T17:57:11.211Z',
|
|
|
|
expired: false,
|
|
|
|
locked: false,
|
|
|
|
};
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
2021-03-22 17:08:59 -04:00
|
|
|
|
|
|
|
expect(findArtifactsBlock().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2018-10-03 10:13:20 -04:00
|
|
|
});
|