X-Git-Url: https://pwan.org/git/?a=blobdiff_plain;f=test%2Fgraphing%2Fradar-spec.js;h=5d38842c96e2cdd5519872b108aa9a1b61858fba;hb=646ed3c7a26852dcbf9f48c744c0128e1129fdc2;hp=76089888052f9fccb5080272512c5908edc31835;hpb=d38f0a110aedcad816a2c74397d4eb65edb4da30;p=tech-radar.git diff --git a/test/graphing/radar-spec.js b/test/graphing/radar-spec.js index 7608988..5d38842 100644 --- a/test/graphing/radar-spec.js +++ b/test/graphing/radar-spec.js @@ -1,13 +1,19 @@ describe('tr.graphing.Radar', function () { - function buildSvg() { - return d3.select("body").append("svg"); - } + var radar; + + beforeEach(function () { + radar = new tr.models.Radar(); + spyOn(radar, 'cycles').andReturn([]); + }); it('sets the size', function () { - var svg = buildSvg(); + var svg, radarGraph; + + radarGraph = new tr.graphing.Radar(500, radar); + svg = radarGraph.svg; spyOn(svg, 'attr').andReturn(svg); - var radarGraph = new tr.graphing.Radar(svg, 500); + radarGraph.plot(); expect(svg.attr).toHaveBeenCalledWith('width', 500); expect(svg.attr).toHaveBeenCalledWith('height', 500); @@ -15,12 +21,14 @@ describe('tr.graphing.Radar', function () { describe('lines', function () { it('plots a vertical line in the center', function () { - var svg = buildSvg(); + var radarGraph, svg; + + radarGraph = new tr.graphing.Radar(500, radar); + + svg = radarGraph.svg; spyOn(svg, 'append').andReturn(svg); spyOn(svg, 'attr').andReturn(svg); - var radarGraph = new tr.graphing.Radar(svg, 500); - radarGraph.plot(); expect(svg.append).toHaveBeenCalledWith('line'); @@ -28,16 +36,17 @@ describe('tr.graphing.Radar', function () { expect(svg.attr).toHaveBeenCalledWith('y1', 0); expect(svg.attr).toHaveBeenCalledWith('x2', 500 / 2); expect(svg.attr).toHaveBeenCalledWith('y2', 500); - expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5); + expect(svg.attr).toHaveBeenCalledWith('stroke-width', 14); }); it('plots a horizontal line in the center', function () { - var svg = buildSvg(); + var svg, radarGraph; + + radarGraph = new tr.graphing.Radar(500, radar); + svg = radarGraph.svg; spyOn(svg, 'append').andReturn(svg); spyOn(svg, 'attr').andReturn(svg); - var radarGraph = new tr.graphing.Radar(svg, 500); - radarGraph.plot(); expect(svg.append).toHaveBeenCalledWith('line'); @@ -45,7 +54,73 @@ describe('tr.graphing.Radar', function () { expect(svg.attr).toHaveBeenCalledWith('y1', 500 / 2); expect(svg.attr).toHaveBeenCalledWith('x2', 500); expect(svg.attr).toHaveBeenCalledWith('y2', 500 / 2); - expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5); + expect(svg.attr).toHaveBeenCalledWith('stroke-width', 14); }); - }) + }); + + describe('circles', function () { + var svg, radarGraph; + + beforeEach(function () { + var radar; + + radar = new tr.models.Radar(); + spyOn(radar, 'cycles').andReturn([ + new tr.models.Cycle('Adopt'), + new tr.models.Cycle('Hold') + ]); + radarGraph = new tr.graphing.Radar(500, radar); + svg = radarGraph.svg; + spyOn(svg, 'append').andReturn(svg); + spyOn(svg, 'attr').andReturn(svg); + }); + + it('plots the circles for the cycles', function () { + radarGraph.plot(); + + expect(svg.append).toHaveBeenCalledWith('circle'); + expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2); + expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2); + expect(svg.attr).toHaveBeenCalledWith('r', Math.round(250 / 2)); + + expect(svg.append).toHaveBeenCalledWith('circle'); + expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2); + expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2); + expect(svg.attr).toHaveBeenCalledWith('r', 250); + }); + + it('adds the name of each cycle for the right side', function () { + var center = 500 / 2; + spyOn(svg, 'text').andReturn(svg); + radarGraph.plot(); + + expect(svg.append).toHaveBeenCalledWith('text'); + expect(svg.attr).toHaveBeenCalledWith('y', center + 4); + expect(svg.attr).toHaveBeenCalledWith('x', 0 + 10); + expect(svg.text).toHaveBeenCalledWith('Adopt'); + + expect(svg.append).toHaveBeenCalledWith('text'); + expect(svg.attr).toHaveBeenCalledWith('y', center + 4); + expect(svg.attr).toHaveBeenCalledWith('x', 0 + (center / 2) + 10); + expect(svg.text).toHaveBeenCalledWith('Hold'); + }); + + it('adds the name of each cycle for the right side', function () { + var center = 500 / 2; + spyOn(svg, 'text').andReturn(svg); + radarGraph.plot(); + + expect(svg.append).toHaveBeenCalledWith('text'); + expect(svg.attr).toHaveBeenCalledWith('y', center + 4); + expect(svg.attr).toHaveBeenCalledWith('x', 500 - 10); + expect(svg.attr).toHaveBeenCalledWith('text-anchor', 'end'); + expect(svg.text).toHaveBeenCalledWith('Adopt'); + + expect(svg.append).toHaveBeenCalledWith('text'); + expect(svg.attr).toHaveBeenCalledWith('y', center + 4); + expect(svg.attr).toHaveBeenCalledWith('x', 500 - (center / 2) - 10); + expect(svg.attr).toHaveBeenCalledWith('text-anchor', 'end'); + expect(svg.text).toHaveBeenCalledWith('Hold'); + }); + }); });