From 7dab57f9bad636554bef011afe9b1cfd5759b7b9 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 11 Jan 2018 09:31:59 +1300 Subject: [PATCH] Removed d3 graph tests --- spec/javascripts/graphs/bar_group_spec.js | 54 -------------- .../graphs/bar_label_group_spec.js | 38 ---------- spec/javascripts/graphs/height_scale_spec.js | 35 --------- .../graphs/horizontal_bar_graph_spec.js | 74 ------------------- spec/javascripts/graphs/width_scale_spec.js | 40 ---------- 5 files changed, 241 deletions(-) delete mode 100644 spec/javascripts/graphs/bar_group_spec.js delete mode 100644 spec/javascripts/graphs/bar_label_group_spec.js delete mode 100644 spec/javascripts/graphs/height_scale_spec.js delete mode 100644 spec/javascripts/graphs/horizontal_bar_graph_spec.js delete mode 100644 spec/javascripts/graphs/width_scale_spec.js diff --git a/spec/javascripts/graphs/bar_group_spec.js b/spec/javascripts/graphs/bar_group_spec.js deleted file mode 100644 index a76992a6c..000000000 --- a/spec/javascripts/graphs/bar_group_spec.js +++ /dev/null @@ -1,54 +0,0 @@ -(function() { - 'use strict'; - - /* - These tests are for the BarGroup object. - */ - - describe('when drawing the group of bars', function() { - var BarGroup; var subject; var bars; var data; - - beforeEach(function() { - BarGroup = growstuff.BarGroup; - - bars = [ - {name: 'Shade', value: 0.2}, - {name: 'Half Shade', value: 0.5}, - ]; - - data = { - bars: bars, - bar_color: 'steelblue', - width: {size: 300, scale: 'linear'}, - height: {size: 400, scale: 'ordinal'}, - }; - - subject = new BarGroup(data); - subject.render(d3.select('#jasmine_content').append('svg')); - }); - - it('draws a group', function() { - expect($('g.bar')).toExist(); - }); - - it('draws 2 bars', function() { - expect($('g.bar rect')).toHaveLength(2); - }); - - it('fills the bars with color', function() { - expect($('g.bar rect')).toHaveAttr('fill', 'steelblue'); - }); - - it('shows a tooltip on hover', function() { - var i; - - // get all of the title nodes for the bars - var barNodes = $('g.bar rect title'); - - for (i = 0; i < bars.length; i++) { - expect(barNodes[i].textContent) - .toBe('This value is ' + bars[i].value + '' + '.'); - } - }); - }); -}()); diff --git a/spec/javascripts/graphs/bar_label_group_spec.js b/spec/javascripts/graphs/bar_label_group_spec.js deleted file mode 100644 index 7cb6e5537..000000000 --- a/spec/javascripts/graphs/bar_label_group_spec.js +++ /dev/null @@ -1,38 +0,0 @@ -(function() { - 'use strict'; - - /* - This file contains tests for the labels that get rendered next to each bar - */ - - describe('BarLabelGroup', function() { - var BarLabelGroup; var subject; var data; - - beforeEach(function() { - BarLabelGroup = growstuff.BarLabelGroup; - var bars = [ - {name: 'Shade', value: 0.2}, - {name: 'Half Shade', value: 0.5}, - ]; - data = { - bars: bars, - }; - subject = new BarLabelGroup(data); - subject.render(d3.select('#jasmine_content').append('svg')); - }); - - it('draws a group for labels', function() { - expect($('g.bar-label')).toExist(); - }); - - it('draws 2 bar labels', function() { - expect($('g.bar-label text')).toHaveLength(2); - }); - - it('has text for 2 bar labels', function() { - // jquery jasmine appends text from all text elements - // into one string - expect($('g.bar-label text')).toHaveText('ShadeHalf Shade'); - }); - }); -}()); diff --git a/spec/javascripts/graphs/height_scale_spec.js b/spec/javascripts/graphs/height_scale_spec.js deleted file mode 100644 index 3a257400c..000000000 --- a/spec/javascripts/graphs/height_scale_spec.js +++ /dev/null @@ -1,35 +0,0 @@ -(function() { - 'use strict'; - - /* - Tests for mapping the number of bars to the size of the svg - */ - - describe('HeightScale when specifying height', function() { - var data; var bars; var HeightScale; var subject; var mockD3; - - beforeEach(function() { - HeightScale = growstuff.HeightScale; - bars = [ - {name: 'Shade', value: 0.2}, - {name: 'Half Shade', value: 0.5}, - ]; - data = { - bars: bars, - width: {size: 300, scale: 'linear'}, - height: {size: 400, scale: 'ordinal'}, - }; - - subject = new HeightScale(data); - mockD3 = jasmine.createSpyObj('d3', ['domain', 'rangeRoundBands']); - mockD3.domain.and.returnValue(mockD3); - mockD3.rangeRoundBands.and.returnValue(mockD3); - spyOn(d3.scale, 'ordinal').and.returnValue(mockD3); - subject.render(); - }); - - it('calls the d3 range round bands function to draw the height', function() { - expect(mockD3.rangeRoundBands).toHaveBeenCalledWith([0, 400], 0.05, 0); - }); - }); -}()); diff --git a/spec/javascripts/graphs/horizontal_bar_graph_spec.js b/spec/javascripts/graphs/horizontal_bar_graph_spec.js deleted file mode 100644 index 16f35f018..000000000 --- a/spec/javascripts/graphs/horizontal_bar_graph_spec.js +++ /dev/null @@ -1,74 +0,0 @@ -(function() { - 'use strict'; - - /* - Tests in this file are for the pieces of HorizontalBarGraph or - are more integration-y type tests that require the full graph. - */ - - describe('HorizontalBarGraph', function() { - var BarLabelGroup; var BarGroup; var subject; var data; - - beforeEach(function() { - var HorizontalBarGraph = growstuff.HorizontalBarGraph; - var bars = [ - {name: 'Shade', value: 0.2}, - {name: 'Half Shade', value: 0.5}, - ]; - data = { - bars: bars, - bar_color: 'steelblue', - width: {size: 300, scale: 'linear'}, - height: {size: 400, scale: 'ordinal'}, - // left is used to shift the bars over so that there is - // room for the labels - margin: {top: 0, right: 0, bottom: 0, left: 100}, - }; - - subject = new HorizontalBarGraph(data); - BarGroup = growstuff.BarGroup; - BarLabelGroup = growstuff.BarLabelGroup; - expect(BarLabelGroup).toExist(); - spyOn(BarGroup.prototype, 'render').and.callThrough(); - spyOn(BarLabelGroup.prototype, 'render').and.callThrough(); - subject.render(d3.select($('#jasmine_content')[0])); - }); - - it('draws a graph', function() { - expect($('#jasmine_content svg')).toExist(); - }); - - it('draws a group for the whole graph', function() { - expect($('g.bar-graph')).toExist(); - }); - - it('draws a bar group', function() { - expect(BarGroup.prototype.render).toHaveBeenCalled(); - }); - - it('draws a group of bar labels', function() { - expect(BarLabelGroup.prototype.render).toHaveBeenCalled(); - }); - - it('has the expected width and height', function() { - var $svg = $('svg'); - var margin = data.margin; - expect($svg).toHaveAttr('width', (data.width.size + margin.left + margin.right) + ''); - expect($svg).toHaveAttr('height', (data.height.size + margin.top + margin.bottom) + ''); - }); - - it('draws the graph shifted to the right to accommodate for labels', function() { - expect('g.bar-graph').toHaveAttr('transform', 'translate(100,0)'); - }); - - it('on the x axis, draws at least one bar at max width less margin width', function() { - // because of domain and range mapping - expect('g.bar rect:eq(1)').toHaveAttr('width', '300' ); - }); - - it('on the y axis, all bars are the same height', function() { - expect('g.bar rect:eq(0)').toHaveAttr('height', '195'); - expect('g.bar rect:eq(1)').toHaveAttr('height', '195'); - }); - }); -}()); diff --git a/spec/javascripts/graphs/width_scale_spec.js b/spec/javascripts/graphs/width_scale_spec.js deleted file mode 100644 index d8e34234a..000000000 --- a/spec/javascripts/graphs/width_scale_spec.js +++ /dev/null @@ -1,40 +0,0 @@ -(function() { - 'use strict'; - - /* - This file contains tests for the mapping the data values to - the length of a bar so that it is the correct size for the screen - */ - - describe('GraphScale, when specifying width', function() { - var data; var WidthScale; var subject; var mockD3; - - beforeEach(function() { - WidthScale = growstuff.WidthScale; - var bars = [ - {name: 'Shade', value: 0.2}, - {name: 'Half Shade', value: 0.5}, - ]; - data = { - bars: bars, - width: {size: 300, scale: 'linear'}, - height: {size: 400, scale: 'ordinal'}, - }; - - subject = new WidthScale(data, 'width'); - mockD3 = jasmine.createSpyObj('d3', ['domain', 'range', 'max']); - mockD3.domain.and.returnValue(mockD3); - mockD3.range.and.returnValue(mockD3); - spyOn(d3.scale, 'linear').and.returnValue(mockD3); - subject.render(); - }); - - it('gets the value of the longest bar', function() { - expect(subject.getMaxValue()).toEqual(0.5); - }); - - it('calls the d3 range function to draw the width', function() { - expect(mockD3.range).toHaveBeenCalledWith([0, 300]); - }); - }); -}());