var clean up on tests
[tech-radar.git] / test / graphing / radar-spec.js
1 describe('tr.graphing.Radar', function () {
2 var radar;
3
4 function buildSvg() {
5 return d3.select("body").append("svg");
6 }
7
8 beforeEach(function () {
9 radar = new tr.models.Radar();
10 spyOn(radar, 'cycles').andReturn([]);
11 });
12
13 it('sets the size', function () {
14 var svg, radarGraph;
15 svg = buildSvg();
16 spyOn(svg, 'attr').andReturn(svg);
17
18 radarGraph = new tr.graphing.Radar(svg, 500, radar);
19
20 expect(svg.attr).toHaveBeenCalledWith('width', 500);
21 expect(svg.attr).toHaveBeenCalledWith('height', 500);
22 });
23
24 describe('lines', function () {
25 it('plots a vertical line in the center', function () {
26 var svg, radarGraph;
27
28 svg = buildSvg();
29 spyOn(svg, 'append').andReturn(svg);
30 spyOn(svg, 'attr').andReturn(svg);
31
32 radarGraph = new tr.graphing.Radar(svg, 500, radar);
33
34 radarGraph.plot();
35
36 expect(svg.append).toHaveBeenCalledWith('line');
37 expect(svg.attr).toHaveBeenCalledWith('x1', 500 / 2);
38 expect(svg.attr).toHaveBeenCalledWith('y1', 0);
39 expect(svg.attr).toHaveBeenCalledWith('x2', 500 / 2);
40 expect(svg.attr).toHaveBeenCalledWith('y2', 500);
41 expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5);
42 });
43
44 it('plots a horizontal line in the center', function () {
45 var svg, radarGraph;
46
47 svg = buildSvg();
48 spyOn(svg, 'append').andReturn(svg);
49 spyOn(svg, 'attr').andReturn(svg);
50
51 radarGraph = new tr.graphing.Radar(svg, 500, radar);
52
53 radarGraph.plot();
54
55 expect(svg.append).toHaveBeenCalledWith('line');
56 expect(svg.attr).toHaveBeenCalledWith('x1', 0);
57 expect(svg.attr).toHaveBeenCalledWith('y1', 500 / 2);
58 expect(svg.attr).toHaveBeenCalledWith('x2', 500);
59 expect(svg.attr).toHaveBeenCalledWith('y2', 500 / 2);
60 expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5);
61 });
62 });
63
64 describe('circles', function () {
65 var svg, radarGraph;
66
67 beforeEach(function () {
68 var radar;
69
70 svg = buildSvg();
71 spyOn(svg, 'append').andReturn(svg);
72 spyOn(svg, 'attr').andReturn(svg);
73
74 radar = new tr.models.Radar();
75 spyOn(radar, 'cycles').andReturn([
76 new tr.models.Cycle('Adopt'),
77 new tr.models.Cycle('Hold')
78 ]);
79 radarGraph = new tr.graphing.Radar(svg, 500, radar);
80 });
81
82 it('plots the circles for the cicles', function () {
83 radarGraph.plot();
84
85 expect(svg.append).toHaveBeenCalledWith('circle');
86 expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2);
87 expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2);
88 expect(svg.attr).toHaveBeenCalledWith('r', Math.round(250 / 2));
89
90 expect(svg.append).toHaveBeenCalledWith('circle');
91 expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2);
92 expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2);
93 expect(svg.attr).toHaveBeenCalledWith('r', 250);
94 });
95 });
96 });