menu_test.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. var view;
  20. describe('App.MainHostMenuView', function () {
  21. beforeEach(function () {
  22. view = App.MainHostMenuView.create({});
  23. });
  24. describe('#content', function () {
  25. beforeEach(function () {
  26. this.mock = sinon.stub(App, 'get');
  27. });
  28. afterEach(function () {
  29. App.get.restore();
  30. });
  31. Em.A([
  32. {
  33. stackVersionsAvailable: true,
  34. stackUpgrade: true,
  35. m: '`versions` is visible',
  36. e: false
  37. },
  38. {
  39. stackVersionsAvailable: true,
  40. stackUpgrade: false,
  41. m: '`versions` is invisible (1)',
  42. e: true
  43. },
  44. {
  45. stackVersionsAvailable: false,
  46. stackUpgrade: true,
  47. m: '`versions` is invisible (2)',
  48. e: true
  49. },
  50. {
  51. stackVersionsAvailable: false,
  52. stackUpgrade: false,
  53. m: '`versions` is invisible (3)',
  54. e: true
  55. }
  56. ]).forEach(function (test) {
  57. it(test.m, function () {
  58. this.mock.withArgs('stackVersionsAvailable').returns(test.stackVersionsAvailable);
  59. this.mock.withArgs('supports.stackUpgrade').returns(test.stackUpgrade);
  60. view.propertyDidChange('content');
  61. expect(view.get('content').findProperty('name', 'versions').get('hidden')).to.equal(test.e);
  62. });
  63. });
  64. Em.A([
  65. {
  66. logSearch: false,
  67. m: '`logs` tab is invisible',
  68. e: true
  69. },
  70. {
  71. logSearch: true,
  72. m: '`logs` tab is visible',
  73. e: false
  74. }
  75. ]).forEach(function(test) {
  76. it(test.m, function() {
  77. this.mock.withArgs('supports.logSearch').returns(test.logSearch);
  78. view.propertyDidChange('content');
  79. expect(view.get('content').findProperty('name', 'logs').get('hidden')).to.equal(test.e);
  80. });
  81. });
  82. });
  83. describe("#updateAlertCounter()", function() {
  84. it("CRITICAL alerts", function() {
  85. view.setProperties({
  86. host: Em.Object.create({
  87. criticalWarningAlertsCount: 1,
  88. alertsSummary: Em.Object.create({
  89. CRITICAL: 1,
  90. WARNING: 0
  91. })
  92. })
  93. });
  94. view.updateAlertCounter();
  95. expect(view.get('content').findProperty('name', 'alerts').get('badgeText')).to.equal('1');
  96. expect(view.get('content').findProperty('name', 'alerts').get('badgeClasses')).to.equal('label alerts-crit-count');
  97. });
  98. it("WARNING alerts", function() {
  99. view.setProperties({
  100. host: Em.Object.create({
  101. criticalWarningAlertsCount: 1,
  102. alertsSummary: Em.Object.create({
  103. CRITICAL: 0,
  104. WARNING: 1
  105. })
  106. })
  107. });
  108. view.updateAlertCounter();
  109. expect(view.get('content').findProperty('name', 'alerts').get('badgeText')).to.equal('1');
  110. expect(view.get('content').findProperty('name', 'alerts').get('badgeClasses')).to.equal('label alerts-warn-count');
  111. });
  112. });
  113. describe("#deactivateChildViews()", function() {
  114. it("active attr should be empty", function() {
  115. view.set('_childViews', [Em.Object.create({active: 'active'})]);
  116. view.deactivateChildViews();
  117. expect(view.get('_childViews').mapProperty('active')).to.eql(['']);
  118. });
  119. });
  120. });