main_test.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. describe('#isClusterDataLoaded', function() {
  53. beforeEach(function () {
  54. sinon.stub(App.router, 'get').returns(true);
  55. });
  56. afterEach(function () {
  57. App.router.get.restore();
  58. });
  59. it ('Should return true', function() {
  60. expect(mainController.get('isClusterDataLoaded')).to.be.true;
  61. });
  62. });
  63. describe('#clusterDataLoadedPercent', function() {
  64. beforeEach(function () {
  65. sinon.stub(App, 'get').withArgs('router.clusterController.clusterDataLoadedPercent').returns(16);
  66. });
  67. afterEach(function () {
  68. App.get.restore();
  69. });
  70. it ('Should return 16', function() {
  71. expect(mainController.get('clusterDataLoadedPercent')).to.be.equal(16);
  72. });
  73. });
  74. describe('#initialize', function() {
  75. var initialize = false;
  76. beforeEach(function () {
  77. sinon.stub(App.router, 'get').returns({
  78. loadClusterData: function() {
  79. initialize = true;
  80. }
  81. });
  82. });
  83. afterEach(function () {
  84. App.router.get.restore();
  85. });
  86. it ('Should return true', function() {
  87. mainController.initialize();
  88. expect(initialize).to.be.true;
  89. });
  90. });
  91. describe('#dataLoading', function() {
  92. it ('Should resolve promise', function() {
  93. sinon.stub(App.router, 'get').returns(true);
  94. var deffer = mainController.dataLoading();
  95. App.router.get.restore();
  96. deffer.then(function(val){
  97. expect(val).to.be.undefined;
  98. });
  99. });
  100. it ('Should resolve promise', function() {
  101. sinon.stub(App.router, 'get').returns(false);
  102. setTimeout(function() {
  103. mainController.set('isClusterDataLoaded', true);
  104. },150);
  105. var deffer = mainController.dataLoading();
  106. App.router.get.restore();
  107. deffer.then(function(val){
  108. expect(val).to.be.undefined;
  109. });
  110. });
  111. });
  112. describe('#checkServerClientVersion', function() {
  113. var initialize = false;
  114. beforeEach(function () {
  115. sinon.stub(mainController, 'getServerVersion').returns({
  116. done: function(func) {
  117. if (func) {
  118. func();
  119. }
  120. }
  121. });
  122. });
  123. afterEach(function () {
  124. mainController.getServerVersion.restore();
  125. });
  126. it ('Should resolve promise', function() {
  127. var deffer = mainController.checkServerClientVersion();
  128. deffer.then(function(val){
  129. expect(val).to.be.undefined;
  130. });
  131. });
  132. });
  133. describe('#getServerVersion', function() {
  134. var res;
  135. beforeEach(function () {
  136. sinon.stub(App.ajax, 'send', function(data) {
  137. res = JSON.parse(JSON.stringify(data));
  138. });
  139. });
  140. afterEach(function () {
  141. App.ajax.send.restore();
  142. });
  143. it ('Should send data', function() {
  144. mainController.getServerVersion();
  145. expect(res).to.be.eql({
  146. "name": "ambari.service",
  147. "sender": {},
  148. "data": {
  149. "fields": "?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true"
  150. },
  151. "success": "getServerVersionSuccessCallback",
  152. "error": "getServerVersionErrorCallback"
  153. });
  154. });
  155. });
  156. describe('#stopAllService', function() {
  157. beforeEach(function () {
  158. sinon.stub(App.router, 'get').returns({
  159. stopAllService: function(func) {
  160. if (func) {
  161. func();
  162. }
  163. }
  164. });
  165. });
  166. afterEach(function () {
  167. App.router.get.restore();
  168. });
  169. it ('Should call event', function() {
  170. var done = false;
  171. var event = function() {
  172. done = true;
  173. };
  174. mainController.stopAllService(event);
  175. expect(done).to.be.true;
  176. });
  177. });
  178. describe('#startAllService', function() {
  179. beforeEach(function () {
  180. sinon.stub(App.router, 'get').returns({
  181. startAllService: function(func) {
  182. if (func) {
  183. func();
  184. }
  185. }
  186. });
  187. });
  188. afterEach(function () {
  189. App.router.get.restore();
  190. });
  191. it ('Should call event', function() {
  192. var done = false;
  193. var event = function() {
  194. done = true;
  195. };
  196. mainController.startAllService(event);
  197. expect(done).to.be.true;
  198. });
  199. });
  200. describe('#isStopAllDisabled', function() {
  201. beforeEach(function () {
  202. sinon.stub(mainController, 'scRequest').returns(true);
  203. });
  204. afterEach(function () {
  205. mainController.scRequest.restore();
  206. });
  207. it ('Should return true', function() {
  208. expect(mainController.get('isStopAllDisabled')).to.be.true;
  209. });
  210. });
  211. describe('#gotoAddService', function() {
  212. var done = false;
  213. beforeEach(function () {
  214. sinon.stub(App.router, 'get').returns({
  215. gotoAddService: function() {
  216. done = true;
  217. }
  218. });
  219. });
  220. afterEach(function () {
  221. App.router.get.restore();
  222. });
  223. it ('Should call router', function() {
  224. mainController.gotoAddService();
  225. expect(done).to.be.true;
  226. });
  227. });
  228. describe('#isStartAllDisabled', function() {
  229. beforeEach(function () {
  230. sinon.stub(mainController, 'scRequest').returns(true);
  231. });
  232. afterEach(function () {
  233. mainController.scRequest.restore();
  234. });
  235. it ('Should return true', function() {
  236. expect(mainController.get('isStartAllDisabled')).to.be.true;
  237. });
  238. });
  239. describe('#isAllServicesInstalled', function() {
  240. beforeEach(function () {
  241. sinon.stub(mainController, 'scRequest').returns(true);
  242. });
  243. afterEach(function () {
  244. mainController.scRequest.restore();
  245. });
  246. it ('Should return true', function() {
  247. expect(mainController.get('isAllServicesInstalled')).to.be.true;
  248. });
  249. });
  250. describe('#scRequest', function() {
  251. beforeEach(function () {
  252. sinon.stub(App.router, 'get').returns({
  253. get: function(request) {
  254. if (request) {
  255. request();
  256. }
  257. }
  258. });
  259. });
  260. afterEach(function () {
  261. App.router.get.restore();
  262. });
  263. it ('Should return true', function() {
  264. var done = false;
  265. var event = function() {
  266. done = true;
  267. };
  268. mainController.scRequest(event);
  269. expect(done).to.be.true;
  270. });
  271. });
  272. describe('#updateTitle', function() {
  273. beforeEach(function () {
  274. sinon.stub(App.router, 'get', function(message){
  275. if (message == 'clusterController.clusterName') {
  276. return 'c1';
  277. } else if (message == 'clusterInstallCompleted') {
  278. return true;
  279. } else if (message == 'clusterController') {
  280. return {
  281. get: function() {
  282. return true;
  283. }
  284. };
  285. }
  286. });
  287. });
  288. afterEach(function () {
  289. App.router.get.restore();
  290. });
  291. it ('Should update title', function() {
  292. $('body').append('<title id="title-id">text</title>');
  293. mainController.updateTitle();
  294. expect($('title').text()).to.be.equal('Ambari - c1');
  295. $('body').remove('#title-id');
  296. });
  297. });
  298. });