2016-10-31 10:56:55 -04:00
|
|
|
/* eslint-disable no-new */
|
2016-11-21 18:19:51 -05:00
|
|
|
/* global Build */
|
|
|
|
/* global Turbolinks */
|
|
|
|
|
2016-11-18 06:32:52 -05:00
|
|
|
//= require lib/utils/timeago
|
|
|
|
//= require lib/utils/datetime_utility
|
2016-09-20 11:50:32 -04:00
|
|
|
//= require build
|
|
|
|
//= require breakpoints
|
|
|
|
//= require jquery.nicescroll
|
|
|
|
//= require turbolinks
|
|
|
|
|
|
|
|
(() => {
|
|
|
|
describe('Build', () => {
|
|
|
|
fixture.preload('build.html');
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
beforeEach(function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
fixture.load('build.html');
|
|
|
|
spyOn($, 'ajax');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('constructor', () => {
|
2016-10-31 10:56:55 -04:00
|
|
|
beforeEach(function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
jasmine.clock().install();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jasmine.clock().uninstall();
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
describe('setup', function () {
|
2016-11-18 07:18:49 -05:00
|
|
|
const removeDate = new Date();
|
|
|
|
removeDate.setUTCFullYear(removeDate.getUTCFullYear() + 1);
|
|
|
|
// give the test three days to run
|
|
|
|
removeDate.setTime(removeDate.getTime() + (3 * 24 * 60 * 60 * 1000));
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
beforeEach(function () {
|
2016-11-18 07:18:49 -05:00
|
|
|
const removeDateElement = document.querySelector('.js-artifacts-remove');
|
|
|
|
removeDateElement.innerText = removeDate.toString();
|
|
|
|
|
2016-09-20 11:50:32 -04:00
|
|
|
this.build = new Build();
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('copies build options', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
expect(this.build.pageUrl).toBe('http://example.com/root/test-build/builds/2');
|
|
|
|
expect(this.build.buildUrl).toBe('http://example.com/root/test-build/builds/2.json');
|
|
|
|
expect(this.build.buildStatus).toBe('passed');
|
|
|
|
expect(this.build.buildStage).toBe('test');
|
|
|
|
expect(this.build.state).toBe('buildstate');
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('only shows the jobs matching the current stage', function () {
|
2016-09-20 11:50:32 -04: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-10-31 10:56:55 -04:00
|
|
|
it('selects the current stage in the build dropdown menu', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
expect($('.stage-selection').text()).toBe('test');
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('updates the jobs when the build dropdown changes', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
$('.stage-item:contains("build")').click();
|
|
|
|
|
|
|
|
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-11-18 07:18:49 -05:00
|
|
|
|
|
|
|
it('displays the remove date correctly', function () {
|
|
|
|
const removeDateElement = document.querySelector('.js-artifacts-remove');
|
|
|
|
expect(removeDateElement.innerText.trim()).toBe('1 year');
|
|
|
|
});
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
describe('initial build trace', function () {
|
|
|
|
beforeEach(function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
new Build();
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('displays the initial build trace', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
expect($.ajax.calls.count()).toBe(1);
|
2016-10-31 10:56:55 -04:00
|
|
|
const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0);
|
2016-09-20 11:50:32 -04:00
|
|
|
expect(url).toBe('http://example.com/root/test-build/builds/2.json');
|
|
|
|
expect(dataType).toBe('json');
|
|
|
|
expect(success).toEqual(jasmine.any(Function));
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
success.call(context, { trace_html: '<span>Example</span>', status: 'running' });
|
2016-09-20 11:50:32 -04:00
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Example/);
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('removes the spinner', function () {
|
|
|
|
const [{ success, context }] = $.ajax.calls.argsFor(0);
|
|
|
|
success.call(context, { trace_html: '<span>Example</span>', status: 'success' });
|
2016-09-20 11:50:32 -04:00
|
|
|
|
|
|
|
expect($('.js-build-refresh').length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
describe('running build', function () {
|
|
|
|
beforeEach(function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
$('.js-build-options').data('buildStatus', 'running');
|
|
|
|
this.build = new Build();
|
|
|
|
spyOn(this.build, 'location')
|
|
|
|
.and.returnValue('http://example.com/root/test-build/builds/2');
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('updates the build trace on an interval', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
|
|
|
|
expect($.ajax.calls.count()).toBe(2);
|
2016-10-31 10:56:55 -04:00
|
|
|
let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1);
|
2016-09-20 11:50:32 -04:00
|
|
|
expect(url).toBe(
|
|
|
|
'http://example.com/root/test-build/builds/2/trace.json?state=buildstate'
|
|
|
|
);
|
|
|
|
expect(dataType).toBe('json');
|
|
|
|
expect(success).toEqual(jasmine.any(Function));
|
|
|
|
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Update<span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'newstate',
|
2016-10-31 10:56:55 -04:00
|
|
|
append: true,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
expect(this.build.state).toBe('newstate');
|
|
|
|
|
|
|
|
jasmine.clock().tick(4001);
|
|
|
|
|
|
|
|
expect($.ajax.calls.count()).toBe(3);
|
2016-10-31 10:56:55 -04:00
|
|
|
[{ url, dataType, success, context }] = $.ajax.calls.argsFor(2);
|
2016-09-20 11:50:32 -04:00
|
|
|
expect(url).toBe(
|
|
|
|
'http://example.com/root/test-build/builds/2/trace.json?state=newstate'
|
|
|
|
);
|
|
|
|
expect(dataType).toBe('json');
|
|
|
|
expect(success).toEqual(jasmine.any(Function));
|
|
|
|
|
|
|
|
success.call(context, {
|
|
|
|
html: '<span>More</span>',
|
|
|
|
status: 'running',
|
|
|
|
state: 'finalstate',
|
2016-10-31 10:56:55 -04:00
|
|
|
append: true,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
|
|
|
|
expect(this.build.state).toBe('finalstate');
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('replaces the entire build trace', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
jasmine.clock().tick(4001);
|
2016-10-31 10:56:55 -04:00
|
|
|
let [{ success, context }] = $.ajax.calls.argsFor(1);
|
2016-09-20 11:50:32 -04:00
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Update</span>',
|
|
|
|
status: 'running',
|
2016-10-31 10:56:55 -04:00
|
|
|
append: true,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
|
|
|
|
|
|
|
|
jasmine.clock().tick(4001);
|
2016-10-31 10:56:55 -04:00
|
|
|
[{ success, context }] = $.ajax.calls.argsFor(2);
|
2016-09-20 11:50:32 -04:00
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Different</span>',
|
|
|
|
status: 'running',
|
2016-10-31 10:56:55 -04:00
|
|
|
append: false,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
|
|
|
|
expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
|
|
|
|
});
|
|
|
|
|
2016-10-31 10:56:55 -04:00
|
|
|
it('reloads the page when the build is done', function () {
|
2016-09-20 11:50:32 -04:00
|
|
|
spyOn(Turbolinks, 'visit');
|
|
|
|
|
|
|
|
jasmine.clock().tick(4001);
|
2016-10-31 10:56:55 -04:00
|
|
|
const [{ success, context }] = $.ajax.calls.argsFor(1);
|
2016-09-20 11:50:32 -04:00
|
|
|
success.call(context, {
|
|
|
|
html: '<span>Final</span>',
|
|
|
|
status: 'passed',
|
2016-10-31 10:56:55 -04:00
|
|
|
append: true,
|
2016-09-20 11:50:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(Turbolinks.visit).toHaveBeenCalledWith(
|
|
|
|
'http://example.com/root/test-build/builds/2'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|