namenode_cpu_test.js 2.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('utils/helper');
  20. require('views/common/chart/pie');
  21. require('views/main/dashboard/widget');
  22. require('views/main/dashboard/widgets/pie_chart_widget');
  23. require('views/main/dashboard/widgets/namenode_cpu');
  24. describe('App.NameNodeCpuPieChartView', function() {
  25. var model;
  26. var nameNodeCpuPieChartView;
  27. beforeEach(function () {
  28. model = Em.Object.create({
  29. used: null,
  30. max: null
  31. });
  32. nameNodeCpuPieChartView = App.NameNodeCpuPieChartView.create({
  33. model_type: null,
  34. model: model,
  35. modelFieldUsed: 'used',
  36. modelFieldMax: 'max',
  37. widgetHtmlId: 'fake'
  38. });
  39. nameNodeCpuPieChartView.calc();
  40. });
  41. afterEach(function () {
  42. nameNodeCpuPieChartView.destroy();
  43. clearTimeout(nameNodeCpuPieChartView.get('intervalId'));
  44. });
  45. describe('#calcIsPieExists', function() {
  46. var tests = [
  47. {
  48. cpuWio: 1,
  49. e: true,
  50. m: 'Exists'
  51. },
  52. {
  53. cpuWio: null,
  54. e: false,
  55. m: 'Not exists'
  56. },
  57. {
  58. cpuWio: undefined,
  59. e: false,
  60. m: 'Not exists'
  61. }
  62. ];
  63. tests.forEach(function(test) {
  64. it(test.m, function() {
  65. nameNodeCpuPieChartView.set('cpuWio', test.cpuWio);
  66. expect(nameNodeCpuPieChartView.calcIsPieExists()).to.equal(test.e);
  67. });
  68. });
  69. });
  70. describe('calcDataForPieChart', function () {
  71. var tests = [
  72. {
  73. cpuWio: 0,
  74. e: ['0.0', '0.00'],
  75. m: 'Nothing is used'
  76. },
  77. {
  78. cpuWio: 100,
  79. e: ['100.0', '100.00'],
  80. m: 'All is used'
  81. },
  82. {
  83. cpuWio: 50,
  84. e: ['50.0', '50.00'],
  85. m: 'Half is used'
  86. }
  87. ];
  88. tests.forEach(function(test) {
  89. it(test.m, function() {
  90. nameNodeCpuPieChartView.set('cpuWio', test.cpuWio);
  91. expect(nameNodeCpuPieChartView.calcDataForPieChart()).to.eql(test.e);
  92. });
  93. });
  94. });
  95. });