2018-01-31 04:27:30 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2018-01-30 11:33:23 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-12-27 09:17:28 -05:00
|
|
|
import { numberToHumanSize } from '~/lib/utils/number_utils';
|
2017-12-07 07:30:53 -05:00
|
|
|
import * as urlUtils from '~/lib/utils/url_utility';
|
2017-04-18 08:27:10 -04:00
|
|
|
import '~/lib/utils/datetime_utility';
|
2017-10-10 07:06:42 -04:00
|
|
|
import Job from '~/job';
|
2017-04-18 08:27:10 -04:00
|
|
|
import '~/breakpoints';
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
describe('Job', () => {
|
|
|
|
const JOB_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1`;
|
2018-01-30 11:33:23 -05:00
|
|
|
let mock;
|
|
|
|
let response;
|
|
|
|
|
|
|
|
function waitForPromise() {
|
|
|
|
return new Promise(resolve => requestAnimationFrame(resolve));
|
|
|
|
}
|
2016-11-19 16:48:49 -05:00
|
|
|
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures('builds/build-with-artifacts.html.raw');
|
2016-11-19 16:48:49 -05:00
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
beforeEach(() => {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures('builds/build-with-artifacts.html.raw');
|
2018-01-30 11:33:23 -05:00
|
|
|
|
|
|
|
spyOn(urlUtils, 'visitUrl');
|
|
|
|
|
2018-01-31 04:27:30 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-01-30 11:33:23 -05:00
|
|
|
|
2018-01-31 04:27:30 -05:00
|
|
|
mock.onGet(new RegExp(`${JOB_URL}/trace.json?(.*)`)).reply(() => [200, response]);
|
2018-01-30 11:33:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
|
|
|
|
response = {};
|
2016-11-19 16:48:49 -05:00
|
|
|
});
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2017-03-16 16:13:03 -04:00
|
|
|
describe('class constructor', () => {
|
2016-11-23 15:45:39 -05:00
|
|
|
beforeEach(() => {
|
2016-11-19 16:48:49 -05:00
|
|
|
jasmine.clock().install();
|
|
|
|
});
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
afterEach(() => {
|
|
|
|
jasmine.clock().uninstall();
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
describe('setup', () => {
|
2016-10-31 10:56:55 -04:00
|
|
|
beforeEach(function () {
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
it('copies build options', function () {
|
2017-12-04 21:18:45 -05:00
|
|
|
expect(this.job.pagePath).toBe(JOB_URL);
|
2017-10-10 07:06:42 -04:00
|
|
|
expect(this.job.buildStatus).toBe('success');
|
|
|
|
expect(this.job.buildStage).toBe('test');
|
|
|
|
expect(this.job.state).toBe('');
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
it('only shows the jobs matching the current stage', () => {
|
2016-11-19 16:48:49 -05:00
|
|
|
expect($('.build-job[data-stage="build"]').is(':visible')).toBe(false);
|
|
|
|
expect($('.build-job[data-stage="test"]').is(':visible')).toBe(true);
|
|
|
|
expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);
|
|
|
|
});
|
2016-11-18 07:18:49 -05:00
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
it('selects the current stage in the build dropdown menu', () => {
|
2016-11-19 16:48:49 -05:00
|
|
|
expect($('.stage-selection').text()).toBe('test');
|
|
|
|
});
|
2016-11-18 07:18:49 -05:00
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
it('updates the jobs when the build dropdown changes', () => {
|
2016-11-19 16:48:49 -05:00
|
|
|
$('.stage-item:contains("build")').click();
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
expect($('.stage-selection').text()).toBe('build');
|
|
|
|
expect($('.build-job[data-stage="build"]').is(':visible')).toBe(true);
|
|
|
|
expect($('.build-job[data-stage="test"]').is(':visible')).toBe(false);
|
|
|
|
expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
describe('running build', () => {
|
2018-01-30 11:33:23 -05:00
|
|
|
it('updates the build trace on an interval', function (done) {
|
|
|
|
response = {
|
2016-11-19 16:48:49 -05:00
|
|
|
html: '<span>Update<span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'newstate',
|
|
|
|
append: true,
|
2017-04-07 07:13:23 -04:00
|
|
|
complete: false,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2016-11-19 16:48:49 -05:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
waitForPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
expect(this.job.state).toBe('newstate');
|
|
|
|
|
|
|
|
response = {
|
|
|
|
html: '<span>More</span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'finalstate',
|
|
|
|
append: true,
|
|
|
|
complete: true,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.then(() => jasmine.clock().tick(4001))
|
|
|
|
.then(waitForPromise)
|
|
|
|
.then(() => {
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
|
|
|
|
expect(this.job.state).toBe('finalstate');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
it('replaces the entire build trace', (done) => {
|
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update<span>',
|
2016-11-19 16:48:49 -05:00
|
|
|
status: 'running',
|
2017-04-07 07:13:23 -04:00
|
|
|
append: false,
|
|
|
|
complete: false,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
waitForPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
|
|
|
|
response = {
|
|
|
|
html: '<span>Different</span>',
|
|
|
|
status: 'running',
|
|
|
|
append: false,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.then(() => jasmine.clock().tick(4001))
|
|
|
|
.then(waitForPromise)
|
|
|
|
.then(() => {
|
|
|
|
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2016-11-19 16:48:49 -05:00
|
|
|
});
|
2017-05-30 04:43:13 -04:00
|
|
|
});
|
2017-04-18 08:27:10 -04:00
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
describe('truncated information', () => {
|
|
|
|
describe('when size is less than total', () => {
|
2018-01-30 11:33:23 -05:00
|
|
|
it('shows information about truncated log', (done) => {
|
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2017-04-18 08:27:10 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
waitForPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect(document.querySelector('.js-truncated-info').classList).not.toContain('hidden');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-05-30 04:43:13 -04:00
|
|
|
});
|
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
it('shows the size in KiB', (done) => {
|
2017-05-30 04:43:13 -04:00
|
|
|
const size = 50;
|
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size,
|
|
|
|
total: 100,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2017-04-18 08:27:10 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
waitForPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-truncated-info-size').textContent.trim(),
|
|
|
|
).toEqual(`${numberToHumanSize(size)}`);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-05-30 04:43:13 -04:00
|
|
|
});
|
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
it('shows incremented size', (done) => {
|
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
waitForPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-truncated-info-size').textContent.trim(),
|
|
|
|
).toEqual(`${numberToHumanSize(50)}`);
|
|
|
|
|
|
|
|
response = {
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: true,
|
|
|
|
size: 10,
|
|
|
|
total: 100,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.then(() => jasmine.clock().tick(4001))
|
|
|
|
.then(waitForPromise)
|
|
|
|
.then(() => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-truncated-info-size').textContent.trim(),
|
|
|
|
).toEqual(`${numberToHumanSize(60)}`);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
it('renders the raw link', () => {
|
2018-01-30 11:33:23 -05:00
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2017-04-18 08:27:10 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-04-18 08:27:10 -04:00
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
expect(
|
|
|
|
document.querySelector('.js-raw-link').textContent.trim(),
|
|
|
|
).toContain('Complete Raw');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when size is equal than total', () => {
|
2018-01-30 11:33:23 -05:00
|
|
|
it('does not show the trunctated information', (done) => {
|
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 100,
|
|
|
|
total: 100,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
waitForPromise()
|
|
|
|
.then(() => {
|
|
|
|
expect(document.querySelector('.js-truncated-info').classList).toContain('hidden');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-05-30 04:43:13 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('output trace', () => {
|
2018-01-30 11:33:23 -05:00
|
|
|
beforeEach((done) => {
|
|
|
|
response = {
|
2017-05-30 04:43:13 -04:00
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2018-01-30 11:33:23 -05:00
|
|
|
};
|
2017-05-30 04:43:13 -04:00
|
|
|
|
2017-10-10 07:06:42 -04:00
|
|
|
this.job = new Job();
|
2018-01-30 11:33:23 -05:00
|
|
|
|
|
|
|
waitForPromise()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-05-30 04:43:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render trace controls', () => {
|
|
|
|
const controllers = document.querySelector('.controllers');
|
|
|
|
|
2018-01-30 11:33:23 -05:00
|
|
|
expect(controllers.querySelector('.js-raw-link-controller')).not.toBeNull();
|
|
|
|
expect(controllers.querySelector('.js-scroll-up')).not.toBeNull();
|
|
|
|
expect(controllers.querySelector('.js-scroll-down')).not.toBeNull();
|
2017-05-30 04:43:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render received output', () => {
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-build-output').innerHTML,
|
|
|
|
).toEqual('<span>Update</span>');
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
});
|
2017-09-28 12:24:24 -04:00
|
|
|
|
|
|
|
describe('getBuildTrace', () => {
|
|
|
|
it('should request build trace with state parameter', (done) => {
|
2018-01-30 11:33:23 -05:00
|
|
|
spyOn(axios, 'get').and.callThrough();
|
2017-10-10 07:06:42 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Job();
|
2017-09-28 12:24:24 -04:00
|
|
|
|
|
|
|
setTimeout(() => {
|
2018-01-30 11:33:23 -05:00
|
|
|
expect(axios.get).toHaveBeenCalledWith(
|
|
|
|
`${JOB_URL}/trace.json`, { params: { state: '' } },
|
2017-09-28 12:24:24 -04:00
|
|
|
);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
});
|
2016-11-19 16:48:49 -05:00
|
|
|
});
|