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

299 lines
10 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
/* eslint-disable no-var, camelcase, vars-on-top */
2015-09-11 14:41:01 +05:30
2018-03-27 19:54:05 +05:30
import ContributorsStatGraphUtil from '~/pages/projects/graphs/show/stat_graph_contributors_util';
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('ContributorsStatGraphUtil', function() {
describe('#parse_log', function() {
it('returns a correctly parsed log', function() {
2014-09-02 18:07:02 +05:30
var fake_log = [
2018-12-13 13:39:08 +05:30
{
author_email: 'karlo@email.com',
author_name: 'Karlo Soriano',
date: '2013-05-09',
additions: 471,
},
{
author_email: 'dzaporozhets@email.com',
author_name: 'Dmitriy Zaporozhets',
date: '2013-05-08',
additions: 6,
deletions: 1,
},
{
author_email: 'dzaporozhets@email.com',
author_name: 'Dmitriy Zaporozhets',
date: '2013-05-08',
additions: 19,
deletions: 3,
},
{
author_email: 'dzaporozhets@email.com',
author_name: 'Dmitriy Zaporozhets',
date: '2013-05-08',
additions: 29,
deletions: 3,
},
2017-08-17 22:00:37 +05:30
];
2014-09-02 18:07:02 +05:30
var correct_parsed_log = {
total: [
2018-12-13 13:39:08 +05:30
{ date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
{ date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
2017-08-17 22:00:37 +05:30
],
by_author: [
{
2018-12-13 13:39:08 +05:30
author_name: 'Karlo Soriano',
author_email: 'karlo@email.com',
'2013-05-09': { date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
2017-08-17 22:00:37 +05:30
},
{
2018-12-13 13:39:08 +05:30
author_name: 'Dmitriy Zaporozhets',
author_email: 'dzaporozhets@email.com',
'2013-05-08': { date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
},
],
2017-08-17 22:00:37 +05:30
};
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.parse_log(fake_log)).toEqual(correct_parsed_log);
});
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#store_data', function() {
var fake_entry = { author: 'Karlo Soriano', date: '2013-05-09', additions: 471 };
2017-08-17 22:00:37 +05:30
var fake_total = {};
var fake_by_author = {};
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
it('calls #store_commits', function() {
2017-08-17 22:00:37 +05:30
spyOn(ContributorsStatGraphUtil, 'store_commits');
ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.store_commits).toHaveBeenCalled();
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
it('calls #store_additions', function() {
2017-08-17 22:00:37 +05:30
spyOn(ContributorsStatGraphUtil, 'store_additions');
ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.store_additions).toHaveBeenCalled();
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
it('calls #store_deletions', function() {
2017-08-17 22:00:37 +05:30
spyOn(ContributorsStatGraphUtil, 'store_deletions');
ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.store_deletions).toHaveBeenCalled();
});
});
2014-09-02 18:07:02 +05:30
// TODO: fix or remove
2017-08-17 22:00:37 +05:30
// describe("#store_commits", function () {
// var fake_total = "fake_total";
// var fake_by_author = "fake_by_author";
//
// it("calls #add twice with arguments fake_total and fake_by_author respectively", function () {
// spyOn(ContributorsStatGraphUtil, 'add');
// ContributorsStatGraphUtil.store_commits(fake_total, fake_by_author);
// expect(ContributorsStatGraphUtil.add.argsForCall).toEqual([["fake_total", "commits", 1], ["fake_by_author", "commits", 1]]);
// });
// });
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#add', function() {
it('adds 1 to current test_field in collection', function() {
2017-08-17 22:00:37 +05:30
var fake_collection = { test_field: 10 };
2018-12-13 13:39:08 +05:30
ContributorsStatGraphUtil.add(fake_collection, 'test_field', 1);
2017-08-17 22:00:37 +05:30
expect(fake_collection.test_field).toEqual(11);
});
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
it('inits and adds 1 if test_field in collection is not defined', function() {
2017-08-17 22:00:37 +05:30
var fake_collection = {};
2018-12-13 13:39:08 +05:30
ContributorsStatGraphUtil.add(fake_collection, 'test_field', 1);
2017-08-17 22:00:37 +05:30
expect(fake_collection.test_field).toEqual(1);
});
});
2014-09-02 18:07:02 +05:30
// TODO: fix or remove
2017-08-17 22:00:37 +05:30
// describe("#store_additions", function () {
// var fake_entry = {additions: 10};
// var fake_total= "fake_total";
// var fake_by_author = "fake_by_author";
// it("calls #add twice with arguments fake_total and fake_by_author respectively", function () {
// spyOn(ContributorsStatGraphUtil, 'add');
// ContributorsStatGraphUtil.store_additions(fake_entry, fake_total, fake_by_author);
// expect(ContributorsStatGraphUtil.add.argsForCall).toEqual([["fake_total", "additions", 10], ["fake_by_author", "additions", 10]]);
// });
// });
2014-09-02 18:07:02 +05:30
// TODO: fix or remove
2017-08-17 22:00:37 +05:30
// describe("#store_deletions", function () {
// var fake_entry = {deletions: 10};
// var fake_total= "fake_total";
// var fake_by_author = "fake_by_author";
// it("calls #add twice with arguments fake_total and fake_by_author respectively", function () {
// spyOn(ContributorsStatGraphUtil, 'add');
// ContributorsStatGraphUtil.store_deletions(fake_entry, fake_total, fake_by_author);
// expect(ContributorsStatGraphUtil.add.argsForCall).toEqual([["fake_total", "deletions", 10], ["fake_by_author", "deletions", 10]]);
// });
// });
2014-09-02 18:07:02 +05:30
2018-12-13 13:39:08 +05:30
describe('#add_date', function() {
it('adds a date field to the collection', function() {
var fake_date = '2013-10-02';
2017-08-17 22:00:37 +05:30
var fake_collection = {};
ContributorsStatGraphUtil.add_date(fake_date, fake_collection);
2018-12-13 13:39:08 +05:30
expect(fake_collection[fake_date].date).toEqual('2013-10-02');
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('#add_author', function() {
it('adds an author field to the collection', function() {
var fake_author = { author_name: 'Author', author_email: 'fake@email.com' };
2017-08-17 22:00:37 +05:30
var fake_author_collection = {};
var fake_email_collection = {};
2018-12-13 13:39:08 +05:30
ContributorsStatGraphUtil.add_author(
fake_author,
fake_author_collection,
fake_email_collection,
);
expect(fake_author_collection[fake_author.author_name].author_name).toEqual('Author');
expect(fake_email_collection[fake_author.author_email].author_name).toEqual('Author');
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('#get_total_data', function() {
it('returns the collection sorted via specified field', function() {
2014-09-02 18:07:02 +05:30
var fake_parsed_log = {
2017-08-17 22:00:37 +05:30
total: [
2018-12-13 13:39:08 +05:30
{ date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
{ date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
2017-08-17 22:00:37 +05:30
],
by_author: [
{
2018-12-13 13:39:08 +05:30
author: 'Karlo Soriano',
'2013-05-09': { date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
2017-08-17 22:00:37 +05:30
},
{
2018-12-13 13:39:08 +05:30
author: 'Dmitriy Zaporozhets',
'2013-05-08': { date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
},
],
2017-08-17 22:00:37 +05:30
};
var correct_total_data = [
2018-12-13 13:39:08 +05:30
{ date: '2013-05-08', commits: 3 },
{ date: '2013-05-09', commits: 1 },
2017-08-17 22:00:37 +05:30
];
2018-12-13 13:39:08 +05:30
expect(ContributorsStatGraphUtil.get_total_data(fake_parsed_log, 'commits')).toEqual(
correct_total_data,
);
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('#pick_field', function() {
it('returns the collection with only the specified field and date', function() {
2017-08-17 22:00:37 +05:30
var fake_parsed_log_total = [
2018-12-13 13:39:08 +05:30
{ date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
{ date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
2017-08-17 22:00:37 +05:30
];
2018-12-13 13:39:08 +05:30
ContributorsStatGraphUtil.pick_field(fake_parsed_log_total, 'commits');
var correct_pick_field_data = [
{ date: '2013-05-09', commits: 1 },
{ date: '2013-05-08', commits: 3 },
];
expect(ContributorsStatGraphUtil.pick_field(fake_parsed_log_total, 'commits')).toEqual(
correct_pick_field_data,
);
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('#get_author_data', function() {
it('returns the log by author sorted by specified field', function() {
2014-09-02 18:07:02 +05:30
var fake_parsed_log = {
total: [
2018-12-13 13:39:08 +05:30
{ date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
{ date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
2014-09-02 18:07:02 +05:30
],
by_author: [
{
2018-12-13 13:39:08 +05:30
author_name: 'Karlo Soriano',
author_email: 'karlo@email.com',
'2013-05-09': { date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
2014-09-02 18:07:02 +05:30
},
{
2018-12-13 13:39:08 +05:30
author_name: 'Dmitriy Zaporozhets',
author_email: 'dzaporozhets@email.com',
'2013-05-08': { date: '2013-05-08', additions: 54, deletions: 7, commits: 3 },
},
],
2017-08-17 22:00:37 +05:30
};
2014-09-02 18:07:02 +05:30
var correct_author_data = [
2018-12-13 13:39:08 +05:30
{
author_name: 'Dmitriy Zaporozhets',
author_email: 'dzaporozhets@email.com',
dates: { '2013-05-08': 3 },
deletions: 7,
additions: 54,
commits: 3,
},
{
author_name: 'Karlo Soriano',
author_email: 'karlo@email.com',
dates: { '2013-05-09': 1 },
deletions: 0,
additions: 471,
commits: 1,
},
2017-08-17 22:00:37 +05:30
];
2018-12-13 13:39:08 +05:30
expect(ContributorsStatGraphUtil.get_author_data(fake_parsed_log, 'commits')).toEqual(
correct_author_data,
);
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_log_entry', function() {
it('adds the corresponding info from the log entry to the author', function() {
var fake_log_entry = {
author_name: 'Karlo Soriano',
author_email: 'karlo@email.com',
'2013-05-09': { date: '2013-05-09', additions: 471, deletions: 0, commits: 1 },
};
var correct_parsed_log = {
author_name: 'Karlo Soriano',
author_email: 'karlo@email.com',
dates: { '2013-05-09': 1 },
deletions: 0,
additions: 471,
commits: 1,
2017-08-17 22:00:37 +05:30
};
2018-12-13 13:39:08 +05:30
expect(ContributorsStatGraphUtil.parse_log_entry(fake_log_entry, 'commits', null)).toEqual(
correct_parsed_log,
);
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('#in_range', function() {
var date = '2013-05-09';
it('returns true if date_range is null', function() {
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.in_range(date, null)).toEqual(true);
});
2018-12-13 13:39:08 +05:30
it('returns true if date is in range', function() {
var date_range = [new Date('2013-01-01'), new Date('2013-12-12')];
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.in_range(date, date_range)).toEqual(true);
});
2018-12-13 13:39:08 +05:30
it('returns false if date is not in range', function() {
var date_range = [new Date('1999-12-01'), new Date('2000-12-01')];
2017-08-17 22:00:37 +05:30
expect(ContributorsStatGraphUtil.in_range(date, date_range)).toEqual(false);
});
});
});