2016-10-31 14:56:55 +00:00
|
|
|
/* eslint-disable no-new */
|
2016-11-21 23:19:51 +00:00
|
|
|
/* global Build */
|
|
|
|
/* global Turbolinks */
|
|
|
|
|
2016-11-18 11:32:52 +00:00
|
|
|
//= require lib/utils/datetime_utility
|
2016-09-20 15:50:32 +00:00
|
|
|
//= require build
|
|
|
|
//= require breakpoints
|
|
|
|
//= require jquery.nicescroll
|
|
|
|
//= require turbolinks
|
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
describe('Build', () => {
|
2016-11-19 23:40:37 +00:00
|
|
|
const BUILD_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/builds/1`;
|
2016-11-19 21:48:49 +00:00
|
|
|
// see spec/factories/ci/builds.rb
|
|
|
|
const BUILD_TRACE = 'BUILD TRACE';
|
|
|
|
// see lib/ci/ansi2html.rb
|
|
|
|
const INITIAL_BUILD_TRACE_STATE = window.btoa(JSON.stringify({
|
|
|
|
offset: BUILD_TRACE.length, n_open_tags: 0, fg_color: null, bg_color: null, style_mask: 0,
|
|
|
|
}));
|
|
|
|
|
2016-12-31 00:14:33 +00:00
|
|
|
preloadFixtures('builds/build-with-artifacts.html.raw');
|
2016-11-19 21:48:49 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
beforeEach(() => {
|
2016-12-31 00:14:33 +00:00
|
|
|
loadFixtures('builds/build-with-artifacts.html.raw');
|
2016-11-19 21:48:49 +00:00
|
|
|
spyOn($, 'ajax');
|
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
describe('constructor', () => {
|
2016-11-23 20:45:39 +00:00
|
|
|
beforeEach(() => {
|
2016-11-19 21:48:49 +00:00
|
|
|
jasmine.clock().install();
|
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
afterEach(() => {
|
|
|
|
jasmine.clock().uninstall();
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
describe('setup', () => {
|
2016-10-31 14:56:55 +00:00
|
|
|
beforeEach(function () {
|
2016-11-19 21:48:49 +00:00
|
|
|
this.build = new Build();
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
it('copies build options', function () {
|
2016-11-19 21:59:32 +00:00
|
|
|
expect(this.build.pageUrl).toBe(BUILD_URL);
|
|
|
|
expect(this.build.buildUrl).toBe(`${BUILD_URL}.json`);
|
2016-11-19 21:48:49 +00:00
|
|
|
expect(this.build.buildStatus).toBe('success');
|
|
|
|
expect(this.build.buildStage).toBe('test');
|
|
|
|
expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE);
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('only shows the jobs matching the current stage', () => {
|
2016-11-19 21:48:49 +00: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 12:18:49 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('selects the current stage in the build dropdown menu', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($('.stage-selection').text()).toBe('test');
|
|
|
|
});
|
2016-11-18 12:18:49 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('updates the jobs when the build dropdown changes', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
$('.stage-item:contains("build")').click();
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00: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 15:50:32 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('displays the remove date correctly', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
const removeDateElement = document.querySelector('.js-artifacts-remove');
|
|
|
|
expect(removeDateElement.innerText.trim()).toBe('1 year');
|
|
|
|
});
|
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
describe('initial build trace', () => {
|
|
|
|
beforeEach(() => {
|
2016-11-19 21:48:49 +00:00
|
|
|
new Build();
|
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('displays the initial build trace', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($.ajax.calls.count()).toBe(1);
|
|
|
|
const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0);
|
2016-11-19 21:59:32 +00:00
|
|
|
expect(url).toBe(`${BUILD_URL}.json`);
|
2016-11-19 21:48:49 +00:00
|
|
|
expect(dataType).toBe('json');
|
|
|
|
expect(success).toEqual(jasmine.any(Function));
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
success.call(context, { trace_html: '<span>Example</span>', status: 'running' });
|
2016-11-18 12:18:49 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Example/);
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('removes the spinner', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
const [{ success, context }] = $.ajax.calls.argsFor(0);
|
|
|
|
success.call(context, { trace_html: '<span>Example</span>', status: 'success' });
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($('.js-build-refresh').length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
describe('running build', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
$('.js-build-options').data('buildStatus', 'running');
|
|
|
|
this.build = new Build();
|
2016-11-19 21:59:32 +00:00
|
|
|
spyOn(this.build, 'location').and.returnValue(BUILD_URL);
|
2016-11-19 21:48:49 +00:00
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
it('updates the build trace on an interval', function () {
|
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
|
|
|
|
expect($.ajax.calls.count()).toBe(2);
|
|
|
|
let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1);
|
|
|
|
expect(url).toBe(
|
2016-11-14 22:37:13 +00:00
|
|
|
`${BUILD_URL}/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}`,
|
2016-11-19 21:48:49 +00:00
|
|
|
);
|
|
|
|
expect(dataType).toBe('json');
|
|
|
|
expect(success).toEqual(jasmine.any(Function));
|
|
|
|
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Update<span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'newstate',
|
|
|
|
append: true,
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
expect(this.build.state).toBe('newstate');
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
jasmine.clock().tick(4001);
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($.ajax.calls.count()).toBe(3);
|
|
|
|
[{ url, dataType, success, context }] = $.ajax.calls.argsFor(2);
|
2016-11-19 21:59:32 +00:00
|
|
|
expect(url).toBe(`${BUILD_URL}/trace.json?state=newstate`);
|
2016-11-19 21:48:49 +00:00
|
|
|
expect(dataType).toBe('json');
|
|
|
|
expect(success).toEqual(jasmine.any(Function));
|
|
|
|
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>More</span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'finalstate',
|
|
|
|
append: true,
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
2016-11-19 21:48:49 +00:00
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
|
|
|
|
expect(this.build.state).toBe('finalstate');
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('replaces the entire build trace', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
let [{ success, context }] = $.ajax.calls.argsFor(1);
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'running',
|
|
|
|
append: true,
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
[{ success, context }] = $.ajax.calls.argsFor(2);
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Different</span>',
|
|
|
|
status: 'running',
|
|
|
|
append: false,
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
|
|
|
|
});
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-23 20:45:39 +00:00
|
|
|
it('reloads the page when the build is done', () => {
|
2016-11-19 21:48:49 +00:00
|
|
|
spyOn(Turbolinks, 'visit');
|
2016-09-20 15:50:32 +00:00
|
|
|
|
2016-11-19 21:48:49 +00:00
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
const [{ success, context }] = $.ajax.calls.argsFor(1);
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Final</span>',
|
|
|
|
status: 'passed',
|
|
|
|
append: true,
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
2016-11-19 21:48:49 +00:00
|
|
|
|
2016-11-19 21:59:32 +00:00
|
|
|
expect(Turbolinks.visit).toHaveBeenCalledWith(BUILD_URL);
|
2016-09-20 15:50:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-11-19 21:48:49 +00:00
|
|
|
});
|