Commit 4f377364 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Added new .eslintrc for jasmine tests and corrected build_spec

parent dd45c5e1
{
"plugins": ["jasmine"],
"env": {
"jasmine": true
},
"extends": "plugin:jasmine/recommended",
"rules": {
"prefer-arrow-callback": 0,
"func-names": 0
}
}
/* eslint-disable */ /* global Build */
/* eslint-disable no-new */
//= require build //= require build
//= require breakpoints //= require breakpoints
//= require jquery.nicescroll //= require jquery.nicescroll
...@@ -8,13 +9,13 @@ ...@@ -8,13 +9,13 @@
describe('Build', () => { describe('Build', () => {
fixture.preload('build.html'); fixture.preload('build.html');
beforeEach(function() { beforeEach(function () {
fixture.load('build.html'); fixture.load('build.html');
spyOn($, 'ajax'); spyOn($, 'ajax');
}); });
describe('constructor', () => { describe('constructor', () => {
beforeEach(function() { beforeEach(function () {
jasmine.clock().install(); jasmine.clock().install();
}); });
...@@ -22,12 +23,12 @@ ...@@ -22,12 +23,12 @@
jasmine.clock().uninstall(); jasmine.clock().uninstall();
}); });
describe('setup', function() { describe('setup', function () {
beforeEach(function() { beforeEach(function () {
this.build = new Build(); this.build = new Build();
}); });
it('copies build options', function() { it('copies build options', function () {
expect(this.build.pageUrl).toBe('http://example.com/root/test-build/builds/2'); 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.buildUrl).toBe('http://example.com/root/test-build/builds/2.json');
expect(this.build.buildStatus).toBe('passed'); expect(this.build.buildStatus).toBe('passed');
...@@ -35,17 +36,17 @@ ...@@ -35,17 +36,17 @@
expect(this.build.state).toBe('buildstate'); expect(this.build.state).toBe('buildstate');
}); });
it('only shows the jobs matching the current stage', function() { it('only shows the jobs matching the current stage', function () {
expect($('.build-job[data-stage="build"]').is(':visible')).toBe(false); 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="test"]').is(':visible')).toBe(true);
expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false); expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false);
}); });
it('selects the current stage in the build dropdown menu', function() { it('selects the current stage in the build dropdown menu', function () {
expect($('.stage-selection').text()).toBe('test'); expect($('.stage-selection').text()).toBe('test');
}); });
it('updates the jobs when the build dropdown changes', function() { it('updates the jobs when the build dropdown changes', function () {
$('.stage-item:contains("build")').click(); $('.stage-item:contains("build")').click();
expect($('.stage-selection').text()).toBe('build'); expect($('.stage-selection').text()).toBe('build');
...@@ -55,44 +56,44 @@ ...@@ -55,44 +56,44 @@
}); });
}); });
describe('initial build trace', function() { describe('initial build trace', function () {
beforeEach(function() { beforeEach(function () {
new Build(); new Build();
}); });
it('displays the initial build trace', function() { it('displays the initial build trace', function () {
expect($.ajax.calls.count()).toBe(1); expect($.ajax.calls.count()).toBe(1);
const [{url, dataType, success, context}] = $.ajax.calls.argsFor(0); const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0);
expect(url).toBe('http://example.com/root/test-build/builds/2.json'); expect(url).toBe('http://example.com/root/test-build/builds/2.json');
expect(dataType).toBe('json'); expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function)); expect(success).toEqual(jasmine.any(Function));
success.call(context, {trace_html: '<span>Example</span>', status: 'running'}); success.call(context, { trace_html: '<span>Example</span>', status: 'running' });
expect($('#build-trace .js-build-output').text()).toMatch(/Example/); expect($('#build-trace .js-build-output').text()).toMatch(/Example/);
}); });
it('removes the spinner', function() { it('removes the spinner', function () {
const [{success, context}] = $.ajax.calls.argsFor(0); const [{ success, context }] = $.ajax.calls.argsFor(0);
success.call(context, {trace_html: '<span>Example</span>', status: 'success'}); success.call(context, { trace_html: '<span>Example</span>', status: 'success' });
expect($('.js-build-refresh').length).toBe(0); expect($('.js-build-refresh').length).toBe(0);
}); });
}); });
describe('running build', function() { describe('running build', function () {
beforeEach(function() { beforeEach(function () {
$('.js-build-options').data('buildStatus', 'running'); $('.js-build-options').data('buildStatus', 'running');
this.build = new Build(); this.build = new Build();
spyOn(this.build, 'location') spyOn(this.build, 'location')
.and.returnValue('http://example.com/root/test-build/builds/2'); .and.returnValue('http://example.com/root/test-build/builds/2');
}); });
it('updates the build trace on an interval', function() { it('updates the build trace on an interval', function () {
jasmine.clock().tick(4001); jasmine.clock().tick(4001);
expect($.ajax.calls.count()).toBe(2); expect($.ajax.calls.count()).toBe(2);
let [{url, dataType, success, context}] = $.ajax.calls.argsFor(1); let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1);
expect(url).toBe( expect(url).toBe(
'http://example.com/root/test-build/builds/2/trace.json?state=buildstate' 'http://example.com/root/test-build/builds/2/trace.json?state=buildstate'
); );
...@@ -103,7 +104,7 @@ ...@@ -103,7 +104,7 @@
html: '<span>Update<span>', html: '<span>Update<span>',
status: 'running', status: 'running',
state: 'newstate', state: 'newstate',
append: true append: true,
}); });
expect($('#build-trace .js-build-output').text()).toMatch(/Update/); expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
...@@ -112,7 +113,7 @@ ...@@ -112,7 +113,7 @@
jasmine.clock().tick(4001); jasmine.clock().tick(4001);
expect($.ajax.calls.count()).toBe(3); expect($.ajax.calls.count()).toBe(3);
[{url, dataType, success, context}] = $.ajax.calls.argsFor(2); [{ url, dataType, success, context }] = $.ajax.calls.argsFor(2);
expect(url).toBe( expect(url).toBe(
'http://example.com/root/test-build/builds/2/trace.json?state=newstate' 'http://example.com/root/test-build/builds/2/trace.json?state=newstate'
); );
...@@ -123,45 +124,45 @@ ...@@ -123,45 +124,45 @@
html: '<span>More</span>', html: '<span>More</span>',
status: 'running', status: 'running',
state: 'finalstate', state: 'finalstate',
append: true append: true,
}); });
expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/); expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/);
expect(this.build.state).toBe('finalstate'); expect(this.build.state).toBe('finalstate');
}); });
it('replaces the entire build trace', function() { it('replaces the entire build trace', function () {
jasmine.clock().tick(4001); jasmine.clock().tick(4001);
let [{success, context}] = $.ajax.calls.argsFor(1); let [{ success, context }] = $.ajax.calls.argsFor(1);
success.call(context, { success.call(context, {
html: '<span>Update</span>', html: '<span>Update</span>',
status: 'running', status: 'running',
append: true append: true,
}); });
expect($('#build-trace .js-build-output').text()).toMatch(/Update/); expect($('#build-trace .js-build-output').text()).toMatch(/Update/);
jasmine.clock().tick(4001); jasmine.clock().tick(4001);
[{success, context}] = $.ajax.calls.argsFor(2); [{ success, context }] = $.ajax.calls.argsFor(2);
success.call(context, { success.call(context, {
html: '<span>Different</span>', html: '<span>Different</span>',
status: 'running', status: 'running',
append: false append: false,
}); });
expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/); expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/);
expect($('#build-trace .js-build-output').text()).toMatch(/Different/); expect($('#build-trace .js-build-output').text()).toMatch(/Different/);
}); });
it('reloads the page when the build is done', function() { it('reloads the page when the build is done', function () {
spyOn(Turbolinks, 'visit'); spyOn(Turbolinks, 'visit');
jasmine.clock().tick(4001); jasmine.clock().tick(4001);
let [{success, context}] = $.ajax.calls.argsFor(1); const [{ success, context }] = $.ajax.calls.argsFor(1);
success.call(context, { success.call(context, {
html: '<span>Final</span>', html: '<span>Final</span>',
status: 'passed', status: 'passed',
append: true append: true,
}); });
expect(Turbolinks.visit).toHaveBeenCalledWith( expect(Turbolinks.visit).toHaveBeenCalledWith(
......
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