X-Git-Url: https://pwan.org/git/?a=blobdiff_plain;f=test%2Fgraphing%2Fradar-spec.js;h=3a382929bfd5f14cd713fcc181aa020c2820d094;hb=638eb0174463927b5f88a08da2238ad423218f18;hp=5c7d3b5f0d1f7fd881b7fd56499a660161bd7c46;hpb=2c6e76ea65109b83d80ca1d51088cbb040960711;p=tech-radar.git diff --git a/test/graphing/radar-spec.js b/test/graphing/radar-spec.js index 5c7d3b5..3a38292 100644 --- a/test/graphing/radar-spec.js +++ b/test/graphing/radar-spec.js @@ -1,20 +1,57 @@ describe('tr.graphing.Radar', function () { var radar; - function buildSvg() { - return d3.select("body").append("svg"); - } - beforeEach(function () { radar = new tr.models.Radar(); spyOn(radar, 'cycles').andReturn([]); }); + describe('init', function () { + it('appends the svg', function () { + var radarGraph, selection; + + radarGraph = new tr.graphing.Radar(500, radar); + selection = { append: jasmine.createSpy() }; + spyOn(d3, 'select').andReturn(selection); + + radarGraph.init(); + + expect(selection.append).toHaveBeenCalledWith('svg'); + }); + + it('selects body if no selector provided', function () { + var radarGraph; + + radarGraph = new tr.graphing.Radar(500, radar); + spyOn(d3, 'select').andCallThrough(); + + radarGraph.init(); + + expect(d3.select).toHaveBeenCalledWith('body'); + }); + + it('selects the selector if provided', function () { + var radarGraph; + + radarGraph = new tr.graphing.Radar(500, radar); + spyOn(d3, 'select').andCallThrough(); + + radarGraph.init('#radar'); + + expect(d3.select).toHaveBeenCalledWith('#radar'); + }); + }); + it('sets the size', function () { - var svg = buildSvg(); + var svg, radarGraph; + + radarGraph = new tr.graphing.Radar(500, radar); + radarGraph.init(); + + svg = radarGraph.svg(); spyOn(svg, 'attr').andReturn(svg); - var radarGraph = new tr.graphing.Radar(svg, 500, radar); + radarGraph.plot(); expect(svg.attr).toHaveBeenCalledWith('width', 500); expect(svg.attr).toHaveBeenCalledWith('height', 500); @@ -22,12 +59,15 @@ 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); + radarGraph.init(); + + svg = radarGraph.svg(); spyOn(svg, 'append').andReturn(svg); spyOn(svg, 'attr').andReturn(svg); - var radarGraph = new tr.graphing.Radar(svg, 500, radar); - radarGraph.plot(); expect(svg.append).toHaveBeenCalledWith('line'); @@ -35,16 +75,19 @@ 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); + radarGraph.init(); + + svg = radarGraph.svg(); spyOn(svg, 'append').andReturn(svg); spyOn(svg, 'attr').andReturn(svg); - var radarGraph = new tr.graphing.Radar(svg, 500, radar); - radarGraph.plot(); expect(svg.append).toHaveBeenCalledWith('line'); @@ -52,7 +95,7 @@ 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); }); }); @@ -62,19 +105,20 @@ describe('tr.graphing.Radar', function () { beforeEach(function () { var radar; - svg = buildSvg(); - spyOn(svg, 'append').andReturn(svg); - spyOn(svg, 'attr').andReturn(svg); - radar = new tr.models.Radar(); spyOn(radar, 'cycles').andReturn([ new tr.models.Cycle('Adopt'), new tr.models.Cycle('Hold') ]); - radarGraph = new tr.graphing.Radar(svg, 500, radar); + radarGraph = new tr.graphing.Radar(500, radar); + radarGraph.init(); + + svg = radarGraph.svg(); + spyOn(svg, 'append').andReturn(svg); + spyOn(svg, 'attr').andReturn(svg); }); - it('plots the circles for the cicles', function () { + it('plots the circles for the cycles', function () { radarGraph.plot(); expect(svg.append).toHaveBeenCalledWith('circle'); @@ -87,5 +131,39 @@ describe('tr.graphing.Radar', function () { 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'); + }); }); });