Commit d100f843 authored by winniehell's avatar winniehell

Remove unnecessary IIFE from build_spec

parent aae82d76
...@@ -9,183 +9,181 @@ ...@@ -9,183 +9,181 @@
//= require jquery.nicescroll //= require jquery.nicescroll
//= require turbolinks //= require turbolinks
(() => { describe('Build', () => {
describe('Build', () => { // see spec/factories/ci/builds.rb
// see spec/factories/ci/builds.rb const BUILD_TRACE = 'BUILD TRACE';
const BUILD_TRACE = 'BUILD TRACE'; // see lib/ci/ansi2html.rb
// see lib/ci/ansi2html.rb const INITIAL_BUILD_TRACE_STATE = window.btoa(JSON.stringify({
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,
offset: BUILD_TRACE.length, n_open_tags: 0, fg_color: null, bg_color: null, style_mask: 0, }));
}));
fixture.preload('builds/build-with-artifacts.html.raw');
fixture.preload('builds/build-with-artifacts.html.raw');
beforeEach(function () {
fixture.load('builds/build-with-artifacts.html.raw');
spyOn($, 'ajax');
});
describe('constructor', () => {
beforeEach(function () { beforeEach(function () {
fixture.load('builds/build-with-artifacts.html.raw'); jasmine.clock().install();
spyOn($, 'ajax'); });
afterEach(() => {
jasmine.clock().uninstall();
}); });
describe('constructor', () => { describe('setup', function () {
beforeEach(function () { beforeEach(function () {
jasmine.clock().install(); this.build = new Build();
}); });
afterEach(() => { it('copies build options', function () {
jasmine.clock().uninstall(); expect(this.build.pageUrl).toBe('http://test.host/namespace1/project1/builds/1');
expect(this.build.buildUrl).toBe('http://test.host/namespace1/project1/builds/1.json');
expect(this.build.buildStatus).toBe('success');
expect(this.build.buildStage).toBe('test');
expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE);
}); });
describe('setup', function () { it('only shows the jobs matching the current stage', function () {
beforeEach(function () { expect($('.build-job[data-stage="build"]').is(':visible')).toBe(false);
this.build = new Build(); expect($('.build-job[data-stage="test"]').is(':visible')).toBe(true);
}); expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);
});
it('copies build options', function () { it('selects the current stage in the build dropdown menu', function () {
expect(this.build.pageUrl).toBe('http://test.host/namespace1/project1/builds/1'); expect($('.stage-selection').text()).toBe('test');
expect(this.build.buildUrl).toBe('http://test.host/namespace1/project1/builds/1.json'); });
expect(this.build.buildStatus).toBe('success');
expect(this.build.buildStage).toBe('test');
expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE);
});
it('only shows the jobs matching the current stage', function () { it('updates the jobs when the build dropdown changes', function () {
expect($('.build-job[data-stage="build"]').is(':visible')).toBe(false); $('.stage-item:contains("build")').click();
expect($('.build-job[data-stage="test"]').is(':visible')).toBe(true);
expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);
});
it('selects the current stage in the build dropdown menu', function () { expect($('.stage-selection').text()).toBe('build');
expect($('.stage-selection').text()).toBe('test'); 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);
});
it('updates the jobs when the build dropdown changes', function () { it('displays the remove date correctly', function () {
$('.stage-item:contains("build")').click(); const removeDateElement = document.querySelector('.js-artifacts-remove');
expect(removeDateElement.innerText.trim()).toBe('1 year');
});
});
expect($('.stage-selection').text()).toBe('build'); describe('initial build trace', function () {
expect($('.build-job[data-stage="build"]').is(':visible')).toBe(true); beforeEach(function () {
expect($('.build-job[data-stage="test"]').is(':visible')).toBe(false); new Build();
expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false); });
});
it('displays the remove date correctly', function () { it('displays the initial build trace', function () {
const removeDateElement = document.querySelector('.js-artifacts-remove'); expect($.ajax.calls.count()).toBe(1);
expect(removeDateElement.innerText.trim()).toBe('1 year'); const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0);
}); expect(url).toBe('http://test.host/namespace1/project1/builds/1.json');
expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function));
success.call(context, { trace_html: '<span>Example</span>', status: 'running' });
expect($('#build-trace .js-build-output').text()).toMatch(/Example/);
}); });
describe('initial build trace', function () { it('removes the spinner', function () {
beforeEach(function () { const [{ success, context }] = $.ajax.calls.argsFor(0);
new Build(); success.call(context, { trace_html: '<span>Example</span>', status: 'success' });
});
it('displays the initial build trace', function () { expect($('.js-build-refresh').length).toBe(0);
expect($.ajax.calls.count()).toBe(1); });
const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0); });
expect(url).toBe('http://test.host/namespace1/project1/builds/1.json');
expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function));
success.call(context, { trace_html: '<span>Example</span>', status: 'running' }); describe('running build', function () {
beforeEach(function () {
$('.js-build-options').data('buildStatus', 'running');
this.build = new Build();
spyOn(this.build, 'location')
.and.returnValue('http://test.host/namespace1/project1/builds/1');
});
expect($('#build-trace .js-build-output').text()).toMatch(/Example/); 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(
`http://test.host/namespace1/project1/builds/1/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}`
);
expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function));
success.call(context, {
html: '<span>Update<span>',
status: 'running',
state: 'newstate',
append: true,
}); });
it('removes the spinner', function () { expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
const [{ success, context }] = $.ajax.calls.argsFor(0); expect(this.build.state).toBe('newstate');
success.call(context, { trace_html: '<span>Example</span>', status: 'success' });
jasmine.clock().tick(4001);
expect($('.js-build-refresh').length).toBe(0); expect($.ajax.calls.count()).toBe(3);
[{ url, dataType, success, context }] = $.ajax.calls.argsFor(2);
expect(url).toBe(
'http://test.host/namespace1/project1/builds/1/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',
append: true,
}); });
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
expect(this.build.state).toBe('finalstate');
}); });
describe('running build', function () { it('replaces the entire build trace', function () {
beforeEach(function () { jasmine.clock().tick(4001);
$('.js-build-options').data('buildStatus', 'running'); let [{ success, context }] = $.ajax.calls.argsFor(1);
this.build = new Build(); success.call(context, {
spyOn(this.build, 'location') html: '<span>Update</span>',
.and.returnValue('http://test.host/namespace1/project1/builds/1'); status: 'running',
append: true,
}); });
it('updates the build trace on an interval', function () { expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
jasmine.clock().tick(4001);
expect($.ajax.calls.count()).toBe(2);
let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1);
expect(url).toBe(
`http://test.host/namespace1/project1/builds/1/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}`
);
expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function));
success.call(context, {
html: '<span>Update<span>',
status: 'running',
state: 'newstate',
append: true,
});
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);
[{ url, dataType, success, context }] = $.ajax.calls.argsFor(2);
expect(url).toBe(
'http://test.host/namespace1/project1/builds/1/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',
append: true,
});
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
expect(this.build.state).toBe('finalstate');
});
it('replaces the entire build trace', function () { jasmine.clock().tick(4001);
jasmine.clock().tick(4001); [{ success, context }] = $.ajax.calls.argsFor(2);
let [{ success, context }] = $.ajax.calls.argsFor(1); success.call(context, {
success.call(context, { html: '<span>Different</span>',
html: '<span>Update</span>', status: 'running',
status: 'running', append: false,
append: true,
});
expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
jasmine.clock().tick(4001);
[{ success, context }] = $.ajax.calls.argsFor(2);
success.call(context, {
html: '<span>Different</span>',
status: 'running',
append: false,
});
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
}); });
it('reloads the page when the build is done', function () { expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
spyOn(Turbolinks, 'visit'); expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
});
jasmine.clock().tick(4001); it('reloads the page when the build is done', function () {
const [{ success, context }] = $.ajax.calls.argsFor(1); spyOn(Turbolinks, 'visit');
success.call(context, {
html: '<span>Final</span>',
status: 'passed',
append: true,
});
expect(Turbolinks.visit).toHaveBeenCalledWith( jasmine.clock().tick(4001);
'http://test.host/namespace1/project1/builds/1' const [{ success, context }] = $.ajax.calls.argsFor(1);
); success.call(context, {
html: '<span>Final</span>',
status: 'passed',
append: true,
}); });
expect(Turbolinks.visit).toHaveBeenCalledWith(
'http://test.host/namespace1/project1/builds/1'
);
}); });
}); });
}); });
})(); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment