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';
|
2022-10-11 01:57:18 +05:30
|
|
|
import ArtifactsBlock from '~/jobs/components/job/sidebar/artifacts_block.vue';
|
|
|
|
import JobRetryForwardDeploymentModal from '~/jobs/components/job/sidebar/job_retry_forward_deployment_modal.vue';
|
|
|
|
import JobsContainer from '~/jobs/components/job/sidebar/jobs_container.vue';
|
|
|
|
import Sidebar from '~/jobs/components/job/sidebar/sidebar.vue';
|
|
|
|
import StagesDropdown from '~/jobs/components/job/sidebar/stages_dropdown.vue';
|
2018-12-05 23:21:45 +05:30
|
|
|
import createStore from '~/jobs/store';
|
2022-10-11 01:57:18 +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';
|
2022-10-11 01:57:18 +05:30
|
|
|
const findModal = () => wrapper.findComponent(JobRetryForwardDeploymentModal);
|
2021-04-29 21:17:54 +05:30
|
|
|
const findArtifactsBlock = () => wrapper.findComponent(ArtifactsBlock);
|
2021-01-29 00:20:46 +05:30
|
|
|
const findNewIssueButton = () => wrapper.findByTestId('job-new-issue');
|
|
|
|
const findTerminalLink = () => wrapper.findByTestId('terminal-link');
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(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', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(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', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.findComponent(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
|
|
|
});
|