main_test.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 testHelpers = require('test/helpers');
  20. describe('App.MainController', function () {
  21. var mainController = App.MainController.create();
  22. describe('#getServerVersionSuccessCallback', function () {
  23. var controller = App.MainController.create(),
  24. cases = [
  25. {
  26. osFamily: 'redhat5',
  27. expected: false
  28. },
  29. {
  30. osFamily: 'redhat6',
  31. expected: true
  32. },
  33. {
  34. osFamily: 'suse11',
  35. expected: false
  36. }
  37. ],
  38. title = 'App.isManagedMySQLForHiveEnabled should be {0} for {1}';
  39. cases.forEach(function (item) {
  40. it(title.format(item.expected, item.osFamily), function () {
  41. controller.getServerVersionSuccessCallback({
  42. 'RootServiceComponents': {
  43. 'component_version': '',
  44. 'properties': {
  45. 'server.os_family': item.osFamily
  46. }
  47. }
  48. });
  49. expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected);
  50. });
  51. });
  52. });
  53. App.TestAliases.testAsComputedAlias(mainController, 'isClusterDataLoaded', 'App.router.clusterController.isLoaded', 'boolean');
  54. App.TestAliases.testAsComputedAlias(mainController, 'clusterDataLoadedPercent', 'App.router.clusterController.clusterDataLoadedPercent', 'string');
  55. describe('#initialize', function() {
  56. var initialize = false;
  57. beforeEach(function () {
  58. sinon.stub(App.router, 'get').returns({
  59. loadClusterData: function() {
  60. initialize = true;
  61. }
  62. });
  63. });
  64. afterEach(function () {
  65. App.router.get.restore();
  66. });
  67. it ('Should return true', function() {
  68. mainController.initialize();
  69. expect(initialize).to.be.true;
  70. });
  71. });
  72. describe('#dataLoading', function() {
  73. beforeEach(function () {
  74. this.stub = sinon.stub(App.router, 'get');
  75. });
  76. afterEach(function () {
  77. this.stub.restore();
  78. });
  79. it ('Should resolve promise', function() {
  80. this.stub.returns(true);
  81. var deffer = mainController.dataLoading();
  82. deffer.then(function(val){
  83. expect(val).to.be.undefined;
  84. });
  85. });
  86. it ('Should resolve promise (2)', function(done) {
  87. this.stub.returns(false);
  88. setTimeout(function() {
  89. mainController.set('isClusterDataLoaded', true);
  90. },150);
  91. var deffer = mainController.dataLoading();
  92. deffer.then(function(val){
  93. expect(val).to.be.undefined;
  94. done();
  95. });
  96. });
  97. });
  98. describe('#checkServerClientVersion', function() {
  99. beforeEach(function () {
  100. sinon.stub(mainController, 'getServerVersion').returns({
  101. done: function(func) {
  102. if (func) {
  103. func();
  104. }
  105. }
  106. });
  107. });
  108. afterEach(function () {
  109. mainController.getServerVersion.restore();
  110. });
  111. it ('Should resolve promise', function() {
  112. var deffer = mainController.checkServerClientVersion();
  113. deffer.then(function(val){
  114. expect(val).to.be.undefined;
  115. });
  116. });
  117. });
  118. describe('#getServerVersion', function() {
  119. it ('Should send data', function() {
  120. mainController.getServerVersion();
  121. var args = testHelpers.findAjaxRequest('name', 'ambari.service');
  122. expect(args[0]).to.exists;
  123. expect(args[0].sender).to.be.eql(mainController);
  124. expect(args[0].data.fields).to.be.equal('?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true');
  125. });
  126. });
  127. describe.skip('#updateTitle', function() {
  128. beforeEach(function () {
  129. sinon.stub(App.router, 'get', function(message){
  130. if (message === 'clusterController.clusterName') {
  131. return 'c1';
  132. } else if (message === 'clusterInstallCompleted') {
  133. return true;
  134. } else if (message === 'clusterController') {
  135. return {
  136. get: function() {
  137. return true;
  138. }
  139. };
  140. }
  141. });
  142. });
  143. afterEach(function () {
  144. App.router.get.restore();
  145. });
  146. it('Should update title', function() {
  147. $('body').append('<title id="title-id">text</title>');
  148. mainController.updateTitle();
  149. expect($('title').text()).to.be.equal('Ambari - c1');
  150. $('body').remove('#title-id');
  151. });
  152. });
  153. });