heatmap_test.js 4.0 KB

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