menu_test.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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/menu');
  20. var mainMenuView = App.MainMenuView.create();
  21. describe('App.MainMenuView', function () {
  22. describe('#content', function () {
  23. beforeEach(function () {
  24. this.mock = sinon.stub(App, 'get');
  25. sinon.stub(App.router, 'get')
  26. .withArgs('clusterController.isLoaded').returns(true)
  27. .withArgs('loggedIn').returns(true);
  28. });
  29. afterEach(function () {
  30. this.mock.restore();
  31. App.router.get.restore();
  32. });
  33. it('menu should be populated if cluster installation is completed', function () {
  34. this.mock.withArgs('router.clusterInstallCompleted').returns(true);
  35. App.router.notifyPropertyChange('clusterInstallCompleted');
  36. expect(mainMenuView.get('content').length > 1).to.be.true;
  37. });
  38. it('menu should not be populated if cluster installation is not completed', function () {
  39. this.mock.withArgs('router.clusterInstallCompleted').returns(false);
  40. App.router.notifyPropertyChange('clusterInstallCompleted');
  41. expect(mainMenuView.get('content').length > 1).to.be.false;
  42. });
  43. });
  44. describe('#itemViewClass', function () {
  45. beforeEach(function () {
  46. mainMenuView.reopen({
  47. content: [
  48. mainMenuView.get('itemViewClass').create({
  49. content: {
  50. routing: 'dashboard'
  51. }
  52. }),
  53. mainMenuView.get('itemViewClass').create({
  54. content: {
  55. routing: 'admin'
  56. }
  57. })
  58. ]
  59. });
  60. });
  61. describe('#dropdownCategories', function () {
  62. var cases = [
  63. {
  64. itemName: 'dashboard',
  65. dropdownCategories: [],
  66. title: 'not Admin item'
  67. },
  68. {
  69. itemName: 'admin',
  70. isHadoopWindowsStack: true,
  71. dropdownCategories: [
  72. {
  73. name: 'stackAndUpgrade',
  74. url: 'stack',
  75. label: Em.I18n.t('admin.stackUpgrade.title')
  76. },
  77. {
  78. name: 'adminServiceAccounts',
  79. url: 'serviceAccounts',
  80. label: Em.I18n.t('common.serviceAccounts')
  81. }
  82. ],
  83. title: 'Admin item, HDPWIN'
  84. },
  85. {
  86. itemName: 'admin',
  87. isHadoopWindowsStack: false,
  88. dropdownCategories: [
  89. {
  90. name: 'stackAndUpgrade',
  91. url: 'stack',
  92. label: Em.I18n.t('admin.stackUpgrade.title')
  93. },
  94. {
  95. name: 'adminServiceAccounts',
  96. url: 'serviceAccounts',
  97. label: Em.I18n.t('common.serviceAccounts')
  98. },
  99. {
  100. name: 'kerberos',
  101. url: 'kerberos/',
  102. label: Em.I18n.t('common.kerberos')
  103. }
  104. ],
  105. title: 'Admin item, not HDPWIN'
  106. }
  107. ];
  108. afterEach(function () {
  109. App.get.restore();
  110. });
  111. cases.forEach(function (item) {
  112. it(item.title, function () {
  113. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
  114. var menuItem = mainMenuView.get('content').findProperty('content.routing', item.itemName);
  115. menuItem.propertyDidChange('dropdownCategories');
  116. expect(menuItem.get('dropdownCategories')).to.eql(item.dropdownCategories);
  117. });
  118. });
  119. });
  120. });
  121. });