From dd45c5e11eb2b315d89779abf6103e2531e1cc08 Mon Sep 17 00:00:00 2001 From: Jared Deckard Date: Tue, 20 Sep 2016 10:50:32 -0500 Subject: Add javascript unit tests for Build Move comments to the correct location Remove array extension usage Move build options to fixture to match view --- spec/javascripts/build_spec.js.es6 | 174 +++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 spec/javascripts/build_spec.js.es6 (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 new file mode 100644 index 00000000000..44485c7745c --- /dev/null +++ b/spec/javascripts/build_spec.js.es6 @@ -0,0 +1,174 @@ +/* eslint-disable */ +//= require build +//= require breakpoints +//= require jquery.nicescroll +//= require turbolinks + +(() => { + describe('Build', () => { + fixture.preload('build.html'); + + beforeEach(function() { + fixture.load('build.html'); + spyOn($, 'ajax'); + }); + + describe('constructor', () => { + beforeEach(function() { + jasmine.clock().install(); + }); + + afterEach(() => { + jasmine.clock().uninstall(); + }); + + describe('setup', function() { + beforeEach(function() { + this.build = new Build(); + }); + + it('copies build options', function() { + 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'); + }); + + 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="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('test'); + }); + + it('updates the jobs when the build dropdown changes', function() { + $('.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); + }); + }); + + describe('initial build trace', function() { + beforeEach(function() { + new Build(); + }); + + it('displays the initial build trace', function() { + expect($.ajax.calls.count()).toBe(1); + const [{url, dataType, success, context}] = $.ajax.calls.argsFor(0); + expect(url).toBe('http://example.com/root/test-build/builds/2.json'); + expect(dataType).toBe('json'); + expect(success).toEqual(jasmine.any(Function)); + + success.call(context, {trace_html: 'Example', status: 'running'}); + + expect($('#build-trace .js-build-output').text()).toMatch(/Example/); + }); + + it('removes the spinner', function() { + const [{success, context}] = $.ajax.calls.argsFor(0); + success.call(context, {trace_html: 'Example', status: 'success'}); + + expect($('.js-build-refresh').length).toBe(0); + }); + }); + + describe('running build', function() { + beforeEach(function() { + $('.js-build-options').data('buildStatus', 'running'); + this.build = new Build(); + spyOn(this.build, 'location') + .and.returnValue('http://example.com/root/test-build/builds/2'); + }); + + 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://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: 'Update', + 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://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: 'More', + 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); + let [{success, context}] = $.ajax.calls.argsFor(1); + success.call(context, { + html: 'Update', + status: 'running', + 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: 'Different', + 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() { + spyOn(Turbolinks, 'visit'); + + jasmine.clock().tick(4001); + let [{success, context}] = $.ajax.calls.argsFor(1); + success.call(context, { + html: 'Final', + status: 'passed', + append: true + }); + + expect(Turbolinks.visit).toHaveBeenCalledWith( + 'http://example.com/root/test-build/builds/2' + ); + }); + }); + }); + }); +})(); -- cgit v1.2.1 From 4f377364ad2b073e59e8edde86f270c80cdb317a Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Mon, 31 Oct 2016 14:56:55 +0000 Subject: Added new .eslintrc for jasmine tests and corrected build_spec --- spec/javascripts/build_spec.js.es6 | 65 +++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index 44485c7745c..370944b6a8c 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -1,4 +1,5 @@ -/* eslint-disable */ +/* global Build */ +/* eslint-disable no-new */ //= require build //= require breakpoints //= require jquery.nicescroll @@ -8,13 +9,13 @@ describe('Build', () => { fixture.preload('build.html'); - beforeEach(function() { + beforeEach(function () { fixture.load('build.html'); spyOn($, 'ajax'); }); describe('constructor', () => { - beforeEach(function() { + beforeEach(function () { jasmine.clock().install(); }); @@ -22,12 +23,12 @@ jasmine.clock().uninstall(); }); - describe('setup', function() { - beforeEach(function() { + describe('setup', function () { + beforeEach(function () { 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.buildUrl).toBe('http://example.com/root/test-build/builds/2.json'); expect(this.build.buildStatus).toBe('passed'); @@ -35,17 +36,17 @@ 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="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() { + it('selects the current stage in the build dropdown menu', function () { 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(); expect($('.stage-selection').text()).toBe('build'); @@ -55,44 +56,44 @@ }); }); - describe('initial build trace', function() { - beforeEach(function() { + describe('initial build trace', function () { + beforeEach(function () { new Build(); }); - it('displays the initial build trace', function() { + it('displays the initial build trace', function () { 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(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); - success.call(context, {trace_html: 'Example', status: 'running'}); + success.call(context, { trace_html: 'Example', status: 'running' }); expect($('#build-trace .js-build-output').text()).toMatch(/Example/); }); - it('removes the spinner', function() { - const [{success, context}] = $.ajax.calls.argsFor(0); - success.call(context, {trace_html: 'Example', status: 'success'}); + it('removes the spinner', function () { + const [{ success, context }] = $.ajax.calls.argsFor(0); + success.call(context, { trace_html: 'Example', status: 'success' }); expect($('.js-build-refresh').length).toBe(0); }); }); - describe('running build', function() { - beforeEach(function() { + describe('running build', function () { + beforeEach(function () { $('.js-build-options').data('buildStatus', 'running'); this.build = new Build(); spyOn(this.build, 'location') .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); 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( 'http://example.com/root/test-build/builds/2/trace.json?state=buildstate' ); @@ -103,7 +104,7 @@ html: 'Update', status: 'running', state: 'newstate', - append: true + append: true, }); expect($('#build-trace .js-build-output').text()).toMatch(/Update/); @@ -112,7 +113,7 @@ jasmine.clock().tick(4001); 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( 'http://example.com/root/test-build/builds/2/trace.json?state=newstate' ); @@ -123,45 +124,45 @@ html: 'More', status: 'running', state: 'finalstate', - append: true + append: true, }); expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/); expect(this.build.state).toBe('finalstate'); }); - it('replaces the entire build trace', function() { + it('replaces the entire build trace', function () { jasmine.clock().tick(4001); - let [{success, context}] = $.ajax.calls.argsFor(1); + let [{ success, context }] = $.ajax.calls.argsFor(1); success.call(context, { html: 'Update', status: 'running', - append: true + append: true, }); expect($('#build-trace .js-build-output').text()).toMatch(/Update/); jasmine.clock().tick(4001); - [{success, context}] = $.ajax.calls.argsFor(2); + [{ success, context }] = $.ajax.calls.argsFor(2); success.call(context, { html: 'Different', status: 'running', - append: false + 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() { + it('reloads the page when the build is done', function () { spyOn(Turbolinks, 'visit'); jasmine.clock().tick(4001); - let [{success, context}] = $.ajax.calls.argsFor(1); + const [{ success, context }] = $.ajax.calls.argsFor(1); success.call(context, { html: 'Final', status: 'passed', - append: true + append: true, }); expect(Turbolinks.visit).toHaveBeenCalledWith( -- cgit v1.2.1 From 2a085e5edddbeb7927d8f8d4413bed8a1ff74f49 Mon Sep 17 00:00:00 2001 From: winniehell Date: Fri, 18 Nov 2016 12:32:52 +0100 Subject: Add missing require statements to build_spec --- spec/javascripts/build_spec.js.es6 | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index 370944b6a8c..b329ad8062a 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -1,5 +1,7 @@ /* global Build */ /* eslint-disable no-new */ +//= require lib/utils/timeago +//= require lib/utils/datetime_utility //= require build //= require breakpoints //= require jquery.nicescroll -- cgit v1.2.1 From 49e726ec331e2f765fae184e8e9dff42a94d5227 Mon Sep 17 00:00:00 2001 From: winniehell Date: Fri, 18 Nov 2016 13:18:49 +0100 Subject: Add failing test for #24614 --- spec/javascripts/build_spec.js.es6 | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index b329ad8062a..e21e5844a26 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -26,7 +26,15 @@ }); describe('setup', function () { + 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)); + beforeEach(function () { + const removeDateElement = document.querySelector('.js-artifacts-remove'); + removeDateElement.innerText = removeDate.toString(); + this.build = new Build(); }); @@ -56,6 +64,11 @@ expect($('.build-job[data-stage="test"]').is(':visible')).toBe(false); expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false); }); + + it('displays the remove date correctly', function () { + const removeDateElement = document.querySelector('.js-artifacts-remove'); + expect(removeDateElement.innerText.trim()).toBe('1 year'); + }); }); describe('initial build trace', function () { -- cgit v1.2.1 From bd0017c6d4e008474fcd87e979b3b4e3f93e39b1 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Mon, 21 Nov 2016 17:19:51 -0600 Subject: clean up globals exemptions within .eslintrc --- spec/javascripts/build_spec.js.es6 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index e21e5844a26..ee192c4f18a 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -1,5 +1,7 @@ -/* global Build */ /* eslint-disable no-new */ +/* global Build */ +/* global Turbolinks */ + //= require lib/utils/timeago //= require lib/utils/datetime_utility //= require build -- cgit v1.2.1 From 8ede8603b0f6910886219ab1594eff1c0bfa3252 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Tue, 22 Nov 2016 23:47:52 -0600 Subject: timeago should be a dependency of datetime_utility --- spec/javascripts/build_spec.js.es6 | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index ee192c4f18a..4208e076e96 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -2,7 +2,6 @@ /* global Build */ /* global Turbolinks */ -//= require lib/utils/timeago //= require lib/utils/datetime_utility //= require build //= require breakpoints -- cgit v1.2.1 From 0bf14cb0b510cd1c74b0ef94c109d519983fddd0 Mon Sep 17 00:00:00 2001 From: winniehell Date: Fri, 18 Nov 2016 21:31:11 +0100 Subject: Create dynamic fixture for build_spec (!7589) --- spec/javascripts/build_spec.js.es6 | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index ee192c4f18a..1a56819724d 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -11,10 +11,10 @@ (() => { describe('Build', () => { - fixture.preload('build.html'); + fixture.preload('builds/build-with-artifacts.html.raw'); beforeEach(function () { - fixture.load('build.html'); + fixture.load('builds/build-with-artifacts.html.raw'); spyOn($, 'ajax'); }); @@ -28,15 +28,7 @@ }); describe('setup', function () { - 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)); - beforeEach(function () { - const removeDateElement = document.querySelector('.js-artifacts-remove'); - removeDateElement.innerText = removeDate.toString(); - this.build = new Build(); }); -- cgit v1.2.1 From aae82d766bd3fcbd85bf3e6da9c910b937ac5e72 Mon Sep 17 00:00:00 2001 From: winniehell Date: Sat, 19 Nov 2016 02:06:49 +0100 Subject: Adjust build_spec to match fixture --- spec/javascripts/build_spec.js.es6 | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index 1a56819724d..d8253c1d0d5 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -11,6 +11,13 @@ (() => { describe('Build', () => { + // 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, + })); + fixture.preload('builds/build-with-artifacts.html.raw'); beforeEach(function () { @@ -33,11 +40,11 @@ }); it('copies build options', function () { - 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.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('buildstate'); + expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE); }); it('only shows the jobs matching the current stage', function () { @@ -73,7 +80,7 @@ it('displays the initial build trace', function () { expect($.ajax.calls.count()).toBe(1); 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://test.host/namespace1/project1/builds/1.json'); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); @@ -95,7 +102,7 @@ $('.js-build-options').data('buildStatus', 'running'); this.build = new Build(); spyOn(this.build, 'location') - .and.returnValue('http://example.com/root/test-build/builds/2'); + .and.returnValue('http://test.host/namespace1/project1/builds/1'); }); it('updates the build trace on an interval', function () { @@ -104,7 +111,7 @@ expect($.ajax.calls.count()).toBe(2); let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1); expect(url).toBe( - 'http://example.com/root/test-build/builds/2/trace.json?state=buildstate' + `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)); @@ -124,7 +131,7 @@ expect($.ajax.calls.count()).toBe(3); [{ url, dataType, success, context }] = $.ajax.calls.argsFor(2); expect(url).toBe( - 'http://example.com/root/test-build/builds/2/trace.json?state=newstate' + 'http://test.host/namespace1/project1/builds/1/trace.json?state=newstate' ); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); @@ -175,7 +182,7 @@ }); expect(Turbolinks.visit).toHaveBeenCalledWith( - 'http://example.com/root/test-build/builds/2' + 'http://test.host/namespace1/project1/builds/1' ); }); }); -- cgit v1.2.1 From d100f843d784b64b1b73ad8090b855e2ffd985dd Mon Sep 17 00:00:00 2001 From: winniehell Date: Sat, 19 Nov 2016 22:48:49 +0100 Subject: Remove unnecessary IIFE from build_spec --- spec/javascripts/build_spec.js.es6 | 284 ++++++++++++++++++------------------- 1 file changed, 141 insertions(+), 143 deletions(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index d8253c1d0d5..c9a314d2a82 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -9,183 +9,181 @@ //= require jquery.nicescroll //= require turbolinks -(() => { - describe('Build', () => { - // 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, - })); - - fixture.preload('builds/build-with-artifacts.html.raw'); +describe('Build', () => { + // 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, + })); + + fixture.preload('builds/build-with-artifacts.html.raw'); + + beforeEach(function () { + fixture.load('builds/build-with-artifacts.html.raw'); + spyOn($, 'ajax'); + }); + describe('constructor', () => { beforeEach(function () { - fixture.load('builds/build-with-artifacts.html.raw'); - spyOn($, 'ajax'); + jasmine.clock().install(); + }); + + afterEach(() => { + jasmine.clock().uninstall(); }); - describe('constructor', () => { + describe('setup', function () { beforeEach(function () { - jasmine.clock().install(); + this.build = new Build(); }); - afterEach(() => { - jasmine.clock().uninstall(); + it('copies build options', function () { + 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 () { - beforeEach(function () { - this.build = new Build(); - }); + 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="test"]').is(':visible')).toBe(true); + expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false); + }); - it('copies build options', function () { - 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); - }); + it('selects the current stage in the build dropdown menu', function () { + expect($('.stage-selection').text()).toBe('test'); + }); - 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="test"]').is(':visible')).toBe(true); - expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false); - }); + it('updates the jobs when the build dropdown changes', function () { + $('.stage-item:contains("build")').click(); - it('selects the current stage in the build dropdown menu', function () { - expect($('.stage-selection').text()).toBe('test'); - }); + 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); + }); - it('updates the jobs when the build dropdown changes', function () { - $('.stage-item:contains("build")').click(); + it('displays the remove date correctly', function () { + const removeDateElement = document.querySelector('.js-artifacts-remove'); + expect(removeDateElement.innerText.trim()).toBe('1 year'); + }); + }); - 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); - }); + describe('initial build trace', function () { + beforeEach(function () { + new Build(); + }); - it('displays the remove date correctly', function () { - const removeDateElement = document.querySelector('.js-artifacts-remove'); - expect(removeDateElement.innerText.trim()).toBe('1 year'); - }); + it('displays the initial build trace', function () { + 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: 'Example', status: 'running' }); + + expect($('#build-trace .js-build-output').text()).toMatch(/Example/); }); - describe('initial build trace', function () { - beforeEach(function () { - new Build(); - }); + it('removes the spinner', function () { + const [{ success, context }] = $.ajax.calls.argsFor(0); + success.call(context, { trace_html: 'Example', status: 'success' }); - it('displays the initial build trace', function () { - 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)); + expect($('.js-build-refresh').length).toBe(0); + }); + }); - success.call(context, { trace_html: 'Example', 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: 'Update', + status: 'running', + state: 'newstate', + append: true, }); - it('removes the spinner', function () { - const [{ success, context }] = $.ajax.calls.argsFor(0); - success.call(context, { trace_html: 'Example', status: 'success' }); + expect($('#build-trace .js-build-output').text()).toMatch(/Update/); + expect(this.build.state).toBe('newstate'); + + 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: 'More', + 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 () { - 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'); + it('replaces the entire build trace', function () { + jasmine.clock().tick(4001); + let [{ success, context }] = $.ajax.calls.argsFor(1); + success.call(context, { + html: 'Update', + status: 'running', + append: true, }); - 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: 'Update', - 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: 'More', - status: 'running', - state: 'finalstate', - append: true, - }); - - expect($('#build-trace .js-build-output').text()).toMatch(/UpdateMore/); - expect(this.build.state).toBe('finalstate'); - }); + expect($('#build-trace .js-build-output').text()).toMatch(/Update/); - it('replaces the entire build trace', function () { - jasmine.clock().tick(4001); - let [{ success, context }] = $.ajax.calls.argsFor(1); - success.call(context, { - html: 'Update', - status: 'running', - 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: 'Different', - status: 'running', - append: false, - }); - - expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/); - expect($('#build-trace .js-build-output').text()).toMatch(/Different/); + jasmine.clock().tick(4001); + [{ success, context }] = $.ajax.calls.argsFor(2); + success.call(context, { + html: 'Different', + status: 'running', + append: false, }); - it('reloads the page when the build is done', function () { - spyOn(Turbolinks, 'visit'); + expect($('#build-trace .js-build-output').text()).not.toMatch(/Update/); + expect($('#build-trace .js-build-output').text()).toMatch(/Different/); + }); - jasmine.clock().tick(4001); - const [{ success, context }] = $.ajax.calls.argsFor(1); - success.call(context, { - html: 'Final', - status: 'passed', - append: true, - }); + it('reloads the page when the build is done', function () { + spyOn(Turbolinks, 'visit'); - expect(Turbolinks.visit).toHaveBeenCalledWith( - 'http://test.host/namespace1/project1/builds/1' - ); + jasmine.clock().tick(4001); + const [{ success, context }] = $.ajax.calls.argsFor(1); + success.call(context, { + html: 'Final', + status: 'passed', + append: true, }); + + expect(Turbolinks.visit).toHaveBeenCalledWith( + 'http://test.host/namespace1/project1/builds/1' + ); }); }); }); -})(); +}); -- cgit v1.2.1 From 918bc207c680bed46e82bef996aea027ac72b38d Mon Sep 17 00:00:00 2001 From: winniehell Date: Sat, 19 Nov 2016 22:59:32 +0100 Subject: Use Rails test host name for frontend fixtures --- spec/javascripts/build_spec.js.es6 | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index c9a314d2a82..50411695925 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -10,6 +10,7 @@ //= require turbolinks describe('Build', () => { + const BUILD_URL = `${gl.TEST_HOST}/namespace1/project1/builds/1`; // see spec/factories/ci/builds.rb const BUILD_TRACE = 'BUILD TRACE'; // see lib/ci/ansi2html.rb @@ -39,8 +40,8 @@ describe('Build', () => { }); it('copies build options', function () { - 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.pageUrl).toBe(BUILD_URL); + expect(this.build.buildUrl).toBe(`${BUILD_URL}.json`); expect(this.build.buildStatus).toBe('success'); expect(this.build.buildStage).toBe('test'); expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE); @@ -79,7 +80,7 @@ describe('Build', () => { it('displays the initial build trace', function () { 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(url).toBe(`${BUILD_URL}.json`); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); @@ -100,8 +101,7 @@ describe('Build', () => { 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'); + spyOn(this.build, 'location').and.returnValue(BUILD_URL); }); it('updates the build trace on an interval', function () { @@ -110,7 +110,7 @@ describe('Build', () => { 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)}` + `${BUILD_URL}/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}` ); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); @@ -129,9 +129,7 @@ describe('Build', () => { 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(url).toBe(`${BUILD_URL}/trace.json?state=newstate`); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); @@ -180,9 +178,7 @@ describe('Build', () => { append: true, }); - expect(Turbolinks.visit).toHaveBeenCalledWith( - 'http://test.host/namespace1/project1/builds/1' - ); + expect(Turbolinks.visit).toHaveBeenCalledWith(BUILD_URL); }); }); }); -- cgit v1.2.1 From 82429b6978361daaf703a3438c7822ac956a3aa4 Mon Sep 17 00:00:00 2001 From: winniehell Date: Sun, 20 Nov 2016 00:40:37 +0100 Subject: Explicitly name namespace and projects for frontend fixtures --- spec/javascripts/build_spec.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index 50411695925..304c4d4e29d 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -10,7 +10,7 @@ //= require turbolinks describe('Build', () => { - const BUILD_URL = `${gl.TEST_HOST}/namespace1/project1/builds/1`; + const BUILD_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/builds/1`; // see spec/factories/ci/builds.rb const BUILD_TRACE = 'BUILD TRACE'; // see lib/ci/ansi2html.rb -- cgit v1.2.1 From 31a5ed97a74e250887721413f5a956a93dc2e1b1 Mon Sep 17 00:00:00 2001 From: winniehell Date: Wed, 23 Nov 2016 21:45:39 +0100 Subject: Prefer arrow functions in build_spec.js.es6 --- spec/javascripts/build_spec.js.es6 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index 304c4d4e29d..d92cc433670 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -20,13 +20,13 @@ describe('Build', () => { fixture.preload('builds/build-with-artifacts.html.raw'); - beforeEach(function () { + beforeEach(() => { fixture.load('builds/build-with-artifacts.html.raw'); spyOn($, 'ajax'); }); describe('constructor', () => { - beforeEach(function () { + beforeEach(() => { jasmine.clock().install(); }); @@ -34,7 +34,7 @@ describe('Build', () => { jasmine.clock().uninstall(); }); - describe('setup', function () { + describe('setup', () => { beforeEach(function () { this.build = new Build(); }); @@ -47,17 +47,17 @@ describe('Build', () => { expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE); }); - it('only shows the jobs matching the current stage', function () { + it('only shows the jobs matching the current stage', () => { 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); }); - it('selects the current stage in the build dropdown menu', function () { + it('selects the current stage in the build dropdown menu', () => { 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', () => { $('.stage-item:contains("build")').click(); expect($('.stage-selection').text()).toBe('build'); @@ -66,18 +66,18 @@ describe('Build', () => { expect($('.build-job[data-stage="deploy"]').is(':visible')).toBe(false); }); - it('displays the remove date correctly', function () { + it('displays the remove date correctly', () => { const removeDateElement = document.querySelector('.js-artifacts-remove'); expect(removeDateElement.innerText.trim()).toBe('1 year'); }); }); - describe('initial build trace', function () { - beforeEach(function () { + describe('initial build trace', () => { + beforeEach(() => { new Build(); }); - it('displays the initial build trace', function () { + it('displays the initial build trace', () => { expect($.ajax.calls.count()).toBe(1); const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0); expect(url).toBe(`${BUILD_URL}.json`); @@ -89,7 +89,7 @@ describe('Build', () => { expect($('#build-trace .js-build-output').text()).toMatch(/Example/); }); - it('removes the spinner', function () { + it('removes the spinner', () => { const [{ success, context }] = $.ajax.calls.argsFor(0); success.call(context, { trace_html: 'Example', status: 'success' }); @@ -97,7 +97,7 @@ describe('Build', () => { }); }); - describe('running build', function () { + describe('running build', () => { beforeEach(function () { $('.js-build-options').data('buildStatus', 'running'); this.build = new Build(); @@ -144,7 +144,7 @@ describe('Build', () => { expect(this.build.state).toBe('finalstate'); }); - it('replaces the entire build trace', function () { + it('replaces the entire build trace', () => { jasmine.clock().tick(4001); let [{ success, context }] = $.ajax.calls.argsFor(1); success.call(context, { @@ -167,7 +167,7 @@ describe('Build', () => { 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', () => { spyOn(Turbolinks, 'visit'); jasmine.clock().tick(4001); -- cgit v1.2.1 From c145413d1acb58addb199f0e5bfd909e0a695a5c Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Mon, 14 Nov 2016 22:37:13 +0000 Subject: Remove JSX/React eslint plugins. Change airbnb eslint config package to `eslint-config-airbnb-base` and update plugins. Change `airbnb` to `airbnb-base` for .eslintrc `extends` value. Added changelog entry Made sure all plugins and envs are set Corrected new failing specs --- spec/javascripts/build_spec.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/javascripts/build_spec.js.es6') diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index d694727880f..3983cad4c13 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -109,7 +109,7 @@ describe('Build', () => { expect($.ajax.calls.count()).toBe(2); let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1); expect(url).toBe( - `${BUILD_URL}/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}` + `${BUILD_URL}/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}`, ); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); -- cgit v1.2.1