uptime_text_widget_test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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('views/main/dashboard/widget');
  20. require('views/main/dashboard/widgets/text_widget');
  21. require('views/main/dashboard/widgets/uptime_text_widget');
  22. describe('App.UptimeTextDashboardWidgetView', function() {
  23. describe('#timeConverter', function() {
  24. var ts1 = 1358245370553, ts2 = 0;
  25. var timestamps = [
  26. {
  27. t: ts1,
  28. e: {
  29. l: 2,
  30. f: new Date(ts1)
  31. }
  32. },
  33. {
  34. t: ts2,
  35. e: {
  36. l: 2,
  37. f: new Date(ts2)
  38. }
  39. }
  40. ];
  41. timestamps.forEach(function(timestamp) {
  42. var uptimeTextDashboardWidgetView = App.UptimeTextDashboardWidgetView.create({thresh1:40, thresh2:70});
  43. it('timestamp ' + timestamp.t, function() {
  44. var result = uptimeTextDashboardWidgetView.timeConverter(timestamp.t);
  45. expect(result.length).to.equal(timestamp.e.l);
  46. assert.include(timestamp.e.f.toString(), result[0].toString(), timestamp.e.f + ' contains string ' + result[0]);
  47. });
  48. });
  49. });
  50. describe('#uptimeProcessing', function() {
  51. var timestamps = [
  52. {
  53. t: (new Date()).getTime() - 10*1000,
  54. e: {
  55. timeUnit: 's'
  56. }
  57. },
  58. {
  59. t: (new Date()).getTime() - 3600*1000,
  60. e: {
  61. timeUnit: 'hr'
  62. }
  63. },
  64. {
  65. t: (new Date()).getTime() - 24*3600*1000,
  66. e: {
  67. timeUnit: 'd'
  68. }
  69. },
  70. {
  71. t: (new Date()).getTime() - 1800*1000,
  72. e: {
  73. timeUnit: 'min'
  74. }
  75. }
  76. ];
  77. timestamps.forEach(function(timestamp) {
  78. var uptimeTextDashboardWidgetView = App.UptimeTextDashboardWidgetView.create({thresh1:40, thresh2:70});
  79. it('timestamp ' + timestamp.t + '. timeUnit should be ' + '"' + timestamp.e.timeUnit + '"', function() {
  80. var result = uptimeTextDashboardWidgetView.uptimeProcessing(timestamp.t);
  81. expect(uptimeTextDashboardWidgetView.get('timeUnit')).to.equal(timestamp.e.timeUnit);
  82. });
  83. });
  84. });
  85. });