added tasks to minify and to generate css from scss files
[tech-radar.git] / test / graphing / radar-spec.js
index f02ef06..3a38292 100644 (file)
@@ -1,21 +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, radarGraph;
-    svg = buildSvg();
+
+    radarGraph = new tr.graphing.Radar(500, radar);
+    radarGraph.init();
+
+    svg = radarGraph.svg();
     spyOn(svg, 'attr').andReturn(svg);
 
-    radarGraph = new tr.graphing.Radar(svg, 500, radar);
+    radarGraph.plot();
 
     expect(svg.attr).toHaveBeenCalledWith('width', 500);
     expect(svg.attr).toHaveBeenCalledWith('height', 500);
@@ -23,14 +59,15 @@ describe('tr.graphing.Radar', function () {
 
   describe('lines', function () {
     it('plots a vertical line in the center', function () {
-      var svg, radarGraph;
+      var radarGraph, svg;
+
+      radarGraph = new tr.graphing.Radar(500, radar);
+      radarGraph.init();
 
-      svg = buildSvg();
+      svg = radarGraph.svg();
       spyOn(svg, 'append').andReturn(svg);
       spyOn(svg, 'attr').andReturn(svg);
 
-      radarGraph = new tr.graphing.Radar(svg, 500, radar);
-
       radarGraph.plot();
 
       expect(svg.append).toHaveBeenCalledWith('line');
@@ -44,12 +81,13 @@ describe('tr.graphing.Radar', function () {
     it('plots a horizontal line in the center', function () {
       var svg, radarGraph;
 
-      svg = buildSvg();
+      radarGraph = new tr.graphing.Radar(500, radar);
+      radarGraph.init();
+
+      svg = radarGraph.svg();
       spyOn(svg, 'append').andReturn(svg);
       spyOn(svg, 'attr').andReturn(svg);
 
-      radarGraph = new tr.graphing.Radar(svg, 500, radar);
-
       radarGraph.plot();
 
       expect(svg.append).toHaveBeenCalledWith('line');
@@ -67,16 +105,17 @@ 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 cycles', function () {