heatmap_test.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. beforeEach(function () {
  46. sinon.stub(App.ajax, 'send', function () {
  47. return {
  48. done: function (callback) {
  49. callback();
  50. }
  51. }
  52. });
  53. });
  54. afterEach(function () {
  55. App.ajax.send.restore();
  56. });
  57. var controller = App.MainChartsHeatmapController.create({
  58. activeWidgetLayout: Em.Object.create({
  59. displayName: 'widget',
  60. id: '1',
  61. scope: 'CLUSTER',
  62. layoutName: 'defualt_layout',
  63. sectionName: 'default_section'
  64. })
  65. });
  66. it('should call App.ajax', function () {
  67. controller.showHeatMapMetric({context:{id: 2}});
  68. expect(App.ajax.send.called).to.be.true;
  69. });
  70. });
  71. describe('#rackClass', function () {
  72. var controller = App.MainChartsHeatmapController.create({
  73. allMetrics: [],
  74. racks: [1]
  75. });
  76. it('should return "span12" for 1 cluster rack', function () {
  77. expect(controller.get('rackClass')).to.equal('span12');
  78. });
  79. it('should return "span6" for 2 cluster racks', function () {
  80. controller.set('racks', [1, 2]);
  81. expect(controller.get('rackClass')).to.equal('span6');
  82. });
  83. it('should return "span4" for 3 cluster racks', function () {
  84. controller.set('racks', [1, 2, 3]);
  85. expect(controller.get('rackClass')).to.equal('span4');
  86. });
  87. });
  88. });