aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/speedometer/c3-master/spec/api.grid-spec.js
blob: ebaeee6c27e64bd3db23baf2f4e5592c38c85af7 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
describe('c3 api grid', function () {
    'use strict';

    var chart, args;

    beforeEach(function (done) {
        chart = window.initChart(chart, args, done);
    });

    describe('ygrid.add and ygrid.remove', function () {

        it('should update args', function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30, 200, 100, 400, 150, 250]
                    ]
                }
            };
            expect(true).toBeTruthy();
        });

        it('should update y grids', function (done) {
            var main = chart.internal.main,
                expectedGrids = [
                    {
                        value: 100,
                        text: 'Pressure Low'
                    },
                    {
                        value: 200,
                        text: 'Pressure High'
                    }
                ],
                grids;

            // Call ygrids.add
            chart.ygrids.add(expectedGrids);
            setTimeout(function () {
                grids = main.selectAll('.c3-ygrid-line');
                expect(grids.size()).toBe(expectedGrids.length);
                grids.each(function (d, i) {
                    var y = +d3.select(this).select('line').attr('y1'),
                        text = d3.select(this).select('text').text(),
                        expectedY = Math.round(chart.internal.y(expectedGrids[i].value)),
                        expectedText = expectedGrids[i].text;
                    expect(y).toBe(expectedY);
                    expect(text).toBe(expectedText);
                });

                // Call ygrids.remove
                chart.ygrids.remove(expectedGrids);
                setTimeout(function () {
                    grids = main.selectAll('.c3-ygrid-line');
                    expect(grids.size()).toBe(0);
                }, 500);

            }, 500);

            setTimeout(function () {
                done();
            }, 1200);
        });

        it("should update x ygrids even if it's zoomed", function (done) {
            var main = chart.internal.main,
                expectedGrids = [
                    {
                        value: 0,
                        text: 'Pressure Low'
                    },
                    {
                        value: 1,
                        text: 'Pressure High'
                    }
                ],
                grids, domain;

            chart.zoom([0, 2]);
            setTimeout(function () {

                // Call xgrids
                chart.xgrids(expectedGrids);
                setTimeout(function () {
                    grids = main.selectAll('.c3-xgrid-line');
                    expect(grids.size()).toBe(expectedGrids.length);
                    grids.each(function (d, i) {
                        var x = +d3.select(this).select('line').attr('x1'),
                            text = d3.select(this).select('text').text(),
                            expectedX = Math.round(chart.internal.x(expectedGrids[i].value)),
                            expectedText = expectedGrids[i].text;
                        expect(x).toBe(expectedX);
                        expect(text).toBe(expectedText);
                    });

                    // check if it was not rescaled
                    domain = chart.internal.y.domain();
                    expect(domain[0]).toBeLessThan(0);
                    expect(domain[1]).toBeGreaterThan(400);

                    // Call xgrids.remove
                    chart.xgrids.remove(expectedGrids);
                    setTimeout(function () {
                        grids = main.selectAll('.c3-xgrid-line');
                        expect(grids.size()).toBe(0);
                    }, 500); // for xgrids.remove()

                }, 500); // for xgrids()

            }, 500); // for zoom

            setTimeout(function () {
                done();
            }, 1700);
        });

    });

});