2016-10-31 10:56:55 -04:00
|
|
|
/* eslint-disable no-new */
|
2016-11-21 18:19:51 -05:00
|
|
|
/* global Build */
|
2017-04-18 08:27:10 -04:00
|
|
|
import { bytesToKiB } from '~/lib/utils/number_utils';
|
|
|
|
import '~/lib/utils/datetime_utility';
|
|
|
|
import '~/lib/utils/url_utility';
|
|
|
|
import '~/build';
|
|
|
|
import '~/breakpoints';
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
describe('Build', () => {
|
2017-05-26 09:55:29 -04:00
|
|
|
const BUILD_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1`;
|
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');
|
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 () {
|
2016-11-19 16:48:49 -05:00
|
|
|
this.build = new Build();
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
it('copies build options', function () {
|
2016-11-19 16:59:32 -05:00
|
|
|
expect(this.build.pageUrl).toBe(BUILD_URL);
|
2016-11-19 16:48:49 -05:00
|
|
|
expect(this.build.buildStatus).toBe('success');
|
|
|
|
expect(this.build.buildStage).toBe('test');
|
2017-02-10 13:40:25 -05:00
|
|
|
expect(this.build.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
|
|
|
it('displays the remove date correctly', () => {
|
2016-11-19 16:48:49 -05:00
|
|
|
const removeDateElement = document.querySelector('.js-artifacts-remove');
|
2017-06-07 16:13:44 -04:00
|
|
|
expect(removeDateElement.innerText.trim()).toBe('1 year remaining');
|
2016-11-19 16:48:49 -05:00
|
|
|
});
|
|
|
|
});
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
describe('running build', () => {
|
2016-11-19 16:48:49 -05:00
|
|
|
it('updates the build trace on an interval', function () {
|
2017-05-30 04:43:13 -04:00
|
|
|
const deferred1 = $.Deferred();
|
|
|
|
const deferred2 = $.Deferred();
|
|
|
|
const deferred3 = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValues(deferred1.promise(), deferred2.promise(), deferred3.promise());
|
2017-04-07 07:13:23 -04:00
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred1.resolve({
|
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,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred2.resolve();
|
2016-11-19 16:48:49 -05:00
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred3.resolve({
|
2016-11-19 16:48:49 -05:00
|
|
|
html: '<span>More</span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'finalstate',
|
|
|
|
append: true,
|
2017-04-07 07:13:23 -04:00
|
|
|
complete: true,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
2016-11-19 16:48:49 -05:00
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
this.build = new Build();
|
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
expect(this.build.state).toBe('newstate');
|
|
|
|
|
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
|
|
|
|
expect(this.build.state).toBe('finalstate');
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2016-11-23 15:45:39 -05:00
|
|
|
it('replaces the entire build trace', () => {
|
2017-05-30 04:43:13 -04:00
|
|
|
const deferred1 = $.Deferred();
|
|
|
|
const deferred2 = $.Deferred();
|
|
|
|
const deferred3 = $.Deferred();
|
|
|
|
|
|
|
|
spyOn($, 'ajax').and.returnValues(deferred1.promise(), deferred2.promise(), deferred3.promise());
|
|
|
|
|
2017-04-07 07:13:23 -04:00
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred1.resolve({
|
|
|
|
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,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred2.resolve();
|
2016-09-20 11:50:32 -04:00
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred3.resolve({
|
2016-11-19 16:48:49 -05:00
|
|
|
html: '<span>Different</span>',
|
|
|
|
status: 'running',
|
|
|
|
append: false,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
this.build = new Build();
|
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
|
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
|
2016-11-19 16:48:49 -05:00
|
|
|
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
|
|
|
|
});
|
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', () => {
|
|
|
|
it('shows information about truncated log', () => {
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
|
|
|
|
deferred.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
this.build = new Build();
|
|
|
|
|
|
|
|
expect(document.querySelector('.js-truncated-info').classList).not.toContain('hidden');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the size in KiB', () => {
|
|
|
|
const size = 50;
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
deferred.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size,
|
|
|
|
total: 100,
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
this.build = new Build();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-truncated-info-size').textContent.trim(),
|
|
|
|
).toEqual(`${bytesToKiB(size)}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows incremented size', () => {
|
|
|
|
const deferred1 = $.Deferred();
|
|
|
|
const deferred2 = $.Deferred();
|
|
|
|
const deferred3 = $.Deferred();
|
|
|
|
|
|
|
|
spyOn($, 'ajax').and.returnValues(deferred1.promise(), deferred2.promise(), deferred3.promise());
|
|
|
|
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
|
|
|
|
deferred1.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
deferred2.resolve();
|
|
|
|
|
|
|
|
this.build = new Build();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-truncated-info-size').textContent.trim(),
|
|
|
|
).toEqual(`${bytesToKiB(50)}`);
|
|
|
|
|
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
|
|
|
|
deferred3.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: true,
|
|
|
|
size: 10,
|
|
|
|
total: 100,
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
2017-05-30 04:43:13 -04:00
|
|
|
|
|
|
|
expect(
|
|
|
|
document.querySelector('.js-truncated-info-size').textContent.trim(),
|
|
|
|
).toEqual(`${bytesToKiB(60)}`);
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
it('renders the raw link', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
deferred.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
|
|
|
});
|
2017-04-18 08:27:10 -04:00
|
|
|
|
2017-05-30 04:43:13 -04:00
|
|
|
this.build = new Build();
|
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', () => {
|
|
|
|
it('does not show the trunctated information', () => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
deferred.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 100,
|
|
|
|
total: 100,
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
2017-05-30 04:43:13 -04:00
|
|
|
|
|
|
|
this.build = new Build();
|
|
|
|
|
|
|
|
expect(document.querySelector('.js-truncated-info').classList).toContain('hidden');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('output trace', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const deferred = $.Deferred();
|
|
|
|
spyOn(gl.utils, 'visitUrl');
|
|
|
|
|
|
|
|
spyOn($, 'ajax').and.returnValue(deferred.promise());
|
|
|
|
deferred.resolve({
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'success',
|
|
|
|
append: false,
|
|
|
|
size: 50,
|
|
|
|
total: 100,
|
2017-04-18 08:27:10 -04:00
|
|
|
});
|
2017-05-30 04:43:13 -04:00
|
|
|
|
|
|
|
this.build = new Build();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render trace controls', () => {
|
|
|
|
const controllers = document.querySelector('.controllers');
|
|
|
|
|
|
|
|
expect(controllers.querySelector('.js-raw-link-controller')).toBeDefined();
|
|
|
|
expect(controllers.querySelector('.js-erase-link')).toBeDefined();
|
|
|
|
expect(controllers.querySelector('.js-scroll-up')).toBeDefined();
|
|
|
|
expect(controllers.querySelector('.js-scroll-down')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
2016-11-19 16:48:49 -05:00
|
|
|
});
|