Add tests for RefTable
authorJosh Mock <josh@joshmock.com>
Wed, 20 May 2015 16:10:50 +0000 (11:10 -0500)
committerJosh Mock <josh@joshmock.com>
Wed, 20 May 2015 16:10:50 +0000 (11:10 -0500)
src/graphing/ref-table.js
test/graphing/ref-table-spec.js [new file with mode: 0644]

index f21e50c..6adaade 100644 (file)
@@ -53,7 +53,7 @@ tr.graphing.RefTable = function (radar) {
         html += '<tr class="radar-ref-status-group"><td colspan="3">' + cycle + '</td></tr>';
 
         blips[cycle].forEach(function (blip) {
-          html += '<tr id="blip-ref-' + blip.number() + '">' +
+          html += '<tr>' +
                     '<td>' + blip.number() + '</td>' +
                     '<td>' + blip.name() + '</td>' +
                     '<td>' + blip.description() + '</td>' +
diff --git a/test/graphing/ref-table-spec.js b/test/graphing/ref-table-spec.js
new file mode 100644 (file)
index 0000000..cdcc531
--- /dev/null
@@ -0,0 +1,69 @@
+describe('tr.graphing.RefTable', function () {
+    var radar, toolsQuadrant, techniquesQuadrant, platformsQuadrant, languageFramework, element;
+
+    beforeEach(function () {
+        toolsQuadrant = new tr.models.Quadrant('Tools');
+        techniquesQuadrant = new tr.models.Quadrant('Techniques');
+        platformsQuadrant = new tr.models.Quadrant('Platforms');
+        languageFramework = new tr.models.Quadrant('Languages');
+
+        radar = new tr.models.Radar();
+        radar.setFirstQuadrant(toolsQuadrant);
+        radar.setSecondQuadrant(techniquesQuadrant);
+        radar.setThirdQuadrant(platformsQuadrant);
+        radar.setFourthQuadrant(languageFramework);
+
+        element = { innerHTML: '' };
+        spyOn(document, 'querySelector').andReturn(element);
+    });
+
+    describe('render', function () {
+        it("groups blips by cycle", function () {
+            var adopt = new tr.models.Cycle('Adopt');
+            var assess = new tr.models.Cycle('Assess');
+
+            toolsQuadrant.add([
+                new tr.models.Blip('foo', adopt, true, 'this is foo'),
+                new tr.models.Blip('bar', assess, true, 'this is bar'),
+                new tr.models.Blip('baz', adopt, true, 'this is baz')
+            ]);
+
+            var table = new tr.graphing.RefTable(radar);
+            table.init('#some-id').render();
+
+            expect(element.innerHTML).toEqual(
+                '<table class="radar-ref-table">' +
+                    '<tr class="radar-ref-status-group"><td colspan="3">Adopt</td></tr>' +
+                    '<tr><td>-1</td><td>foo</td><td>this is foo</td></tr>' +
+                    '<tr><td>-1</td><td>baz</td><td>this is baz</td></tr>' +
+                    '<tr class="radar-ref-status-group"><td colspan="3">Assess</td></tr>' +
+                    '<tr><td>-1</td><td>bar</td><td>this is bar</td></tr>' +
+                '</table>');
+        });
+
+        it("respects the assigned order of cycles", function () {
+            var adopt = new tr.models.Cycle('Adopt', 1);
+            var assess = new tr.models.Cycle('Assess', 3);
+            var hold = new tr.models.Cycle('Hold', 2);
+
+            toolsQuadrant.add([
+                new tr.models.Blip('foo', adopt, true, 'this is foo'),
+                new tr.models.Blip('bar', assess, true, 'this is bar'),
+                new tr.models.Blip('baz', hold, true, 'this is baz')
+            ]);
+
+            var table = new tr.graphing.RefTable(radar);
+            table.init('#some-id').render();
+
+            expect(element.innerHTML).toEqual(
+                '<table class="radar-ref-table">' +
+                    '<tr class="radar-ref-status-group"><td colspan="3">Adopt</td></tr>' +
+                    '<tr><td>-1</td><td>foo</td><td>this is foo</td></tr>' +
+                    '<tr class="radar-ref-status-group"><td colspan="3">Hold</td></tr>' +
+                    '<tr><td>-1</td><td>baz</td><td>this is baz</td></tr>' +
+                    '<tr class="radar-ref-status-group"><td colspan="3">Assess</td></tr>' +
+                    '<tr><td>-1</td><td>bar</td><td>this is bar</td></tr>' +
+                '</table>');
+        });
+    });
+});