main_test.js 5.2 KB

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