debian-mirror-gitlab/spec/javascripts/jobs/components/job_app_spec.js

592 lines
17 KiB
JavaScript
Raw Normal View History

2018-12-05 23:21:45 +05:30
import Vue from 'vue';
2018-12-13 13:39:08 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2018-12-05 23:21:45 +05:30
import jobApp from '~/jobs/components/job_app.vue';
import createStore from '~/jobs/store';
2019-10-12 21:52:04 +05:30
import * as types from '~/jobs/store/mutation_types';
2018-12-05 23:21:45 +05:30
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2019-10-12 21:52:04 +05:30
import { waitForMutation } from 'spec/helpers/vue_test_utils_helper';
2018-12-13 13:39:08 +05:30
import { resetStore } from '../store/helpers';
import job from '../mock_data';
2018-12-05 23:21:45 +05:30
describe('Job App ', () => {
2018-12-13 13:39:08 +05:30
const delayedJobFixture = getJSONFixture('jobs/delayed.json');
2018-12-05 23:21:45 +05:30
const Component = Vue.extend(jobApp);
let store;
let vm;
2018-12-13 13:39:08 +05:30
let mock;
2018-12-05 23:21:45 +05:30
const props = {
2018-12-13 13:39:08 +05:30
endpoint: `${gl.TEST_HOST}jobs/123.json`,
runnerHelpUrl: 'help/runner',
2019-07-07 11:18:12 +05:30
deploymentHelpUrl: 'help/deployment',
2018-12-05 23:21:45 +05:30
runnerSettingsUrl: 'settings/ci-cd/runners',
2019-10-12 21:52:04 +05:30
variablesSettingsUrl: 'settings/ci-cd/variables',
2018-12-13 13:39:08 +05:30
terminalPath: 'jobs/123/terminal',
pagePath: `${gl.TEST_HOST}jobs/123`,
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-13 13:39:08 +05:30
logState:
'eyJvZmZzZXQiOjE3NDUxLCJuX29wZW5fdGFncyI6MCwiZmdfY29sb3IiOm51bGwsImJnX2NvbG9yIjpudWxsLCJzdHlsZV9tYXNrIjowfQ%3D%3D',
2018-12-05 23:21:45 +05:30
};
2019-10-12 21:52:04 +05:30
const waitForJobReceived = () => waitForMutation(store, types.RECEIVE_JOB_SUCCESS);
const setupAndMount = ({ jobData = {}, traceData = {} } = {}) => {
mock.onGet(props.endpoint).replyOnce(200, { ...job, ...jobData });
mock.onGet(`${props.pagePath}/trace.json`).reply(200, traceData);
vm = mountComponentWithStore(Component, { props, store });
return waitForJobReceived();
};
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(() => {
2018-12-13 13:39:08 +05:30
resetStore(store);
2018-12-05 23:21:45 +05:30
vm.$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(() => {
2019-10-12 21:52:04 +05:30
setupAndMount();
2018-12-13 13:39:08 +05:30
});
2019-10-12 21:52:04 +05:30
it('renders loading icon', () => {
2018-12-13 13:39:08 +05:30
expect(vm.$el.querySelector('.js-job-loading')).not.toBeNull();
expect(vm.$el.querySelector('.js-job-sidebar')).toBeNull();
expect(vm.$el.querySelector('.js-job-content')).toBeNull();
});
});
describe('with successful request', () => {
describe('Header section', () => {
describe('job callout message', () => {
it('should not render the reason when reason is absent', done => {
2019-10-12 21:52:04 +05:30
setupAndMount()
.then(() => {
expect(vm.shouldRenderCalloutMessage).toBe(false);
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
it('should render the reason when reason is present', done => {
2019-10-12 21:52:04 +05:30
setupAndMount({
jobData: {
callout_message: 'There is an unkown failure, please try again',
},
})
.then(() => {
expect(vm.shouldRenderCalloutMessage).toBe(true);
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
});
describe('triggered job', () => {
2019-10-12 21:52:04 +05:30
beforeEach(done => {
2019-06-05 12:25:43 +05:30
const aYearAgo = new Date();
aYearAgo.setFullYear(aYearAgo.getFullYear() - 1);
2019-10-12 21:52:04 +05:30
setupAndMount({ jobData: { started: aYearAgo.toISOString() } })
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
2019-10-12 21:52:04 +05:30
it('should render provided job information', () => {
expect(
vm.$el
.querySelector('.header-main-content')
.textContent.replace(/\s+/g, ' ')
.trim(),
).toContain('passed Job #4757 triggered 1 year ago by Root');
2018-12-13 13:39:08 +05:30
});
2019-10-12 21:52:04 +05:30
it('should render new issue link', () => {
expect(vm.$el.querySelector('.js-new-issue').getAttribute('href')).toEqual(
job.new_issue_path,
);
2018-12-13 13:39:08 +05:30
});
});
describe('created job', () => {
it('should render created key', done => {
2019-10-12 21:52:04 +05:30
setupAndMount()
.then(() => {
expect(
vm.$el
.querySelector('.header-main-content')
.textContent.replace(/\s+/g, ' ')
.trim(),
).toContain('passed Job #4757 created 3 weeks ago by Root');
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
});
});
describe('stuck block', () => {
describe('without active runners availabl', () => {
it('renders stuck block when there are no runners', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-stuck')).not.toBeNull();
expect(
vm.$el.querySelector('.js-job-stuck .js-stuck-no-active-runner'),
).not.toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
});
describe('when available runners can not run specified tag', () => {
it('renders tags in stuck block when there are no runners', done => {
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,
},
2019-10-12 21:52:04 +05:30
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-stuck').textContent).toContain(job.tags[0]);
expect(vm.$el.querySelector('.js-job-stuck .js-stuck-with-tags')).not.toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
});
describe('when runners are offline and build has tags', () => {
it('renders message about job being stuck because of no runners with the specified tags', done => {
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: true,
online: true,
},
2019-10-12 21:52:04 +05:30
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-stuck').textContent).toContain(job.tags[0]);
expect(vm.$el.querySelector('.js-job-stuck .js-stuck-with-tags')).not.toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
});
it('does not renders stuck block when there are no runners', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-stuck')).toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +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', () => {
it('renders unmet prerequisites block when there is an unmet prerequisites failure', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-failed')).not.toBeNull();
})
.then(done)
.catch(done.fail);
2019-07-07 11:18:12 +05:30
});
});
2018-12-13 13:39:08 +05:30
describe('environments block', () => {
it('renders environment block when job has environment', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-environment')).not.toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
it('does not render environment block when job has environment', done => {
2019-10-12 21:52:04 +05:30
setupAndMount()
.then(() => {
expect(vm.$el.querySelector('.js-job-environment')).toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +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', () => {
it('renders erased block when `erased` is true', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-erased-block')).not.toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
it('does not render erased block when `erased` is false', done => {
2019-10-12 21:52:04 +05:30
setupAndMount({
jobData: {
erased_at: null,
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-erased-block')).toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
});
2018-12-13 13:39:08 +05:30
describe('empty states block', () => {
it('renders empty state when job does not have trace and is not running', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-empty-state')).not.toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
it('does not render empty state when job does not have trace but it is running', done => {
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
},
})
.then(() => {
expect(vm.$el.querySelector('.js-job-empty-state')).toBeNull();
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
it('does not render empty state when job has trace but it is not running', done => {
2019-10-12 21:52:04 +05:30
setupAndMount({ jobData: { has_trace: true } })
.then(() => {
expect(vm.$el.querySelector('.js-job-empty-state')).toBeNull();
})
.then(done)
.catch(done.fail);
done();
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
it('displays remaining time for a delayed job', done => {
const oneHourInMilliseconds = 3600000;
spyOn(Date, 'now').and.callFake(
() => new Date(delayedJobFixture.scheduled_at).getTime() - oneHourInMilliseconds,
);
2019-10-12 21:52:04 +05:30
setupAndMount({ jobData: delayedJobFixture })
.then(() => {
expect(vm.$el.querySelector('.js-job-empty-state')).not.toBeNull();
2018-12-05 23:21:45 +05:30
2019-10-12 21:52:04 +05:30
const title = vm.$el.querySelector('.js-job-empty-state-title');
2018-12-05 23:21:45 +05:30
2019-10-12 21:52:04 +05:30
expect(title).toContainText('01:00:00');
})
.then(done)
.catch(done.fail);
});
});
2018-12-05 23:21:45 +05:30
2019-10-12 21:52:04 +05:30
describe('sidebar', () => {
it('has no blank blocks', done => {
setupAndMount({
jobData: {
duration: null,
finished_at: null,
erased_at: null,
queued: null,
runner: null,
coverage: null,
tags: [],
cancel_path: null,
},
})
.then(() => {
vm.$el.querySelectorAll('.blocks-container > *').forEach(block => {
expect(block.textContent.trim()).not.toBe('');
});
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
});
});
2018-12-13 13:39:08 +05:30
describe('archived job', () => {
2019-10-12 21:52:04 +05:30
beforeEach(done => {
setupAndMount({ jobData: { archived: true } })
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
2019-10-12 21:52:04 +05:30
it('renders warning about job being archived', () => {
expect(vm.$el.querySelector('.js-archived-job ')).not.toBeNull();
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', () => {
2019-10-12 21:52:04 +05:30
beforeEach(done => {
setupAndMount()
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
2018-12-05 23:21:45 +05:30
2019-10-12 21:52:04 +05:30
it('does not warning about job being archived', () => {
expect(vm.$el.querySelector('.js-archived-job ')).toBeNull();
2018-12-05 23:21:45 +05:30
});
});
2018-12-13 13:39:08 +05:30
describe('trace output', () => {
describe('with append flag', () => {
it('appends the log content to the existing one', done => {
2019-10-12 21:52:04 +05:30
setupAndMount({
traceData: {
html: '<span>More<span>',
status: 'running',
state: 'newstate',
append: true,
complete: true,
},
})
.then(() => {
vm.$store.state.trace = 'Update';
return vm.$nextTick();
})
.then(() => {
expect(vm.$el.querySelector('.js-build-trace').textContent.trim()).toContain('Update');
})
.then(done)
.catch(done.fail);
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('without append flag', () => {
it('replaces the trace', done => {
2019-10-12 21:52:04 +05:30
setupAndMount({
traceData: {
html: '<span>Different<span>',
status: 'running',
append: false,
complete: true,
},
})
.then(() => {
expect(vm.$el.querySelector('.js-build-trace').textContent.trim()).not.toContain(
'Update',
);
2018-12-13 13:39:08 +05:30
2019-10-12 21:52:04 +05:30
expect(vm.$el.querySelector('.js-build-trace').textContent.trim()).toContain(
'Different',
);
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +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('truncated information', () => {
describe('when size is less than total', () => {
it('shows information about truncated log', done => {
mock.onGet(`${props.pagePath}/trace.json`).reply(200, {
html: '<span>Update</span>',
status: 'success',
append: false,
size: 50,
total: 100,
complete: true,
});
2019-10-12 21:52:04 +05:30
setupAndMount({
traceData: {
html: '<span>Update</span>',
status: 'success',
append: false,
size: 50,
total: 100,
complete: true,
},
})
.then(() => {
expect(vm.$el.querySelector('.js-truncated-info').textContent.trim()).toContain(
'50 bytes',
);
})
.then(done)
.catch(done.fail);
2018-12-13 13:39:08 +05:30
});
});
describe('when size is equal than total', () => {
it('does not show the truncated information', done => {
2019-10-12 21:52:04 +05:30
setupAndMount({
traceData: {
html: '<span>Update</span>',
status: 'success',
append: false,
size: 100,
total: 100,
complete: true,
},
})
.then(() => {
expect(vm.$el.querySelector('.js-truncated-info').textContent.trim()).not.toContain(
'50 bytes',
);
})
.then(done)
.catch(done.fail);
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('trace controls', () => {
2019-10-12 21:52:04 +05:30
beforeEach(done => {
setupAndMount({
traceData: {
html: '<span>Update</span>',
status: 'success',
append: false,
size: 50,
total: 100,
complete: true,
},
})
.then(done)
.catch(done.fail);
2018-12-05 23:21:45 +05:30
});
2019-10-12 21:52:04 +05:30
it('should render scroll buttons', () => {
expect(vm.$el.querySelector('.js-scroll-top')).not.toBeNull();
expect(vm.$el.querySelector('.js-scroll-bottom')).not.toBeNull();
2018-12-13 13:39:08 +05:30
});
2019-10-12 21:52:04 +05:30
it('should render link to raw ouput', () => {
expect(vm.$el.querySelector('.js-raw-link-controller')).not.toBeNull();
2018-12-13 13:39:08 +05:30
});
2019-10-12 21:52:04 +05:30
it('should render link to erase job', () => {
expect(vm.$el.querySelector('.js-erase-link')).not.toBeNull();
2018-12-13 13:39:08 +05:30
});
2018-12-05 23:21:45 +05:30
});
});
});