heatmap_metric_test.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. App.testMode = false;
  42. sinon.spy($, 'ajax');
  43. });
  44. afterEach(function() {
  45. $.ajax.restore();
  46. App.testMode = true;
  47. });
  48. mainChartHeatmapMetric = App.MainChartHeatmapMetric.create({});
  49. mainChartHeatmapMetric.set('ajaxIndex', 'hosts.metrics.host_component');
  50. mainChartHeatmapMetric.set('ajaxData', {
  51. serviceName: 'SERVICE',
  52. componentName: 'COMPONENT'
  53. });
  54. mainChartHeatmapMetric.set('defaultMetric', 'default.metric');
  55. it('Should load proper URL', function() {
  56. mainChartHeatmapMetric.refreshHostSlots();
  57. expect($.ajax.args[0][0].url.endsWith('/api/v1/clusters/tdk/services/SERVICE/components/COMPONENT?fields=host_components/default/metric')).to.equal(true);
  58. });
  59. });
  60. });