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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

217 lines
6.9 KiB
JavaScript
Raw Normal View History

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';
2023-01-13 00:05:48 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-03-08 18:12:59 +05:30
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2023-01-13 00:05:48 +05:30
import axios from '~/lib/utils/axios_utils';
2023-03-17 16:20:25 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
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', () => {
2023-01-13 00:05:48 +05:30
let mock;
2018-12-05 23:21:45 +05:30
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');
2023-01-13 00:05:48 +05:30
const findJobStagesDropdown = () => wrapper.findComponent(StagesDropdown);
const findJobsContainer = () => wrapper.findComponent(JobsContainer);
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
2023-01-13 00:05:48 +05:30
beforeEach(() => {
mock = new MockAdapter(axios);
2023-03-17 16:20:25 +05:30
mock.onGet().reply(HTTP_STATUS_OK, {
2023-01-13 00:05:48 +05:30
name: job.stage,
});
});
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();
2023-01-13 00:05:48 +05:30
return store.dispatch('receiveJobSuccess', job);
2018-12-05 23:21:45 +05:30
});
describe('with stages', () => {
it('renders value provided as selectedStage as selected', () => {
2023-01-13 00:05:48 +05:30
expect(findJobStagesDropdown().props('selectedStage')).toBe(job.stage);
2018-12-05 23:21:45 +05:30
});
});
describe('without jobs for stages', () => {
2021-01-29 00:20:46 +05:30
it('does not render jobs container', () => {
2023-01-13 00:05:48 +05:30
expect(findJobsContainer().exists()).toBe(false);
2018-12-05 23:21:45 +05:30
});
});
describe('with jobs for stages', () => {
2023-01-13 00:05:48 +05:30
beforeEach(() => {
return store.dispatch('receiveJobsForStageSuccess', jobsInStage.latest_statuses);
});
2023-06-20 00:43:36 +05:30
it('renders list of jobs', () => {
2023-01-13 00:05:48 +05:30
expect(findJobsContainer().exists()).toBe(true);
});
});
describe('when job data changes', () => {
const stageArg = job.pipeline.details.stages.find((stage) => stage.name === job.stage);
2023-06-20 00:43:36 +05:30
beforeEach(() => {
2023-01-13 00:05:48 +05:30
jest.spyOn(store, 'dispatch');
2018-12-05 23:21:45 +05:30
});
2023-01-13 00:05:48 +05:30
describe('and the job stage is currently selected', () => {
describe('when the status changed', () => {
it('refetch the jobs list for the stage', async () => {
await store.dispatch('receiveJobSuccess', { ...job, status: 'new' });
expect(store.dispatch).toHaveBeenNthCalledWith(2, 'fetchJobsForStage', { ...stageArg });
});
});
describe('when the status did not change', () => {
it('does not refetch the jobs list for the stage', async () => {
await store.dispatch('receiveJobSuccess', { ...job });
expect(store.dispatch).toHaveBeenCalledTimes(1);
expect(store.dispatch).toHaveBeenNthCalledWith(1, 'receiveJobSuccess', {
...job,
});
});
});
});
describe('and the job stage is not currently selected', () => {
it('does not refetch the jobs list for the stage', async () => {
// Setting stage to `random` on the job means that we are looking
// at `build` stage currently, but the job we are seeing in the logs
// belong to `random`, so we shouldn't have to refetch
await store.dispatch('receiveJobSuccess', { ...job, stage: 'random' });
expect(store.dispatch).toHaveBeenCalledTimes(1);
expect(store.dispatch).toHaveBeenNthCalledWith(1, 'receiveJobSuccess', {
...job,
stage: 'random',
});
});
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
});