idea ide updates
[scannr.git] / js / flotr2 / spec / Flotr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
describe('Flotr', function () {
 
  describe('Plots', function () {
 
    var
      nodeA, nodeB,
      a, b;
 
    beforeEach(function () {
 
      // Add imagediff matchers
      this.addMatchers(imagediff.jasmine);
 
      nodeA = buildNode();
      nodeB = buildNode();
    });
 
    afterEach(function () {
      destroyNode(nodeA);
      destroyNode(nodeB);
      a = null;
      b = null;
      Flotr = null;
    });
 
    _.each(TestFlotr.ExampleList.examples, function (example, key) {
 
      it('should draw a `' + example.name + '`line graph', function () {
 
        executeExampleTest(example, StableFlotr, nodeA);
        executeExampleTest(example, TestFlotr, nodeB);
 
        if (example.timeout) {
          waits(example.timeout);
          runs (function () {
            expect(nodeB.graph.ctx).toImageDiffEqual(nodeA.graph.ctx, example.tolerance || 0);
          });
        } else {
          expect(nodeB.graph.ctx).toImageDiffEqual(nodeA.graph.ctx, example.tolerance || 0);
        }
      });
    });
 
    // Helpers
 
    function executeExampleTest (example, flotr, node) {
      Math.seedrandom(example.key);
      Flotr = flotr;
      example.callback.apply(this, [node].concat(example.args || []));
    }
 
    function buildNode () {
      var node = document.createElement('div');
      document.body.appendChild(node);
      node.style.width = '320px';
      node.style.height = '240px';
      return node;
    }
 
    function destroyNode (node) {
      document.body.removeChild(node);
    }
  });
 
  describe('Main', function () {
 
    it('gets a tick size', function () {
      expect(TestFlotr.getTickSize).not.toBeUndefined();
      expect(TestFlotr.getTickSize(10, 0, 100, 1)).toEqual(10);
      expect(TestFlotr.getTickSize(20, 0, 100, 1)).toEqual(5);
      expect(TestFlotr.getTickSize(5, 10, 110, 1)).toEqual(20);
      expect(TestFlotr.getTickSize(0, 0, 10, 1)).toEqual(Number.POSITIVE_INFINITY);
      expect(isNaN(TestFlotr.getTickSize(0, 0, -10, 1))).toBeTruthy();
    });
  });
});