2021-01-29 00:20:46 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
2021-04-29 21:17:54 +05:30
|
|
|
import ArtifactsBlock from '~/jobs/components/artifacts_block.vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
import JobRetryForwardDeploymentModal from '~/jobs/components/job_retry_forward_deployment_modal.vue';
|
|
|
|
import JobRetryButton from '~/jobs/components/job_sidebar_retry_button.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
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-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';
|
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);
|
2021-04-29 21:17:54 +05:30
|
|
|
const findArtifactsBlock = () => wrapper.findComponent(ArtifactsBlock);
|
2021-01-29 00:20:46 +05:30
|
|
|
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-05-07 20:08:51 +05:30
|
|
|
const findEraseLink = () => wrapper.findByTestId('job-log-erase-link');
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
const createWrapper = (props) => {
|
2018-12-05 23:21:45 +05:30
|
|
|
store = createStore();
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
store.state.job = job;
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = extendedWrapper(
|
|
|
|
shallowMount(Sidebar, {
|
2022-05-07 20:08:51 +05:30
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
store,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
2022-05-07 20:08:51 +05:30
|
|
|
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-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', () => {
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(findCancelButton().props('icon')).toBe('cancel');
|
2021-01-29 00:20:46 +05:30
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
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-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
expect(findArtifactsBlock().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|