better organizing the cycle names
[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', 14);
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', 14);
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 cycles', 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 it('adds the name of each cycle for the right side', function () {
97 var center = 500 / 2;
98 spyOn(svg, 'text').andReturn(svg);
99 radarGraph.plot();
100
101 expect(svg.append).toHaveBeenCalledWith('text');
102 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
103 expect(svg.attr).toHaveBeenCalledWith('x', 0 + 10);
104 expect(svg.text).toHaveBeenCalledWith('Adopt');
105
106 expect(svg.append).toHaveBeenCalledWith('text');
107 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
108 expect(svg.attr).toHaveBeenCalledWith('x', 0 + (center / 2) + 10);
109 expect(svg.text).toHaveBeenCalledWith('Hold');
110 });
111
112 it('adds the name of each cycle for the right side', function () {
113 var center = 500 / 2;
114 spyOn(svg, 'text').andReturn(svg);
115 radarGraph.plot();
116
117 expect(svg.append).toHaveBeenCalledWith('text');
118 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
119 expect(svg.attr).toHaveBeenCalledWith('x', 500 - 10);
120 expect(svg.attr).toHaveBeenCalledWith('text-anchor', 'end');
121 expect(svg.text).toHaveBeenCalledWith('Adopt');
122
123 expect(svg.append).toHaveBeenCalledWith('text');
124 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
125 expect(svg.attr).toHaveBeenCalledWith('x', 500 - (center / 2) - 10);
126 expect(svg.attr).toHaveBeenCalledWith('text-anchor', 'end');
127 expect(svg.text).toHaveBeenCalledWith('Hold');
128 });
129 });
130 });