debian-mirror-gitlab/spec/javascripts/graphs/stat_graph_contributors_graph_spec.js

153 lines
4.7 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
/* eslint-disable jasmine/no-suite-dupes, vars-on-top, no-var */
2018-03-17 18:26:18 +05:30
import { scaleLinear, scaleTime } from 'd3-scale';
import { timeParse } from 'd3-time-format';
2018-12-13 13:39:08 +05:30
import {
ContributorsGraph,
ContributorsMasterGraph,
} from '~/pages/projects/graphs/show/stat_graph_contributors_graph';
2015-09-11 14:41:01 +05:30
2018-03-17 18:26:18 +05:30
const d3 = { scaleLinear, scaleTime, timeParse };
2018-12-13 13:39:08 +05:30
describe('ContributorsGraph', function() {
describe('#set_x_domain', function() {
it('set the x_domain', function() {
2017-08-17 22:00:37 +05:30
ContributorsGraph.set_x_domain(20);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsGraph.prototype.x_domain).toEqual(20);
});
});
2016-09-29 09:46:39 +05:30
2018-12-13 13:39:08 +05:30
describe('#set_y_domain', function() {
it('sets the y_domain', function() {
2017-08-17 22:00:37 +05:30
ContributorsGraph.set_y_domain([{ commits: 30 }]);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]);
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#init_x_domain', function() {
it('sets the initial x_domain', function() {
ContributorsGraph.init_x_domain([{ date: '2013-01-31' }, { date: '2012-01-31' }]);
expect(ContributorsGraph.prototype.x_domain).toEqual(['2012-01-31', '2013-01-31']);
2017-08-17 22:00:37 +05:30
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#init_y_domain', function() {
it('sets the initial y_domain', function() {
2017-08-17 22:00:37 +05:30
ContributorsGraph.init_y_domain([{ commits: 30 }]);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]);
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#init_domain', function() {
it('calls init_x_domain and init_y_domain', function() {
spyOn(ContributorsGraph, 'init_x_domain');
spyOn(ContributorsGraph, 'init_y_domain');
2017-08-17 22:00:37 +05:30
ContributorsGraph.init_domain();
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsGraph.init_x_domain).toHaveBeenCalled();
expect(ContributorsGraph.init_y_domain).toHaveBeenCalled();
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#set_dates', function() {
it('sets the dates', function() {
ContributorsGraph.set_dates('2013-12-01');
expect(ContributorsGraph.prototype.dates).toEqual('2013-12-01');
2017-08-17 22:00:37 +05:30
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#set_x_domain', function() {
it("sets the instance's x domain using the prototype's x_domain", function() {
2017-08-17 22:00:37 +05:30
ContributorsGraph.prototype.x_domain = 20;
var instance = new ContributorsGraph();
2018-12-13 13:39:08 +05:30
instance.x = d3
.scaleTime()
.range([0, 100])
.clamp(true);
2017-08-17 22:00:37 +05:30
spyOn(instance.x, 'domain');
instance.set_x_domain();
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(instance.x.domain).toHaveBeenCalledWith(20);
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#set_y_domain', function() {
it("sets the instance's y domain using the prototype's y_domain", function() {
2017-08-17 22:00:37 +05:30
ContributorsGraph.prototype.y_domain = 30;
var instance = new ContributorsGraph();
2018-12-13 13:39:08 +05:30
instance.y = d3
.scaleLinear()
.range([100, 0])
.nice();
2017-08-17 22:00:37 +05:30
spyOn(instance.y, 'domain');
instance.set_y_domain();
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(instance.y.domain).toHaveBeenCalledWith(30);
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#set_domain', function() {
it('calls set_x_domain and set_y_domain', function() {
2017-08-17 22:00:37 +05:30
var instance = new ContributorsGraph();
spyOn(instance, 'set_x_domain');
spyOn(instance, 'set_y_domain');
instance.set_domain();
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(instance.set_x_domain).toHaveBeenCalled();
expect(instance.set_y_domain).toHaveBeenCalled();
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#set_data', function() {
it('sets the data', function() {
2017-08-17 22:00:37 +05:30
var instance = new ContributorsGraph();
2018-12-13 13:39:08 +05:30
instance.set_data('20');
expect(instance.data).toEqual('20');
2017-08-17 22:00:37 +05:30
});
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('ContributorsMasterGraph', function() {
2014-09-02 18:07:02 +05:30
// TODO: fix or remove
2017-08-17 22:00:37 +05:30
// describe("#process_dates", function () {
// it("gets and parses dates", function () {
// var graph = new ContributorsMasterGraph();
// var data = 'random data here';
// spyOn(graph, 'parse_dates');
// spyOn(graph, 'get_dates').andReturn("get");
// spyOn(ContributorsGraph,'set_dates').andCallThrough();
// graph.process_dates(data);
// expect(graph.parse_dates).toHaveBeenCalledWith(data);
// expect(graph.get_dates).toHaveBeenCalledWith(data);
// expect(ContributorsGraph.set_dates).toHaveBeenCalledWith("get");
// });
// });
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#get_dates', function() {
it('plucks the date field from data collection', function() {
2017-08-17 22:00:37 +05:30
var graph = new ContributorsMasterGraph();
2018-12-13 13:39:08 +05:30
var data = [{ date: '2013-01-01' }, { date: '2012-12-15' }];
expect(graph.get_dates(data)).toEqual(['2013-01-01', '2012-12-15']);
2017-08-17 22:00:37 +05:30
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#parse_dates', function() {
it('parses the dates', function() {
2017-08-17 22:00:37 +05:30
var graph = new ContributorsMasterGraph();
2018-12-13 13:39:08 +05:30
var parseDate = d3.timeParse('%Y-%m-%d');
var data = [{ date: '2013-01-01' }, { date: '2012-12-15' }];
2017-08-17 22:00:37 +05:30
var correct = [{ date: parseDate(data[0].date) }, { date: parseDate(data[1].date) }];
graph.parse_dates(data);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(data).toEqual(correct);
});
});
});