heatmap_metric_test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('controllers/main/charts/heatmap_metrics/heatmap_metric');
  19. describe('MainChartHeatmapMetric', function () {
  20. var mainChartHeatmapMetric = App.MainChartHeatmapMetric.create({});
  21. describe('#formatLegendNumber', function () {
  22. var tests = [
  23. {m:'undefined to undefined',i:undefined,e:undefined},
  24. {m:'0 to 0',i:0,e:0},
  25. {m:'1 to 1',i:1,e:1},
  26. {m:'1.23 to 1.2',i:1.23,e:1.2}
  27. ];
  28. tests.forEach(function(test) {
  29. it(test.m + ' ', function () {
  30. expect(mainChartHeatmapMetric.formatLegendNumber(test.i)).to.equal(test.e);
  31. });
  32. });
  33. it('NaN to NaN' + ' ', function () {
  34. expect(isNaN(mainChartHeatmapMetric.formatLegendNumber(NaN))).to.equal(true);
  35. });
  36. });
  37. describe('#refreshHostSlots', function() {
  38. beforeEach(function() {
  39. App.set('apiPrefix', '/api/v1');
  40. App.set('clusterName', 'tdk');
  41. sinon.stub(App, 'get', function(k) {
  42. if ('testMode' === k) return false;
  43. return Em.get(App, k);
  44. });
  45. sinon.spy($, 'ajax');
  46. });
  47. afterEach(function() {
  48. $.ajax.restore();
  49. App.get.restore();
  50. });
  51. mainChartHeatmapMetric = App.MainChartHeatmapMetric.create({});
  52. mainChartHeatmapMetric.set('ajaxIndex', 'hosts.metrics.host_component');
  53. mainChartHeatmapMetric.set('ajaxData', {
  54. serviceName: 'SERVICE',
  55. componentName: 'COMPONENT'
  56. });
  57. mainChartHeatmapMetric.set('defaultMetric', 'default.metric');
  58. it('Should load proper URL', function() {
  59. mainChartHeatmapMetric.refreshHostSlots();
  60. expect($.ajax.args[0][0].url.endsWith('/api/v1/clusters/tdk/services/SERVICE/components/COMPONENT?fields=host_components/default/metric')).to.equal(true);
  61. });
  62. });
  63. });