PageRenderTime 31ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/javascripts/graphs/stat_graph_contributors_graph_spec.js

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