added the plot of circles to to the radar
[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 = buildSvg();
15 spyOn(svg, 'attr').andReturn(svg);
16
17 var radarGraph = new tr.graphing.Radar(svg, 500, radar);
18
19 expect(svg.attr).toHaveBeenCalledWith('width', 500);
20 expect(svg.attr).toHaveBeenCalledWith('height', 500);
21 });
22
23 describe('lines', function () {
24 it('plots a vertical line in the center', function () {
25 var svg = buildSvg();
26 spyOn(svg, 'append').andReturn(svg);
27 spyOn(svg, 'attr').andReturn(svg);
28
29 var radarGraph = new tr.graphing.Radar(svg, 500, radar);
30
31 radarGraph.plot();
32
33 expect(svg.append).toHaveBeenCalledWith('line');
34 expect(svg.attr).toHaveBeenCalledWith('x1', 500 / 2);
35 expect(svg.attr).toHaveBeenCalledWith('y1', 0);
36 expect(svg.attr).toHaveBeenCalledWith('x2', 500 / 2);
37 expect(svg.attr).toHaveBeenCalledWith('y2', 500);
38 expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5);
39 });
40
41 it('plots a horizontal line in the center', function () {
42 var svg = buildSvg();
43 spyOn(svg, 'append').andReturn(svg);
44 spyOn(svg, 'attr').andReturn(svg);
45
46 var radarGraph = new tr.graphing.Radar(svg, 500, radar);
47
48 radarGraph.plot();
49
50 expect(svg.append).toHaveBeenCalledWith('line');
51 expect(svg.attr).toHaveBeenCalledWith('x1', 0);
52 expect(svg.attr).toHaveBeenCalledWith('y1', 500 / 2);
53 expect(svg.attr).toHaveBeenCalledWith('x2', 500);
54 expect(svg.attr).toHaveBeenCalledWith('y2', 500 / 2);
55 expect(svg.attr).toHaveBeenCalledWith('stroke-width', 5);
56 });
57 });
58
59 describe('circles', function () {
60 var svg, radarGraph;
61
62 beforeEach(function () {
63 var radar;
64
65 svg = buildSvg();
66 spyOn(svg, 'append').andReturn(svg);
67 spyOn(svg, 'attr').andReturn(svg);
68
69 radar = new tr.models.Radar();
70 spyOn(radar, 'cycles').andReturn([
71 new tr.models.Cycle('Adopt'),
72 new tr.models.Cycle('Hold')
73 ]);
74 radarGraph = new tr.graphing.Radar(svg, 500, radar);
75 });
76
77 it('plots the circles for the cicles', function () {
78 radarGraph.plot();
79
80 expect(svg.append).toHaveBeenCalledWith('circle');
81 expect(svg.attr).toHaveBeenCalledWith('cx', 500 / 2);
82 expect(svg.attr).toHaveBeenCalledWith('cy', 500 / 2);
83 expect(svg.attr).toHaveBeenCalledWith('r', Math.round(250 / 2));
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', 250);
89 });
90 });
91 });