2022-04-04 11:22:00 +05:30
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Vuex from 'vuex';
|
2023-03-04 22:38:38 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2022-10-11 01:57:18 +05:30
|
|
|
import EmptyState from '~/jobs/components/job/empty_state.vue';
|
|
|
|
import EnvironmentsBlock from '~/jobs/components/job/environments_block.vue';
|
|
|
|
import ErasedBlock from '~/jobs/components/job/erased_block.vue';
|
|
|
|
import JobApp from '~/jobs/components/job/job_app.vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import JobLog from '~/jobs/components/log/log.vue';
|
|
|
|
import JobLogTopBar from '~/jobs/components/job/job_log_controllers.vue';
|
2022-10-11 01:57:18 +05:30
|
|
|
import Sidebar from '~/jobs/components/job/sidebar/sidebar.vue';
|
|
|
|
import StuckBlock from '~/jobs/components/job/stuck_block.vue';
|
|
|
|
import UnmetPrerequisitesBlock from '~/jobs/components/job/unmet_prerequisites_block.vue';
|
2018-12-05 23:21:45 +05:30
|
|
|
import createStore from '~/jobs/store';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
|
|
|
import { MANUAL_STATUS } from '~/jobs/constants';
|
2022-10-11 01:57:18 +05:30
|
|
|
import job from '../../mock_data';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { mockPendingJobData } from './mock_data';
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('Job App', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
let store;
|
2020-03-13 15:44:24 +05:30
|
|
|
let wrapper;
|
2018-12-13 13:39:08 +05:30
|
|
|
let mock;
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const initSettings = {
|
2020-07-28 23:09:34 +05:30
|
|
|
endpoint: `${TEST_HOST}jobs/123.json`,
|
|
|
|
pagePath: `${TEST_HOST}jobs/123`,
|
2020-03-13 15:44:24 +05:30
|
|
|
logState:
|
|
|
|
'eyJvZmZzZXQiOjE3NDUxLCJuX29wZW5fdGFncyI6MCwiZmdfY29sb3IiOm51bGwsImJnX2NvbG9yIjpudWxsLCJzdHlsZV9tYXNrIjowfQ%3D%3D',
|
|
|
|
};
|
|
|
|
|
|
|
|
const props = {
|
2020-11-24 15:15:51 +05:30
|
|
|
artifactHelpUrl: 'help/artifact',
|
2019-07-07 11:18:12 +05:30
|
|
|
deploymentHelpUrl: 'help/deployment',
|
2018-12-05 23:21:45 +05:30
|
|
|
runnerSettingsUrl: 'settings/ci-cd/runners',
|
2018-12-13 13:39:08 +05:30
|
|
|
terminalPath: 'jobs/123/terminal',
|
2019-10-12 21:52:04 +05:30
|
|
|
projectPath: 'user-name/project-name',
|
2019-12-04 20:38:33 +05:30
|
|
|
subscriptionsMoreMinutesUrl: 'https://customers.gitlab.com/buy_pipeline_minutes',
|
2018-12-05 23:21:45 +05:30
|
|
|
};
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const createComponent = () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
wrapper = shallowMountExtended(JobApp, {
|
|
|
|
propsData: { ...props },
|
|
|
|
store,
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
};
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const setupAndMount = async ({ jobData = {}, jobLogData = {} } = {}) => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(initSettings.endpoint).replyOnce(HTTP_STATUS_OK, { ...job, ...jobData });
|
|
|
|
mock.onGet(`${initSettings.pagePath}/trace.json`).reply(HTTP_STATUS_OK, jobLogData);
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const asyncInit = store.dispatch('init', initSettings);
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
createComponent();
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await asyncInit;
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
await axios.waitForAll();
|
|
|
|
await nextTick();
|
2019-10-12 21:52:04 +05:30
|
|
|
};
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findLoadingComponent = () => wrapper.findComponent(GlLoadingIcon);
|
|
|
|
const findSidebar = () => wrapper.findComponent(Sidebar);
|
|
|
|
const findStuckBlockComponent = () => wrapper.findComponent(StuckBlock);
|
|
|
|
const findFailedJobComponent = () => wrapper.findComponent(UnmetPrerequisitesBlock);
|
|
|
|
const findEnvironmentsBlockComponent = () => wrapper.findComponent(EnvironmentsBlock);
|
|
|
|
const findErasedBlock = () => wrapper.findComponent(ErasedBlock);
|
|
|
|
const findEmptyState = () => wrapper.findComponent(EmptyState);
|
2023-03-04 22:38:38 +05:30
|
|
|
const findJobLog = () => wrapper.findComponent(JobLog);
|
|
|
|
const findJobLogTopBar = () => wrapper.findComponent(JobLogTopBar);
|
|
|
|
|
|
|
|
const findJobContent = () => wrapper.findByTestId('job-content');
|
|
|
|
const findArchivedJob = () => wrapper.findByTestId('archived-job');
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
beforeEach(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
mock = new MockAdapter(axios);
|
2018-12-05 23:21:45 +05:30
|
|
|
store = createStore();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
wrapper.destroy();
|
2018-12-13 13:39:08 +05:30
|
|
|
mock.restore();
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('while loading', () => {
|
|
|
|
beforeEach(() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
store.state.isLoading = true;
|
|
|
|
createComponent();
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it('renders loading icon', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findLoadingComponent().exists()).toBe(true);
|
|
|
|
expect(findSidebar().exists()).toBe(false);
|
|
|
|
expect(findJobContent().exists()).toBe(false);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with successful request', () => {
|
|
|
|
describe('Header section', () => {
|
|
|
|
describe('job callout message', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('should not render the reason when reason is absent', () =>
|
|
|
|
setupAndMount().then(() => {
|
|
|
|
expect(wrapper.vm.shouldRenderCalloutMessage).toBe(false);
|
|
|
|
}));
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('should render the reason when reason is present', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
|
|
|
callout_message: 'There is an unkown failure, please try again',
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
|
|
|
expect(wrapper.vm.shouldRenderCalloutMessage).toBe(true);
|
|
|
|
}));
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stuck block', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('without active runners available', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders stuck block when there are no runners', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2018-12-13 13:39:08 +05:30
|
|
|
status: {
|
|
|
|
group: 'pending',
|
|
|
|
icon: 'status_pending',
|
|
|
|
label: 'pending',
|
|
|
|
text: 'pending',
|
|
|
|
details_path: 'path',
|
|
|
|
},
|
|
|
|
stuck: true,
|
|
|
|
runners: {
|
|
|
|
available: false,
|
|
|
|
online: false,
|
|
|
|
},
|
|
|
|
tags: [],
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findStuckBlockComponent().exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('does not render stuck block when there are runners', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2018-12-13 13:39:08 +05:30
|
|
|
runners: { available: true },
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findStuckBlockComponent().exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('unmet prerequisites block', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders unmet prerequisites block when there is an unmet prerequisites failure', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2019-07-07 11:18:12 +05:30
|
|
|
status: {
|
|
|
|
group: 'failed',
|
|
|
|
icon: 'status_failed',
|
|
|
|
label: 'failed',
|
|
|
|
text: 'failed',
|
|
|
|
details_path: 'path',
|
|
|
|
illustration: {
|
|
|
|
content: 'Retry this job in order to create the necessary resources.',
|
|
|
|
image: 'path',
|
|
|
|
size: 'svg-430',
|
|
|
|
title: 'Failed to create resources',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
failure_reason: 'unmet_prerequisites',
|
|
|
|
has_trace: false,
|
|
|
|
runners: {
|
|
|
|
available: true,
|
|
|
|
},
|
|
|
|
tags: [],
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findFailedJobComponent().exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('environments block', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders environment block when job has environment', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2018-12-13 13:39:08 +05:30
|
|
|
deployment_status: {
|
|
|
|
environment: {
|
|
|
|
environment_path: '/path',
|
|
|
|
name: 'foo',
|
|
|
|
},
|
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findEnvironmentsBlockComponent().exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
|
|
|
|
|
|
|
it('does not render environment block when job has environment', () =>
|
|
|
|
setupAndMount().then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findEnvironmentsBlockComponent().exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('erased block', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders erased block when `erased` is true', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2018-12-13 13:39:08 +05:30
|
|
|
erased_by: {
|
|
|
|
username: 'root',
|
|
|
|
web_url: 'gitlab.com/root',
|
|
|
|
},
|
|
|
|
erased_at: '2016-11-07T11:11:16.525Z',
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findErasedBlock().exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('does not render erased block when `erased` is false', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
|
|
|
erased_at: null,
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findErasedBlock().exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('empty states block', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
it('renders empty state when job does not have log and is not running', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2018-12-13 13:39:08 +05:30
|
|
|
has_trace: false,
|
|
|
|
status: {
|
|
|
|
group: 'pending',
|
|
|
|
icon: 'status_pending',
|
|
|
|
label: 'pending',
|
|
|
|
text: 'pending',
|
|
|
|
details_path: 'path',
|
|
|
|
illustration: {
|
|
|
|
image: 'path',
|
|
|
|
size: '340',
|
|
|
|
title: 'Empty State',
|
|
|
|
content: 'This is an empty state',
|
|
|
|
},
|
|
|
|
action: {
|
|
|
|
button_title: 'Retry job',
|
|
|
|
method: 'post',
|
|
|
|
path: '/path',
|
|
|
|
},
|
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findEmptyState().exists()).toBe(true);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it('does not render empty state when job does not have log but it is running', () =>
|
2019-10-12 21:52:04 +05:30
|
|
|
setupAndMount({
|
|
|
|
jobData: {
|
2018-12-13 13:39:08 +05:30
|
|
|
has_trace: false,
|
|
|
|
status: {
|
|
|
|
group: 'running',
|
|
|
|
icon: 'status_running',
|
|
|
|
label: 'running',
|
|
|
|
text: 'running',
|
|
|
|
details_path: 'path',
|
|
|
|
},
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
}).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findEmptyState().exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
it('does not render empty state when job has log but it is not running', () =>
|
2020-03-13 15:44:24 +05:30
|
|
|
setupAndMount({ jobData: { has_trace: true } }).then(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findEmptyState().exists()).toBe(false);
|
2020-03-13 15:44:24 +05:30
|
|
|
}));
|
2019-10-12 21:52:04 +05:30
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe('sidebar', () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
it('renders sidebar', async () => {
|
|
|
|
await setupAndMount();
|
2022-06-21 17:19:12 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(findSidebar().exists()).toBe(true);
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('archived job', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
beforeEach(() => setupAndMount({ jobData: { archived: true } }));
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it('renders warning about job being archived', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findArchivedJob().exists()).toBe(true);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('non-archived job', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
beforeEach(() => setupAndMount());
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it('does not warning about job being archived', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(findArchivedJob().exists()).toBe(false);
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
describe('job log', () => {
|
|
|
|
beforeEach(() => setupAndMount());
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('should render job log header', () => {
|
|
|
|
expect(findJobLogTopBar().exists()).toBe(true);
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('should render job log', () => {
|
|
|
|
expect(findJobLog().exists()).toBe(true);
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
describe('job log polling', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.spyOn(store, 'dispatch');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should poll job log by default', async () => {
|
|
|
|
await setupAndMount({
|
|
|
|
jobData: mockPendingJobData,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('fetchJobLog');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should NOT poll job log for manual variables form empty state', async () => {
|
|
|
|
const manualPendingJobData = mockPendingJobData;
|
|
|
|
manualPendingJobData.status.group = MANUAL_STATUS;
|
|
|
|
|
|
|
|
await setupAndMount({
|
|
|
|
jobData: manualPendingJobData,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(store.dispatch).not.toHaveBeenCalledWith('fetchJobLog');
|
|
|
|
});
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|