moved svg creation and append to the graphing radar
[tech-radar.git] / test / graphing / radar-spec.js
1 describe('tr.graphing.Radar', function () {
2 var radar;
3
4 beforeEach(function () {
5 radar = new tr.models.Radar();
6 spyOn(radar, 'cycles').andReturn([]);
7 });
8
9 it('sets the size', function () {
10 var svg, radarGraph;
11
12 radarGraph = new tr.graphing.Radar(500, radar);
13 svg = radarGraph.svg;
14 spyOn(svg, 'attr').andReturn(svg);
15
16 radarGraph.plot();
17
18 expect(svg.attr).toHaveBeenCalledWith('width', 500);
19 expect(svg.attr).toHaveBeenCalledWith('height', 500);
20 });
21
22 describe('lines', function () {
23 it('plots a vertical line in the center', function () {
24 var radarGraph, svg;
25
26 radarGraph = new tr.graphing.Radar(500, radar);
27
28 svg = radarGraph.svg;
29 spyOn(svg, 'append').andReturn(svg);
30 spyOn(svg, 'attr').andReturn(svg);
31
32 radarGraph.plot();
33
34 expect(svg.append).toHaveBeenCalledWith('line');
35 expect(svg.attr).toHaveBeenCalledWith('x1', 500 / 2);
36 expect(svg.attr).toHaveBeenCalledWith('y1', 0);
37 expect(svg.attr).toHaveBeenCalledWith('x2', 500 / 2);
38 expect(svg.attr).toHaveBeenCalledWith('y2', 500);
39 expect(svg.attr).toHaveBeenCalledWith('stroke-width', 14);
40 });
41
42 it('plots a horizontal line in the center', function () {
43 var svg, radarGraph;
44
45 radarGraph = new tr.graphing.Radar(500, radar);
46 svg = radarGraph.svg;
47 spyOn(svg, 'append').andReturn(svg);
48 spyOn(svg, 'attr').andReturn(svg);
49
50 radarGraph.plot();
51
52 expect(svg.append).toHaveBeenCalledWith('line');
53 expect(svg.attr).toHaveBeenCalledWith('x1', 0);
54 expect(svg.attr).toHaveBeenCalledWith('y1', 500 / 2);
55 expect(svg.attr).toHaveBeenCalledWith('x2', 500);
56 expect(svg.attr).toHaveBeenCalledWith('y2', 500 / 2);
57 expect(svg.attr).toHaveBeenCalledWith('stroke-width', 14);
58 });
59 });
60
61 describe('circles', function () {
62 var svg, radarGraph;
63
64 beforeEach(function () {
65 var radar;
66
67 radar = new tr.models.Radar();
68 spyOn(radar, 'cycles').andReturn([
69 new tr.models.Cycle('Adopt'),
70 new tr.models.Cycle('Hold')
71 ]);
72 radarGraph = new tr.graphing.Radar(500, radar);
73 svg = radarGraph.svg;
74 spyOn(svg, 'append').andReturn(svg);
75 spyOn(svg, 'attr').andReturn(svg);
76 });
77
78 it('plots the circles for the cycles', function () {
79 radarGraph.plot();
80
81 expect(svg.append).toHaveBeenCalledWith('circle');
82 expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2);
83 expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2);
84 expect(svg.attr).toHaveBeenCalledWith('r', Math.round(250 / 2));
85
86 expect(svg.append).toHaveBeenCalledWith('circle');
87 expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2);
88 expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2);
89 expect(svg.attr).toHaveBeenCalledWith('r', 250);
90 });
91
92 it('adds the name of each cycle for the right side', function () {
93 var center = 500 / 2;
94 spyOn(svg, 'text').andReturn(svg);
95 radarGraph.plot();
96
97 expect(svg.append).toHaveBeenCalledWith('text');
98 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
99 expect(svg.attr).toHaveBeenCalledWith('x', 0 + 10);
100 expect(svg.text).toHaveBeenCalledWith('Adopt');
101
102 expect(svg.append).toHaveBeenCalledWith('text');
103 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
104 expect(svg.attr).toHaveBeenCalledWith('x', 0 + (center / 2) + 10);
105 expect(svg.text).toHaveBeenCalledWith('Hold');
106 });
107
108 it('adds the name of each cycle for the right side', function () {
109 var center = 500 / 2;
110 spyOn(svg, 'text').andReturn(svg);
111 radarGraph.plot();
112
113 expect(svg.append).toHaveBeenCalledWith('text');
114 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
115 expect(svg.attr).toHaveBeenCalledWith('x', 500 - 10);
116 expect(svg.attr).toHaveBeenCalledWith('text-anchor', 'end');
117 expect(svg.text).toHaveBeenCalledWith('Adopt');
118
119 expect(svg.append).toHaveBeenCalledWith('text');
120 expect(svg.attr).toHaveBeenCalledWith('y', center + 4);
121 expect(svg.attr).toHaveBeenCalledWith('x', 500 - (center / 2) - 10);
122 expect(svg.attr).toHaveBeenCalledWith('text-anchor', 'end');
123 expect(svg.text).toHaveBeenCalledWith('Hold');
124 });
125 });
126 });