From 401a2ec0b159b3c5f4de617768b9a0489a7cdde3 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Fri, 9 Dec 2016 15:13:20 +0000 Subject: [PATCH] Adds tests to prevent future errors. Fix undefined variable in es5 --- app/assets/javascripts/pipelines.js.es6 | 2 +- changelogs/unreleased/25483-broken-tabs.yml | 2 +- .../fixtures/pipeline_graph.html.haml | 15 +++++++++++ spec/javascripts/pipelines_spec.js.es6 | 25 +++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 spec/javascripts/fixtures/pipeline_graph.html.haml create mode 100644 spec/javascripts/pipelines_spec.js.es6 diff --git a/app/assets/javascripts/pipelines.js.es6 b/app/assets/javascripts/pipelines.js.es6 index a7a384fd856..fd1e320dc35 100644 --- a/app/assets/javascripts/pipelines.js.es6 +++ b/app/assets/javascripts/pipelines.js.es6 @@ -16,7 +16,7 @@ addMarginToBuildColumns() { this.pipelineGraph = document.querySelector('.pipeline-graph'); const secondChildBuildNodes = document.querySelector('.pipeline-graph').querySelectorAll('.build:nth-child(2)'); - for (buildNodeIndex in secondChildBuildNodes) { + for (const buildNodeIndex in secondChildBuildNodes) { const buildNode = secondChildBuildNodes[buildNodeIndex]; const firstChildBuildNode = buildNode.previousElementSibling; if (!firstChildBuildNode || !firstChildBuildNode.matches('.build')) continue; diff --git a/changelogs/unreleased/25483-broken-tabs.yml b/changelogs/unreleased/25483-broken-tabs.yml index 7bc50bdf860..d6c92014bea 100644 --- a/changelogs/unreleased/25483-broken-tabs.yml +++ b/changelogs/unreleased/25483-broken-tabs.yml @@ -1,4 +1,4 @@ --- title: Fix TypeError: Cannot read property 'initTabs' on commit builds tab -merge_request: +merge_request: 8009 author: diff --git a/spec/javascripts/fixtures/pipeline_graph.html.haml b/spec/javascripts/fixtures/pipeline_graph.html.haml new file mode 100644 index 00000000000..be5f105767c --- /dev/null +++ b/spec/javascripts/fixtures/pipeline_graph.html.haml @@ -0,0 +1,15 @@ +%div.pipeline-visualization.pipeline-graph + %ul.stage-column-list + %li.stage-column + .stage-name + %a{:href => "/"} + Test + .builds-container + %ul + %li.build + .curve + .build-content + %a + %svg + .ci-status-text + stop_review diff --git a/spec/javascripts/pipelines_spec.js.es6 b/spec/javascripts/pipelines_spec.js.es6 new file mode 100644 index 00000000000..85c9cf4b4f1 --- /dev/null +++ b/spec/javascripts/pipelines_spec.js.es6 @@ -0,0 +1,25 @@ +//= require pipelines + +(() => { + describe('Pipelines', () => { + fixture.preload('pipeline_graph'); + + beforeEach(() => { + fixture.load('pipeline_graph'); + }); + + it('should be defined', () => { + expect(window.gl.Pipelines).toBeDefined(); + }); + + it('should create a `Pipelines` instance without options', () => { + expect(() => { new window.gl.Pipelines(); }).not.toThrow(); //eslint-disable-line + }); + + it('should create a `Pipelines` instance with options', () => { + const pipelines = new window.gl.Pipelines({ foo: 'bar' }); + + expect(pipelines.pipelineGraph).toBeDefined(); + }); + }); +})();