heatmap_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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('controllers/main/charts/heatmap');
  20. describe('MainChartsHeatmapController', function () {
  21. describe('#validation()', function () {
  22. var controller = App.MainChartsHeatmapController.create({
  23. allMetrics: [],
  24. selectedMetric: Ember.Object.create({maximumValue: 100})
  25. });
  26. it('should set maximumValue if inputMaximum consists only of digits', function () {
  27. controller.set("inputMaximum", 5);
  28. expect(controller.get('selectedMetric.maximumValue')).to.equal(5);
  29. })
  30. it('should not set maximumValue if inputMaximum consists not only of digits', function () {
  31. controller.set("inputMaximum", 'qwerty');
  32. expect(controller.get('selectedMetric.maximumValue')).to.equal(5);
  33. })
  34. it('should not set maximumValue if inputMaximum consists not only of digits', function () {
  35. controller.set("inputMaximum", '100%');
  36. expect(controller.get('selectedMetric.maximumValue')).to.equal(5);
  37. })
  38. it('should set maximumValue if inputMaximum consists only of digits', function () {
  39. controller.set("inputMaximum", 1000);
  40. expect(controller.get('selectedMetric.maximumValue')).to.equal(1000);
  41. })
  42. });
  43. describe('#showHeatMapMetric()', function () {
  44. var controller = App.MainChartsHeatmapController.create({
  45. allMetrics: [],
  46. selectedMetric: Ember.Object.create({maximumValue: 100}),
  47. loadMetrics: function () {
  48. }
  49. });
  50. controller.set("selectedMetric", 100);
  51. it('should not set selectedMetric event.context if it is not defined', function () {
  52. controller.showHeatMapMetric({});
  53. expect(controller.get('selectedMetric')).to.equal(100);
  54. })
  55. it('should set selectedMetric event.context if it is defined', function () {
  56. controller.showHeatMapMetric({context: 5});
  57. expect(controller.get('selectedMetric')).to.equal(5);
  58. })
  59. });
  60. describe('#loadMetrics()', function () {
  61. var controller = App.MainChartsHeatmapController.create({
  62. testPassed: false,
  63. allMetrics: [],
  64. inputMaximum: 10
  65. });
  66. controller.set('selectedMetric', Ember.Object.create({
  67. maximumValue: 100,
  68. refreshHostSlots: function () {
  69. controller.set('testPassed', true);
  70. }
  71. }))
  72. controller.loadMetrics();
  73. it('should set inputMaximum as selectedMetric.maximumValue', function () {
  74. expect(controller.get('inputMaximum')).to.equal(100);
  75. })
  76. it('should call refreshHostSlots from selectedMetric', function () {
  77. expect(controller.get('testPassed')).to.equal(true);
  78. })
  79. });
  80. describe('#rackClass', function () {
  81. var controller = App.MainChartsHeatmapController.create({
  82. allMetrics: [],
  83. cluster: {racks: [1]}
  84. });
  85. it('should return "span12" for 1 cluster rack', function () {
  86. expect(controller.get('rackClass')).to.equal('span12');
  87. })
  88. it('should return "span6" for 2 cluster racks', function () {
  89. controller.set('cluster', {racks: [1, 2]});
  90. expect(controller.get('rackClass')).to.equal('span6');
  91. })
  92. it('should return "span4" for 3 cluster racks', function () {
  93. controller.set('cluster', {racks: [1, 2, 3]});
  94. expect(controller.get('rackClass')).to.equal('span4');
  95. })
  96. });
  97. });