graph_widget_view_test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('views/common/widget/graph_widget_view');
  20. describe('App.GraphWidgetView', function () {
  21. var view = App.GraphWidgetView.create();
  22. describe("#adjustData()", function() {
  23. var testCases = [
  24. {
  25. title: 'empty data',
  26. data: {
  27. dataLinks: {},
  28. dataLength: 0
  29. },
  30. result: {}
  31. },
  32. {
  33. title: 'correct data',
  34. data: {
  35. dataLinks: {
  36. s1: [[0, 0]]
  37. },
  38. dataLength: 1
  39. },
  40. result: {
  41. s1: [[0, 0]]
  42. }
  43. },
  44. {
  45. title: 'second series empty',
  46. data: {
  47. dataLinks: {
  48. s1: [[1, 0]],
  49. s2: []
  50. },
  51. dataLength: 1
  52. },
  53. result: {
  54. s1: [[1, 0]],
  55. s2: [[0, 0]]
  56. }
  57. },
  58. {
  59. title: 'second series missing data at the end',
  60. data: {
  61. dataLinks: {
  62. s1: [[1, 0], [2, 1], [3, 2]],
  63. s2: [[1, 0]]
  64. },
  65. dataLength: 3
  66. },
  67. result: {
  68. s1: [[1, 0], [2, 1], [3, 2]],
  69. s2: [[1, 0], [0, 1], [0, 2]]
  70. }
  71. },
  72. {
  73. title: 'second series missing data at the beginning',
  74. data: {
  75. dataLinks: {
  76. s1: [[1, 0], [2, 1], [3, 2]],
  77. s2: [[3, 2]]
  78. },
  79. dataLength: 3
  80. },
  81. result: {
  82. s1: [[1, 0], [2, 1], [3, 2]],
  83. s2: [[0, 0], [0, 1], [3, 2]]
  84. }
  85. },
  86. {
  87. title: 'second series missing data in the middle',
  88. data: {
  89. dataLinks: {
  90. s1: [[1, 0], [2, 1], [3, 2]],
  91. s2: [[1, 1]]
  92. },
  93. dataLength: 3
  94. },
  95. result: {
  96. s1: [[1, 0], [2, 1], [3, 2]],
  97. s2: [[0, 0], [1, 1], [0, 2]]
  98. }
  99. },
  100. {
  101. title: 'second and third series missing data',
  102. data: {
  103. dataLinks: {
  104. s1: [[1, 0], [2, 1], [3, 2]],
  105. s2: [[1, 1]],
  106. s3: [[1, 2]]
  107. },
  108. dataLength: 3
  109. },
  110. result: {
  111. s1: [[1, 0], [2, 1], [3, 2]],
  112. s2: [[0, 0], [1, 1], [0, 2]],
  113. s3: [[0, 0], [0, 1], [1, 2]]
  114. }
  115. }
  116. ];
  117. testCases.forEach(function (test) {
  118. it(test.title, function () {
  119. view.adjustData(test.data.dataLinks, test.data.dataLength);
  120. expect(test.data.dataLinks).to.eql(test.result);
  121. });
  122. });
  123. });
  124. });