heatmap_test.js 3.7 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. function getController() {
  22. return App.MainChartsHeatmapController.create();
  23. }
  24. describe('MainChartsHeatmapController', function () {
  25. App.TestAliases.testAsComputedAlias(getController(), 'activeWidget', 'widgets.firstObject', 'object');
  26. App.TestAliases.testAsComputedAlias(getController(), 'hostToSlotMap', 'selectedMetric.hostToSlotMap', 'object');
  27. describe('#validation()', function () {
  28. var controller = App.MainChartsHeatmapController.create({
  29. allMetrics: [],
  30. selectedMetric: Ember.Object.create({maximumValue: 100})
  31. });
  32. it('should set maximumValue if inputMaximum consists only of digits', function () {
  33. controller.set("inputMaximum", 5);
  34. expect(controller.get('selectedMetric.maximumValue')).to.equal(5);
  35. });
  36. it('should not set maximumValue if inputMaximum consists not only of digits', function () {
  37. controller.set("inputMaximum", 'qwerty');
  38. expect(controller.get('selectedMetric.maximumValue')).to.equal(5);
  39. });
  40. it('should not set maximumValue if inputMaximum consists not only of digits', function () {
  41. controller.set("inputMaximum", '100%');
  42. expect(controller.get('selectedMetric.maximumValue')).to.equal(5);
  43. });
  44. it('should set maximumValue if inputMaximum consists only of digits', function () {
  45. controller.set("inputMaximum", 1000);
  46. expect(controller.get('selectedMetric.maximumValue')).to.equal(1000);
  47. })
  48. });
  49. describe('#showHeatMapMetric()', function () {
  50. beforeEach(function () {
  51. sinon.stub(App.ajax, 'send', function () {
  52. return {
  53. done: function (callback) {
  54. callback();
  55. }
  56. }
  57. });
  58. });
  59. afterEach(function () {
  60. App.ajax.send.restore();
  61. });
  62. var controller = App.MainChartsHeatmapController.create({
  63. activeWidgetLayout: Em.Object.create({
  64. displayName: 'widget',
  65. id: '1',
  66. scope: 'CLUSTER',
  67. layoutName: 'defualt_layout',
  68. sectionName: 'default_section'
  69. })
  70. });
  71. it('should call App.ajax', function () {
  72. controller.showHeatMapMetric({context:{id: 2}});
  73. expect(App.ajax.send.called).to.be.true;
  74. });
  75. });
  76. describe('#rackClass', function () {
  77. var controller = App.MainChartsHeatmapController.create({
  78. allMetrics: [],
  79. racks: [1]
  80. });
  81. it('should return "span12" for 1 cluster rack', function () {
  82. expect(controller.get('rackClass')).to.equal('span12');
  83. });
  84. it('should return "span6" for 2 cluster racks', function () {
  85. controller.set('racks', [1, 2]);
  86. expect(controller.get('rackClass')).to.equal('span6');
  87. });
  88. it('should return "span4" for 3 cluster racks', function () {
  89. controller.set('racks', [1, 2, 3]);
  90. expect(controller.get('rackClass')).to.equal('span4');
  91. });
  92. });
  93. });