PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/javascripts/graphs/stat_graph_contributors_graph_spec.js

https://gitlab.com/certik/gitlab-ce
JavaScript | 128 lines | 99 code | 14 blank | 15 comment | 0 complexity | 32d8e7eed16c9252444df59619791281 MD5 | raw file
  1. /* eslint-disable quotes, jasmine/no-suite-dupes, vars-on-top, no-var */
  2. import d3 from 'd3';
  3. import { ContributorsGraph, ContributorsMasterGraph } from '~/graphs/stat_graph_contributors_graph';
  4. describe("ContributorsGraph", function () {
  5. describe("#set_x_domain", function () {
  6. it("set the x_domain", function () {
  7. ContributorsGraph.set_x_domain(20);
  8. expect(ContributorsGraph.prototype.x_domain).toEqual(20);
  9. });
  10. });
  11. describe("#set_y_domain", function () {
  12. it("sets the y_domain", function () {
  13. ContributorsGraph.set_y_domain([{ commits: 30 }]);
  14. expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]);
  15. });
  16. });
  17. describe("#init_x_domain", function () {
  18. it("sets the initial x_domain", function () {
  19. ContributorsGraph.init_x_domain([{ date: "2013-01-31" }, { date: "2012-01-31" }]);
  20. expect(ContributorsGraph.prototype.x_domain).toEqual(["2012-01-31", "2013-01-31"]);
  21. });
  22. });
  23. describe("#init_y_domain", function () {
  24. it("sets the initial y_domain", function () {
  25. ContributorsGraph.init_y_domain([{ commits: 30 }]);
  26. expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]);
  27. });
  28. });
  29. describe("#init_domain", function () {
  30. it("calls init_x_domain and init_y_domain", function () {
  31. spyOn(ContributorsGraph, "init_x_domain");
  32. spyOn(ContributorsGraph, "init_y_domain");
  33. ContributorsGraph.init_domain();
  34. expect(ContributorsGraph.init_x_domain).toHaveBeenCalled();
  35. expect(ContributorsGraph.init_y_domain).toHaveBeenCalled();
  36. });
  37. });
  38. describe("#set_dates", function () {
  39. it("sets the dates", function () {
  40. ContributorsGraph.set_dates("2013-12-01");
  41. expect(ContributorsGraph.prototype.dates).toEqual("2013-12-01");
  42. });
  43. });
  44. describe("#set_x_domain", function () {
  45. it("sets the instance's x domain using the prototype's x_domain", function () {
  46. ContributorsGraph.prototype.x_domain = 20;
  47. var instance = new ContributorsGraph();
  48. instance.x = d3.time.scale().range([0, 100]).clamp(true);
  49. spyOn(instance.x, 'domain');
  50. instance.set_x_domain();
  51. expect(instance.x.domain).toHaveBeenCalledWith(20);
  52. });
  53. });
  54. describe("#set_y_domain", function () {
  55. it("sets the instance's y domain using the prototype's y_domain", function () {
  56. ContributorsGraph.prototype.y_domain = 30;
  57. var instance = new ContributorsGraph();
  58. instance.y = d3.scale.linear().range([100, 0]).nice();
  59. spyOn(instance.y, 'domain');
  60. instance.set_y_domain();
  61. expect(instance.y.domain).toHaveBeenCalledWith(30);
  62. });
  63. });
  64. describe("#set_domain", function () {
  65. it("calls set_x_domain and set_y_domain", function () {
  66. var instance = new ContributorsGraph();
  67. spyOn(instance, 'set_x_domain');
  68. spyOn(instance, 'set_y_domain');
  69. instance.set_domain();
  70. expect(instance.set_x_domain).toHaveBeenCalled();
  71. expect(instance.set_y_domain).toHaveBeenCalled();
  72. });
  73. });
  74. describe("#set_data", function () {
  75. it("sets the data", function () {
  76. var instance = new ContributorsGraph();
  77. instance.set_data("20");
  78. expect(instance.data).toEqual("20");
  79. });
  80. });
  81. });
  82. describe("ContributorsMasterGraph", function () {
  83. // TODO: fix or remove
  84. // describe("#process_dates", function () {
  85. // it("gets and parses dates", function () {
  86. // var graph = new ContributorsMasterGraph();
  87. // var data = 'random data here';
  88. // spyOn(graph, 'parse_dates');
  89. // spyOn(graph, 'get_dates').andReturn("get");
  90. // spyOn(ContributorsGraph,'set_dates').andCallThrough();
  91. // graph.process_dates(data);
  92. // expect(graph.parse_dates).toHaveBeenCalledWith(data);
  93. // expect(graph.get_dates).toHaveBeenCalledWith(data);
  94. // expect(ContributorsGraph.set_dates).toHaveBeenCalledWith("get");
  95. // });
  96. // });
  97. describe("#get_dates", function () {
  98. it("plucks the date field from data collection", function () {
  99. var graph = new ContributorsMasterGraph();
  100. var data = [{ date: "2013-01-01" }, { date: "2012-12-15" }];
  101. expect(graph.get_dates(data)).toEqual(["2013-01-01", "2012-12-15"]);
  102. });
  103. });
  104. describe("#parse_dates", function () {
  105. it("parses the dates", function () {
  106. var graph = new ContributorsMasterGraph();
  107. var parseDate = d3.time.format("%Y-%m-%d").parse;
  108. var data = [{ date: "2013-01-01" }, { date: "2012-12-15" }];
  109. var correct = [{ date: parseDate(data[0].date) }, { date: parseDate(data[1].date) }];
  110. graph.parse_dates(data);
  111. expect(data).toEqual(correct);
  112. });
  113. });
  114. });