wizard_test.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  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('models/cluster');
  20. require('controllers/wizard');
  21. var c;
  22. function getSteps(start, count) {
  23. var steps = [];
  24. for (var j = start; j <= count; j++) {
  25. steps.push(Em.Object.create({step: j, value: false}));
  26. }
  27. return steps;
  28. }
  29. describe('App.WizardController', function () {
  30. var wizardController = App.WizardController.create({});
  31. var totalSteps = 11;
  32. var ruller = d3.range(0, totalSteps);
  33. var i;
  34. beforeEach(function () {
  35. c = App.WizardController.create({});
  36. });
  37. describe('#setLowerStepsDisable', function () {
  38. var steps = getSteps(1, 10);
  39. wizardController.set('isStepDisabled', steps);
  40. steps.forEach(function (step) {
  41. var index = step.get('step');
  42. it('Steps: 10 | Disabled: ' + (index - 1), function () {
  43. wizardController.setLowerStepsDisable(index);
  44. expect(wizardController.get('isStepDisabled').filterProperty('value', true).length).to.be.equal(index - 1);
  45. });
  46. });
  47. });
  48. // isStep0 ... isStep10 tests
  49. App.WizardController1 = App.WizardController.extend({currentStep:''});
  50. var tests = [];
  51. for (i = 0; i < totalSteps; i++) {
  52. var n = ruller.slice(0);
  53. n.splice(i, 1);
  54. tests.push({i: i, n: n});
  55. }
  56. tests.forEach(function (test) {
  57. describe('isStep' + test.i, function () {
  58. var w = App.WizardController1.create();
  59. w.set('currentStep', test.i);
  60. it('Current Step is {0}, so isStep{1} is TRUE'.format(test.i, test.i), function () {
  61. expect(w.get('isStep' + test.i)).to.equal(true);
  62. });
  63. test.n.forEach(function (indx) {
  64. it('Current Step is {0}, so isStep{1} is FALSE'.format(test.i, indx), function () {
  65. expect(w.get('isStep' + indx)).to.equal(false);
  66. });
  67. });
  68. });
  69. });
  70. // isStep0 ... isStep10 tests end
  71. describe('#gotoStep', function() {
  72. var w = App.WizardController1.create();
  73. var steps = getSteps(0, totalSteps - 1);
  74. steps.forEach(function(step, index) {
  75. step.set('value', true);
  76. w.set('isStepDisabled', steps);
  77. it('step {0} is disabled, so gotoStep({1}) is not possible'.format(index, index), function() {
  78. expect(w.gotoStep(index)).to.equal(false);
  79. });
  80. });
  81. });
  82. describe('#launchBootstrapSuccessCallback', function() {
  83. var params = {popup: {finishLoading: function(){}}};
  84. beforeEach(function () {
  85. sinon.spy(params.popup, "finishLoading");
  86. });
  87. afterEach(function () {
  88. params.popup.finishLoading.restore();
  89. });
  90. it('Save bootstrapRequestId', function() {
  91. var data = {requestId: 123, status: 'SUCCESS', log: 'ok'};
  92. wizardController.launchBootstrapSuccessCallback(data, {}, params);
  93. expect(params.popup.finishLoading.calledWith(123, null, 'SUCCESS', 'ok')).to.be.true;
  94. });
  95. });
  96. describe('#getInstallOptions', function () {
  97. var cases = [
  98. {
  99. isHadoopWindowsStack: true,
  100. expected: {
  101. useSsh: false
  102. }
  103. },
  104. {
  105. isHadoopWindowsStack: false,
  106. expected: {
  107. useSsh: true
  108. }
  109. }
  110. ],
  111. title = 'should return {0}';
  112. beforeEach(function () {
  113. sinon.stub(wizardController, 'get')
  114. .withArgs('installOptionsTemplate').returns({useSsh: true})
  115. .withArgs('installWindowsOptionsTemplate').returns({useSsh: false});
  116. this.stub = sinon.stub(App, 'get');
  117. });
  118. afterEach(function () {
  119. App.get.restore();
  120. wizardController.get.restore();
  121. });
  122. cases.forEach(function (item) {
  123. it(title.format(item.expected), function () {
  124. this.stub.withArgs('isHadoopWindowsStack').returns(item.isHadoopWindowsStack);
  125. expect(wizardController.getInstallOptions()).to.eql(item.expected);
  126. });
  127. });
  128. });
  129. describe('#clearInstallOptions', function () {
  130. wizardController.setProperties({
  131. content: {},
  132. name: 'wizardController'
  133. });
  134. beforeEach(function () {
  135. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
  136. });
  137. afterEach(function () {
  138. App.get.restore();
  139. });
  140. describe('should clear install options', function () {
  141. beforeEach(function () {
  142. wizardController.clearInstallOptions();
  143. });
  144. it('content.installOptions', function () {
  145. expect(wizardController.get('content.installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
  146. });
  147. it('content.hosts', function () {
  148. expect(wizardController.get('content.hosts')).to.eql({});
  149. });
  150. it('installOptions', function () {
  151. expect(wizardController.getDBProperty('installOptions')).to.eql(wizardController.get('installOptionsTemplate'));
  152. });
  153. it('hosts', function () {
  154. expect(wizardController.getDBProperty('hosts')).to.eql({});
  155. });
  156. });
  157. });
  158. describe('#loadServiceConfigGroups', function () {
  159. beforeEach(function () {
  160. sinon.stub(wizardController, 'getDBProperties', function() {
  161. return {
  162. serviceConfigGroups: [
  163. {
  164. hosts: ['h1']
  165. }
  166. ],
  167. hosts: Em.Object.create({
  168. h1: Em.Object.create({
  169. id: 'h1'
  170. })
  171. })
  172. };
  173. });
  174. });
  175. afterEach(function () {
  176. wizardController.getDBProperties.restore();
  177. });
  178. it('should load service confgig group', function () {
  179. wizardController.loadServiceConfigGroups();
  180. expect(wizardController.get('content.configGroups')).to.eql([
  181. {
  182. "hosts": [
  183. "h1"
  184. ]
  185. }
  186. ]);
  187. });
  188. });
  189. describe('#saveTasksStatuses', function () {
  190. it('should set status', function () {
  191. wizardController.saveTasksStatuses('st');
  192. expect(wizardController.get('content.tasksStatuses')).to.equal('st');
  193. });
  194. });
  195. describe('#saveSlaveComponentHosts', function () {
  196. beforeEach(function(){
  197. sinon.stub(wizardController,'getDBProperty').returns(Em.A({
  198. 'h1': {
  199. id: 1
  200. }
  201. }));
  202. });
  203. afterEach(function(){
  204. wizardController.getDBProperty.restore();
  205. });
  206. it('should save slave components', function () {
  207. var stepController = Em.Object.create({
  208. hosts: Em.A([
  209. Em.Object.create({
  210. hostName: 'h1',
  211. checkboxes: Em.A([
  212. Em.Object.create({title: 'hl1', checked: true})
  213. ])
  214. })
  215. ]),
  216. headers: Em.A([
  217. Em.Object.create({name: 'header1', label: 'hl1'})
  218. ])
  219. });
  220. wizardController.saveSlaveComponentHosts(stepController);
  221. var res = JSON.parse(JSON.stringify(wizardController.get('content.slaveComponentHosts')));
  222. expect(res).to.eql([
  223. {
  224. "componentName": "header1",
  225. "displayName": "hl1",
  226. "hosts": [
  227. {
  228. "group": "Default",
  229. "host_id": 1
  230. }
  231. ]
  232. }
  233. ]);
  234. });
  235. });
  236. describe('#showLaunchBootstrapPopup', function () {
  237. afterEach(function(){
  238. App.ModalPopup.show.restore();
  239. });
  240. describe('errors', function () {
  241. beforeEach(function () {
  242. sinon.stub(App.ModalPopup,'show', function (data) {
  243. data.finishLoading.call(c);
  244. });
  245. });
  246. it('should set error', function () {
  247. c.showLaunchBootstrapPopup(Em.K);
  248. expect(c.get('isError')).to.be.true;
  249. });
  250. });
  251. describe('#finishLoading', function () {
  252. var stepController = App.get('router.wizardStep3Controller'),
  253. cases = [
  254. {
  255. requestId: null,
  256. serverError: 'error',
  257. wizardControllerProperties: {
  258. isError: true,
  259. showFooter: true,
  260. showCloseButton: true,
  261. serverError: 'error'
  262. },
  263. stepControllerProperties: {
  264. isRegistrationInProgress: false,
  265. isBootstrapFailed: true
  266. },
  267. bootStatus: 'FAILED',
  268. callbackCallCount: 0,
  269. hideCallCount: 0,
  270. title: 'no request id'
  271. },
  272. {
  273. requestId: 0,
  274. status: 'ERROR',
  275. log: 'log',
  276. wizardControllerProperties: {
  277. isError: true,
  278. showFooter: true,
  279. showCloseButton: true,
  280. serverError: 'log'
  281. },
  282. stepControllerProperties: {
  283. isRegistrationInProgress: false,
  284. isBootstrapFailed: true
  285. },
  286. bootStatus: 'FAILED',
  287. callbackCallCount: 0,
  288. hideCallCount: 0,
  289. title: 'ERROR status'
  290. },
  291. {
  292. requestId: 1,
  293. log: 'log',
  294. wizardControllerProperties: {
  295. isError: false,
  296. showFooter: false,
  297. showCloseButton: false,
  298. serverError: null
  299. },
  300. stepControllerProperties: {
  301. isRegistrationInProgress: true,
  302. isBootstrapFailed: false
  303. },
  304. bootStatus: 'PENDING',
  305. callbackCallCount: 1,
  306. hideCallCount: 1,
  307. title: 'request accepted'
  308. }
  309. ];
  310. beforeEach(function () {
  311. c.setProperties({
  312. isError: false,
  313. showFooter: false,
  314. showCloseButton: false,
  315. serverError: null,
  316. hide: Em.K,
  317. callback: Em.K
  318. });
  319. stepController.setProperties({
  320. isRegistrationInProgress: true,
  321. isBootstrapFailed: false,
  322. hosts: [
  323. {
  324. bootStatus: 'PENDING'
  325. },
  326. {
  327. bootStatus: 'PENDING'
  328. }
  329. ]
  330. });
  331. sinon.spy(c, 'hide');
  332. sinon.spy(c, 'callback');
  333. });
  334. afterEach(function () {
  335. c.hide.restore();
  336. c.callback.restore();
  337. });
  338. cases.forEach(function (item) {
  339. describe(item.title, function () {
  340. var wizardControllerProperties = Em.keys(item.wizardControllerProperties),
  341. stepControllerProperties = Em.keys(item.stepControllerProperties);
  342. beforeEach(function () {
  343. sinon.stub(App.ModalPopup,'show', function (data) {
  344. data.finishLoading.call(c, item.requestId, item.serverError, item.status, item.log);
  345. });
  346. c.showLaunchBootstrapPopup(c.callback);
  347. });
  348. it('wizardControllerProperties are valid', function () {
  349. expect(c.getProperties.apply(c, wizardControllerProperties)).to.eql(item.wizardControllerProperties);
  350. });
  351. it('stepControllerProperties are valid', function () {
  352. expect(stepController.getProperties.apply(stepController, stepControllerProperties)).to.eql(item.stepControllerProperties);
  353. });
  354. it('bootStatus is valid', function () {
  355. expect(stepController.get('hosts').mapProperty('bootStatus').uniq()).to.eql([item.bootStatus]);
  356. });
  357. it('callback is called needed number of times', function () {
  358. expect(c.callback.callCount).to.equal(item.callbackCallCount);
  359. });
  360. it('hide is called needed number of times', function () {
  361. expect(c.hide.callCount).to.equal(item.hideCallCount);
  362. });
  363. });
  364. });
  365. });
  366. });
  367. describe('#gotoStep0', function () {
  368. var res;
  369. beforeEach(function(){
  370. sinon.stub(wizardController,'gotoStep', function(step){
  371. res = step;
  372. });
  373. });
  374. afterEach(function(){
  375. wizardController.gotoStep.restore();
  376. });
  377. it('should go to 0 step', function () {
  378. wizardController.gotoStep0(Em.K);
  379. expect(res).to.be.equal(0);
  380. });
  381. });
  382. describe('#gotoStep1', function () {
  383. var res;
  384. beforeEach(function(){
  385. sinon.stub(wizardController,'gotoStep', function(step){
  386. res = step;
  387. });
  388. });
  389. afterEach(function(){
  390. wizardController.gotoStep.restore();
  391. });
  392. it('should go to 1 step', function () {
  393. wizardController.gotoStep1(Em.K);
  394. expect(res).to.be.equal(1);
  395. });
  396. });
  397. describe('#gotoStep2', function () {
  398. var res;
  399. beforeEach(function(){
  400. sinon.stub(wizardController,'gotoStep', function(step){
  401. res = step;
  402. });
  403. });
  404. afterEach(function(){
  405. wizardController.gotoStep.restore();
  406. });
  407. it('should go to 2 step', function () {
  408. wizardController.gotoStep2(Em.K);
  409. expect(res).to.be.equal(2);
  410. });
  411. });
  412. describe('#gotoSte3', function () {
  413. var res;
  414. beforeEach(function(){
  415. sinon.stub(wizardController,'gotoStep', function(step){
  416. res = step;
  417. });
  418. });
  419. afterEach(function(){
  420. wizardController.gotoStep.restore();
  421. });
  422. it('should go to 3 step', function () {
  423. wizardController.gotoStep3(Em.K);
  424. expect(res).to.be.equal(3);
  425. });
  426. });
  427. describe('#gotoStep4', function () {
  428. var res;
  429. beforeEach(function(){
  430. sinon.stub(wizardController,'gotoStep', function(step){
  431. res = step;
  432. });
  433. });
  434. afterEach(function(){
  435. wizardController.gotoStep.restore();
  436. });
  437. it('should go to 4 step', function () {
  438. wizardController.gotoStep4(Em.K);
  439. expect(res).to.be.equal(4);
  440. });
  441. });
  442. describe('#gotoStep5', function () {
  443. var res;
  444. beforeEach(function(){
  445. sinon.stub(wizardController,'gotoStep', function(step){
  446. res = step;
  447. });
  448. });
  449. afterEach(function(){
  450. wizardController.gotoStep.restore();
  451. });
  452. it('should go to 5 step', function () {
  453. wizardController.gotoStep5(Em.K);
  454. expect(res).to.be.equal(5);
  455. });
  456. });
  457. describe('#gotoStep6', function () {
  458. var res;
  459. beforeEach(function(){
  460. sinon.stub(wizardController,'gotoStep', function(step){
  461. res = step;
  462. });
  463. });
  464. afterEach(function(){
  465. wizardController.gotoStep.restore();
  466. });
  467. it('should go to 6 step', function () {
  468. wizardController.gotoStep6(Em.K);
  469. expect(res).to.be.equal(6);
  470. });
  471. });
  472. describe('#gotoStep7', function () {
  473. var res;
  474. beforeEach(function(){
  475. sinon.stub(wizardController,'gotoStep', function(step){
  476. res = step;
  477. });
  478. });
  479. afterEach(function(){
  480. wizardController.gotoStep.restore();
  481. });
  482. it('should go to 7 step', function () {
  483. wizardController.gotoStep7(Em.K);
  484. expect(res).to.be.equal(7);
  485. });
  486. });
  487. describe('#gotoStep8', function () {
  488. var res;
  489. beforeEach(function(){
  490. sinon.stub(wizardController,'gotoStep', function(step){
  491. res = step;
  492. });
  493. });
  494. afterEach(function(){
  495. wizardController.gotoStep.restore();
  496. });
  497. it('should go to 8 step', function () {
  498. wizardController.gotoStep8(Em.K);
  499. expect(res).to.be.equal(8);
  500. });
  501. });
  502. describe('#gotoStep9', function () {
  503. var res;
  504. beforeEach(function(){
  505. sinon.stub(wizardController,'gotoStep', function(step){
  506. res = step;
  507. });
  508. });
  509. afterEach(function(){
  510. wizardController.gotoStep.restore();
  511. });
  512. it('should go to 9 step', function () {
  513. wizardController.gotoStep9(Em.K);
  514. expect(res).to.be.equal(9);
  515. });
  516. });
  517. describe('#gotoStep10', function () {
  518. var res;
  519. beforeEach(function(){
  520. sinon.stub(wizardController,'gotoStep', function(step){
  521. res = step;
  522. });
  523. });
  524. afterEach(function(){
  525. wizardController.gotoStep.restore();
  526. });
  527. it('should go to 10 step', function () {
  528. wizardController.gotoStep10(Em.K);
  529. expect(res).to.be.equal(10);
  530. });
  531. });
  532. describe('#gotoStep', function () {
  533. beforeEach(function(){
  534. sinon.stub(App.ModalPopup,'show', Em.K);
  535. sinon.stub(App.clusterStatus,'setClusterStatus', Em.K);
  536. sinon.stub(App.router,'send', Em.K);
  537. });
  538. afterEach(function(){
  539. App.ModalPopup.show.restore();
  540. App.clusterStatus.setClusterStatus.restore();
  541. App.router.send.restore();
  542. });
  543. it('should go to step', function () {
  544. wizardController.set('isStepDisabled', Em.A([
  545. Em.Object.create({
  546. step: '8',
  547. value: false
  548. })
  549. ]));
  550. wizardController.hide = Em.K;
  551. wizardController.set('content.controllerName','installerController');
  552. wizardController.set('currentStep','9');
  553. expect(wizardController.gotoStep('8')).to.be.true;
  554. });
  555. });
  556. describe('#launchBootstrap', function () {
  557. beforeEach(function(){
  558. sinon.stub(wizardController,'showLaunchBootstrapPopup').returns({
  559. name: 'popup'
  560. });
  561. });
  562. afterEach(function(){
  563. wizardController.showLaunchBootstrapPopup.restore();
  564. });
  565. it('should return popup', function () {
  566. expect(wizardController.launchBootstrap()).to.be.eql({
  567. name: 'popup'
  568. });
  569. });
  570. });
  571. describe('#save', function () {
  572. var res;
  573. beforeEach(function () {
  574. sinon.stub(wizardController,'setDBProperty', function(data){
  575. res = data;
  576. });
  577. sinon.stub(wizardController,'toJSInstance').returns('val');
  578. });
  579. afterEach(function () {
  580. wizardController.setDBProperty.restore();
  581. wizardController.toJSInstance.restore();
  582. });
  583. it('should save data', function () {
  584. wizardController.save('name');
  585. expect(res).to.be.equal('name');
  586. });
  587. });
  588. describe('#installServicesSuccessCallback', function () {
  589. var res;
  590. beforeEach(function(){
  591. sinon.stub(wizardController,'saveClusterStatus', function(data){
  592. res = JSON.parse(JSON.stringify(data));
  593. });
  594. sinon.stub(App,'dateTime').returns('22');
  595. });
  596. afterEach(function(){
  597. wizardController.saveClusterStatus.restore();
  598. App.dateTime.restore();
  599. });
  600. it('should call callbeck with data', function () {
  601. var jsonData = {
  602. Requests: {
  603. id: 1
  604. }
  605. };
  606. wizardController.installServicesSuccessCallback(jsonData);
  607. expect(res).to.be.eql({
  608. "status": "PENDING",
  609. "requestId": 1,
  610. "isInstallError": false,
  611. "isCompleted": false,
  612. "installStartTime": "22"
  613. });
  614. });
  615. });
  616. describe('#installServices', function () {
  617. var res;
  618. beforeEach(function(){
  619. sinon.stub(wizardController,'saveClusterStatus', function(data){
  620. res = JSON.parse(JSON.stringify(data));
  621. });
  622. });
  623. afterEach(function(){
  624. wizardController.saveClusterStatus.restore();
  625. });
  626. it('should call callbeck with data', function () {
  627. wizardController.set('content', Em.Object.create({
  628. cluster: {
  629. oldRequestsId: '1'
  630. }
  631. }));
  632. wizardController.installServices(true);
  633. expect(res).to.be.eql({
  634. "status": "PENDING"
  635. });
  636. });
  637. });
  638. describe('#saveInstalledHosts', function () {
  639. beforeEach(function(){
  640. sinon.stub(wizardController,'getDBProperty').returns({
  641. 'h1': {
  642. id: 1,
  643. status: '',
  644. name: 'h1'
  645. }
  646. });
  647. });
  648. afterEach(function(){
  649. wizardController.getDBProperty.restore();
  650. });
  651. it('should save installed hosts', function () {
  652. var stepController = Em.Object.create({
  653. hosts: Em.A([
  654. Em.Object.create({
  655. hostName: 'h1',
  656. name: 'h1',
  657. status: 'st',
  658. message: 'ms',
  659. checkboxes: Em.A([
  660. Em.Object.create({title: 'hl1', checked: true})
  661. ])
  662. })
  663. ])
  664. });
  665. wizardController.saveInstalledHosts(stepController);
  666. var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
  667. expect(res).to.eql({
  668. "h1": {
  669. "id": 1,
  670. "status": "st",
  671. "name": "h1",
  672. "message": "ms"
  673. }
  674. });
  675. });
  676. });
  677. describe('#saveConfirmedHosts', function () {
  678. beforeEach(function(){
  679. sinon.stub(wizardController,'getDBProperty').returns({
  680. 'h1': {
  681. id: 1,
  682. status: '',
  683. name: 'h1'
  684. }
  685. });
  686. });
  687. afterEach(function(){
  688. wizardController.getDBProperty.restore();
  689. });
  690. it('should save confirmed hosts', function () {
  691. var stepController = Em.Object.create({
  692. confirmedHosts: Em.A([
  693. {
  694. name: 'h2',
  695. cpu: '1',
  696. isInstalled: true
  697. }
  698. ])
  699. });
  700. wizardController.set('content.hosts', {
  701. 'h1': {
  702. isInstalled: false,
  703. bootStatus: 'REGISTERED'
  704. },
  705. 'h2': {
  706. isInstalled: true,
  707. bootStatus: 'REGISTERED'
  708. }
  709. });
  710. wizardController.saveConfirmedHosts(stepController);
  711. var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
  712. expect(res).to.eql({
  713. "h2": {
  714. "isInstalled": true,
  715. "bootStatus": "REGISTERED"
  716. }
  717. });
  718. });
  719. });
  720. describe('#loadTasksStatuses', function () {
  721. beforeEach(function () {
  722. sinon.stub(wizardController, 'getDBProperty').returns('st');
  723. });
  724. afterEach(function () {
  725. wizardController.getDBProperty.restore();
  726. });
  727. it('should load status', function () {
  728. wizardController.loadTasksStatuses();
  729. expect(wizardController.get('content.tasksStatuses')).to.equal('st');
  730. });
  731. });
  732. describe('#saveTasksRequestIds', function () {
  733. it('should save id', function () {
  734. wizardController.saveTasksRequestIds('st');
  735. expect(wizardController.get('content.tasksRequestIds')).to.equal('st');
  736. });
  737. });
  738. describe('#loadTasksRequestIds', function () {
  739. beforeEach(function () {
  740. sinon.stub(wizardController, 'getDBProperty').returns('st');
  741. });
  742. afterEach(function () {
  743. wizardController.getDBProperty.restore();
  744. });
  745. it('should load status', function () {
  746. wizardController.loadTasksRequestIds();
  747. expect(wizardController.get('content.tasksRequestIds')).to.equal('st');
  748. });
  749. });
  750. describe('#saveRequestIds', function () {
  751. it('should save id', function () {
  752. wizardController.saveRequestIds('st');
  753. expect(wizardController.get('content.requestIds')).to.equal('st');
  754. });
  755. });
  756. describe('#load', function () {
  757. it('should clear install options', function () {
  758. var name = 'Name';
  759. wizardController.set('get'+name.capitalize(), function() {return 'res';});
  760. wizardController.load(name, true);
  761. expect(wizardController.get('content.' + name)).to.equal('res');
  762. });
  763. });
  764. describe('#usersLoading', function () {
  765. beforeEach(function(){
  766. sinon.stub(App.MainAdminServiceAccountsController,'create').returns({
  767. loadUsers: function() {},
  768. get: function(type) {
  769. if (type === 'dataIsLoaded') {
  770. return true;
  771. }
  772. return Em.Object.create({
  773. hdfsUser: {
  774. name: 'user'
  775. }
  776. });
  777. }
  778. });
  779. });
  780. afterEach(function(){
  781. App.MainAdminServiceAccountsController.create.restore();
  782. });
  783. it('should load users', function () {
  784. wizardController.set('content.hdfsUser', true);
  785. wizardController.usersLoading().then(function(data){
  786. expect(data).to.be.undefined;
  787. });
  788. });
  789. });
  790. describe('#loadConfirmedHosts', function () {
  791. beforeEach(function(){
  792. sinon.stub(App.db, 'getHosts').returns(Em.A([
  793. Em.Object.create({
  794. name: 'h1'
  795. })
  796. ]));
  797. });
  798. afterEach(function(){
  799. App.db.getHosts.restore();
  800. });
  801. it('should load hosts from db', function () {
  802. wizardController.loadConfirmedHosts();
  803. var res = JSON.parse(JSON.stringify(wizardController.get('content.hosts')));
  804. expect(res).to.eql([
  805. {
  806. "name": "h1"
  807. }
  808. ]);
  809. });
  810. });
  811. describe('#loadServicesFromServer', function () {//TODO
  812. var res;
  813. beforeEach(function(){
  814. sinon.stub(App.StackService, 'find').returns(Em.A([
  815. Em.Object.create({
  816. isSelected: false,
  817. isInstalled: false,
  818. serviceName: 's1'
  819. })
  820. ]));
  821. sinon.stub(App.Service, 'find').returns(Em.A([
  822. Em.Object.create({
  823. isSelected: false,
  824. isInstalled: false,
  825. serviceName: 's1'
  826. })
  827. ]));
  828. sinon.stub(wizardController, 'setDBProperty', function(data) {
  829. res = data;
  830. });
  831. });
  832. afterEach(function () {
  833. App.StackService.find.restore();
  834. App.Service.find.restore();
  835. wizardController.setDBProperty.restore();
  836. });
  837. it('should load services from server', function () {
  838. wizardController.loadServicesFromServer();
  839. expect(res).to.be.equal('services');
  840. });
  841. });
  842. describe('#loadRequestIds', function () {
  843. beforeEach(function () {
  844. sinon.stub(wizardController, 'getDBProperty').returns('st');
  845. });
  846. afterEach(function () {
  847. wizardController.getDBProperty.restore();
  848. });
  849. it('should load status', function () {
  850. wizardController.loadRequestIds();
  851. expect(wizardController.get('content.requestIds')).to.equal('st');
  852. });
  853. });
  854. describe('#loadServiceComponentsSuccessCallback', function () {
  855. beforeEach(function () {
  856. sinon.stub(wizardController, 'getDBProperties', function() {
  857. return {
  858. selectedServiceNames: ['a','b'],
  859. installedServiceNames: ['c','d']
  860. };
  861. });
  862. sinon.stub(App.stackServiceMapper, 'mapStackServices', Em.K);
  863. });
  864. afterEach(function () {
  865. wizardController.getDBProperties.restore();
  866. App.stackServiceMapper.mapStackServices.restore();
  867. });
  868. it('should load json data', function () {
  869. var jsonData = {
  870. items: [
  871. {
  872. StackServices: {
  873. isSelected: false,
  874. service_name: 'a'
  875. }
  876. },
  877. {
  878. StackServices: {
  879. isSelected: false,
  880. service_name: 'none'
  881. }
  882. }
  883. ]
  884. };
  885. wizardController.loadServiceComponentsSuccessCallback(jsonData);
  886. var exp = {
  887. "items": [
  888. {
  889. "StackServices": {
  890. "isSelected": false,
  891. "service_name": "a",
  892. "is_selected": true,
  893. "is_installed": false
  894. }
  895. },
  896. {
  897. "StackServices": {
  898. "isSelected": false,
  899. "service_name": "none",
  900. "is_selected": false,
  901. "is_installed": false
  902. }
  903. }
  904. ]
  905. };
  906. expect(jsonData).to.eql(exp);
  907. });
  908. });
  909. describe('#setInfoForStep9', function () {
  910. var res;
  911. beforeEach(function () {
  912. sinon.stub(wizardController, 'getDBProperty').returns(Em.Object.create({
  913. status: {},
  914. message: {},
  915. logTasks: {},
  916. tasks: {},
  917. progress: {}
  918. }));
  919. sinon.stub(wizardController, 'setDBProperty', function(title,data) {
  920. res = data;
  921. });
  922. });
  923. afterEach(function () {
  924. wizardController.getDBProperty.restore();
  925. wizardController.setDBProperty.restore();
  926. });
  927. it('should return info for step 9', function () {
  928. wizardController.setInfoForStep9();
  929. var exp = {
  930. "status": {
  931. "status": "pending",
  932. "message": "Waiting",
  933. "logTasks": [],
  934. "tasks": [],
  935. "progress": "0"
  936. },
  937. "message": {
  938. "status": "pending",
  939. "message": "Waiting",
  940. "logTasks": [],
  941. "tasks": [],
  942. "progress": "0"
  943. },
  944. "logTasks": {
  945. "status": "pending",
  946. "message": "Waiting",
  947. "logTasks": [],
  948. "tasks": [],
  949. "progress": "0"
  950. },
  951. "tasks": {
  952. "status": "pending",
  953. "message": "Waiting",
  954. "logTasks": [],
  955. "tasks": [],
  956. "progress": "0"
  957. },
  958. "progress": {
  959. "status": "pending",
  960. "message": "Waiting",
  961. "logTasks": [],
  962. "tasks": [],
  963. "progress": "0"
  964. }
  965. };
  966. res = JSON.parse(JSON.stringify(res));
  967. expect(res).to.eql(exp);
  968. });
  969. });
  970. describe('#saveServiceConfigProperties', function () {
  971. beforeEach(function () {
  972. c.set('content', {});
  973. sinon.stub(c, 'setDBProperties', Em.K);
  974. sinon.stub(c, 'getDBProperty').withArgs('fileNamesToUpdate').returns([]);
  975. sinon.stub(App.config, 'shouldSupportFinal').returns(true);
  976. });
  977. afterEach(function () {
  978. c.setDBProperties.restore();
  979. c.getDBProperty.restore();
  980. App.config.shouldSupportFinal.restore();
  981. });
  982. var kerberosStepController = Em.Object.create({
  983. installedServiceNames: ['KERBEROS'],
  984. stepConfigs: [
  985. Em.Object.create({
  986. serviceName: 'KERBEROS',
  987. configs: [
  988. Em.Object.create({
  989. id: 'id',
  990. name: 'admin_password',
  991. value: 'value',
  992. defaultValue: 'defaultValue',
  993. description: 'description',
  994. serviceName: 'serviceName',
  995. domain: 'domain',
  996. isVisible: true,
  997. isNotDefaultValue: true,
  998. isFinal: true,
  999. defaultIsFinal: true,
  1000. supportsFinal: true,
  1001. filename: 'krb5-conf.xml',
  1002. displayType: 'string',
  1003. isRequiredByAgent: true,
  1004. hasInitialValue: true,
  1005. isRequired: true,
  1006. group: {name: 'group'},
  1007. showLabel: true,
  1008. category: 'some_category'
  1009. }),
  1010. Em.Object.create({
  1011. id: 'id',
  1012. name: 'admin_principal',
  1013. value: 'value',
  1014. defaultValue: 'defaultValue',
  1015. description: 'description',
  1016. serviceName: 'serviceName',
  1017. domain: 'domain',
  1018. isVisible: true,
  1019. isNotDefaultValue: true,
  1020. isFinal: true,
  1021. defaultIsFinal: true,
  1022. supportsFinal: true,
  1023. filename: 'krb5-conf.xml',
  1024. displayType: 'string',
  1025. isRequiredByAgent: true,
  1026. hasInitialValue: true,
  1027. isRequired: true,
  1028. group: {name: 'group'},
  1029. showLabel: true,
  1030. category: 'some_category'
  1031. })
  1032. ]
  1033. })
  1034. ]
  1035. });
  1036. var stepController = Em.Object.create({
  1037. installedServiceNames: ['HDFS'],
  1038. stepConfigs: [
  1039. Em.Object.create({
  1040. serviceName: 'HDFS',
  1041. configs: [
  1042. Em.Object.create({
  1043. id: 'id',
  1044. name: 'name',
  1045. value: 'value',
  1046. defaultValue: 'defaultValue',
  1047. description: 'description',
  1048. serviceName: 'serviceName',
  1049. domain: 'domain',
  1050. isVisible: true,
  1051. isNotDefaultValue: true,
  1052. isFinal: true,
  1053. defaultIsFinal: true,
  1054. supportsFinal: true,
  1055. filename: 'filename',
  1056. displayType: 'string',
  1057. isRequiredByAgent: true,
  1058. hasInitialValue: true,
  1059. isRequired: true,
  1060. showLabel: true,
  1061. category: 'some_category'
  1062. })
  1063. ]
  1064. }),
  1065. Em.Object.create({
  1066. serviceName: 'YARN',
  1067. configs: [
  1068. Em.Object.create({
  1069. id: 'id',
  1070. name: 'name',
  1071. value: 'value',
  1072. defaultValue: 'defaultValue',
  1073. description: 'description',
  1074. serviceName: 'serviceName',
  1075. domain: 'domain',
  1076. isVisible: true,
  1077. isFinal: true,
  1078. defaultIsFinal: true,
  1079. supportsFinal: true,
  1080. filename: 'filename',
  1081. displayType: 'string',
  1082. isRequiredByAgent: true,
  1083. hasInitialValue: true,
  1084. isRequired: true,
  1085. group: {name: 'group'},
  1086. showLabel: true,
  1087. category: 'some_category'
  1088. })
  1089. ]
  1090. })
  1091. ]});
  1092. it('should save configs from default config group to content.serviceConfigProperties', function () {
  1093. c.saveServiceConfigProperties(stepController);
  1094. var saved = c.get('content.serviceConfigProperties');
  1095. expect(saved.length).to.equal(1);
  1096. expect(saved[0].category).to.equal('some_category');
  1097. });
  1098. it('should not save admin_principal or admin_password to the localStorage', function () {
  1099. c.saveServiceConfigProperties(kerberosStepController);
  1100. var saved = c.get('content.serviceConfigProperties');
  1101. expect(saved.everyProperty('value', '')).to.be.true;
  1102. });
  1103. });
  1104. describe('#enableStep', function () {
  1105. beforeEach(function () {
  1106. c.set('isStepDisabled', [
  1107. Em.Object.create({step: 1, value: true}),
  1108. Em.Object.create({step: 2, value: true}),
  1109. Em.Object.create({step: 3, value: true}),
  1110. Em.Object.create({step: 4, value: true}),
  1111. Em.Object.create({step: 5, value: true}),
  1112. Em.Object.create({step: 6, value: true}),
  1113. Em.Object.create({step: 7, value: true})
  1114. ]);
  1115. });
  1116. it('should update 1st value in isStepDisabled', function () {
  1117. c.enableStep(1);
  1118. expect(c.get('isStepDisabled')[0].get('value')).to.be.false;
  1119. });
  1120. it('should update 6th value in isStepDisabled', function () {
  1121. c.enableStep(7);
  1122. expect(c.get('isStepDisabled')[6].get('value')).to.be.false;
  1123. });
  1124. });
  1125. describe('#allHosts', function () {
  1126. it('should return all hosts', function () {
  1127. var hosts = {
  1128. 'h1': {hostComponents: ['c1', 'c2'], disk_info: [{size: 2, available: 1}]},
  1129. 'h2': {hostComponents: ['c3', 'c4'], disk_info: [{size: 2, available: 1}]}
  1130. };
  1131. var content = Em.Object.create({
  1132. hosts: hosts
  1133. });
  1134. c.set('content', content);
  1135. var exp = [
  1136. {
  1137. "id": "h1",
  1138. "hostName": "h1",
  1139. "publicHostName": "h1",
  1140. "diskInfo": [
  1141. {
  1142. "size": 2,
  1143. "available": 1
  1144. }
  1145. ],
  1146. "diskTotal": 0.0000019073486328125,
  1147. "diskFree": 9.5367431640625e-7,
  1148. "disksMounted": 1,
  1149. "osType": 0,
  1150. "osArch": 0,
  1151. "ip": 0,
  1152. "hostComponents": [
  1153. {
  1154. "componentName": "c1",
  1155. "displayName": "C1"
  1156. },
  1157. {
  1158. "componentName": "c2",
  1159. "displayName": "C2"
  1160. }
  1161. ]
  1162. },
  1163. {
  1164. "id": "h2",
  1165. "hostName": "h2",
  1166. "publicHostName": "h2",
  1167. "diskInfo": [
  1168. {
  1169. "size": 2,
  1170. "available": 1
  1171. }
  1172. ],
  1173. "diskTotal": 0.0000019073486328125,
  1174. "diskFree": 9.5367431640625e-7,
  1175. "disksMounted": 1,
  1176. "osType": 0,
  1177. "osArch": 0,
  1178. "ip": 0,
  1179. "hostComponents": [
  1180. {
  1181. "componentName": "c3",
  1182. "displayName": "C3"
  1183. },
  1184. {
  1185. "componentName": "c4",
  1186. "displayName": "C4"
  1187. }
  1188. ]
  1189. }
  1190. ];
  1191. var res = JSON.parse(JSON.stringify(c.get('allHosts')));
  1192. expect(res).to.be.eql(exp);
  1193. });
  1194. });
  1195. describe('#getSlaveComponentHosts', function () {
  1196. beforeEach(function () {
  1197. sinon.stub(App.Service, 'find').returns(Em.A([
  1198. Em.Object.create({
  1199. serviceName: 's1'
  1200. })
  1201. ]));
  1202. sinon.stub(App.StackService, 'find').returns(Em.A([
  1203. Em.Object.create({
  1204. serviceName: 's2',
  1205. isSelected: true
  1206. })
  1207. ]));
  1208. sinon.stub(App.StackServiceComponent, 'find').returns(Em.A([
  1209. Em.Object.create({componentName: 'DATANODE', serviceName: 's1', isSlave: true}),
  1210. Em.Object.create({componentName: 'c2', serviceName: 's2', isSlave: true})
  1211. ]));
  1212. sinon.stub(App.HostComponent, 'find').returns(Em.A([
  1213. Em.Object.create({
  1214. componentName: 'DATANODE',
  1215. hostName: 'h1'
  1216. })
  1217. ]));
  1218. });
  1219. afterEach(function () {
  1220. App.Service.find.restore();
  1221. App.HostComponent.find.restore();
  1222. App.StackService.find.restore();
  1223. App.StackServiceComponent.find.restore();
  1224. });
  1225. it('should return slave components', function () {
  1226. var res = JSON.parse(JSON.stringify(c.getSlaveComponentHosts()));
  1227. var exp = [
  1228. {
  1229. "componentName": "DATANODE",
  1230. "displayName": "DataNode",
  1231. "hosts": [
  1232. {
  1233. "group": "Default",
  1234. "hostName": "h1",
  1235. "isInstalled": true
  1236. }
  1237. ],
  1238. "isInstalled": true
  1239. },
  1240. {
  1241. "componentName": "CLIENT",
  1242. "displayName": "Client",
  1243. "hosts": [],
  1244. "isInstalled": true
  1245. },
  1246. {
  1247. "componentName": "c2",
  1248. "displayName": "C2",
  1249. "hosts": [
  1250. {
  1251. "group": "Default",
  1252. "hostName": "h1",
  1253. "isInstalled": false
  1254. }
  1255. ],
  1256. "isInstalled": false
  1257. }
  1258. ];
  1259. expect(res).to.be.eql(exp);
  1260. });
  1261. });
  1262. describe('#setSkipSlavesStep', function () {
  1263. var step = 6,
  1264. cases = [
  1265. {
  1266. services: [
  1267. {
  1268. hasSlave: true,
  1269. hasNonMastersWithCustomAssignment: true
  1270. }
  1271. ],
  1272. skipSlavesStep: false,
  1273. title: 'service with customizable slave selected'
  1274. },
  1275. {
  1276. services: [
  1277. {
  1278. hasClient: true,
  1279. hasNonMastersWithCustomAssignment: true
  1280. }
  1281. ],
  1282. skipSlavesStep: false,
  1283. title: 'service with customizable client selected'
  1284. },
  1285. {
  1286. services: [
  1287. {
  1288. hasSlave: true,
  1289. hasNonMastersWithCustomAssignment: false
  1290. },
  1291. {
  1292. hasClient: true,
  1293. hasNonMastersWithCustomAssignment: false
  1294. }
  1295. ],
  1296. skipSlavesStep: true,
  1297. title: 'no service with customizable slaves or clients selected'
  1298. },
  1299. {
  1300. services: [
  1301. {
  1302. hasSlave: false,
  1303. hasClient: false
  1304. }
  1305. ],
  1306. skipSlavesStep: true,
  1307. title: 'no service with slaves or clients selected'
  1308. }
  1309. ];
  1310. beforeEach(function () {
  1311. c.reopen({
  1312. isStepDisabled: [
  1313. Em.Object.create({
  1314. step: 6
  1315. })
  1316. ],
  1317. content: {}
  1318. });
  1319. });
  1320. cases.forEach(function (item) {
  1321. it(item.title, function () {
  1322. c.setSkipSlavesStep(item.services, step);
  1323. expect(Boolean(c.get('isStepDisabled').findProperty('step', step).get('value'))).to.equal(item.skipSlavesStep);
  1324. });
  1325. });
  1326. });
  1327. describe('#toJSInstance', function () {
  1328. var testCases = [
  1329. {
  1330. o: {'test': 'test'},
  1331. e: {'test': 'test'}
  1332. },
  1333. {
  1334. o: {'test': Em.Object.create()},
  1335. e: {'test': {}}
  1336. },
  1337. {
  1338. o: {'test': Em.Object.create({'test': {}})},
  1339. e: {'test': {'test': {}}}
  1340. },
  1341. {
  1342. o: [],
  1343. e: []
  1344. },
  1345. {
  1346. o: Em.A([[]]),
  1347. e: [[]]
  1348. },
  1349. {
  1350. o: 11,
  1351. e: 11
  1352. },
  1353. {
  1354. o: '11',
  1355. e: '11'
  1356. },
  1357. {
  1358. o: null,
  1359. e: null
  1360. }
  1361. ];
  1362. testCases.forEach(function (testCase, index) {
  1363. it('should convert objects and arrays to pure JS objects and arrays (' + (index + 1) + ')', function () {
  1364. expect(c.toJSInstance(testCase.o)).to.eql(testCase.e);
  1365. });
  1366. });
  1367. });
  1368. describe('#loadConfigThemes', function() {
  1369. beforeEach(function () {
  1370. sinon.stub(wizardController, 'loadConfigThemeForServices').returns({
  1371. always: Em.clb
  1372. });
  1373. sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(true);
  1374. sinon.stub(App.config, 'loadConfigsFromStack').returns({
  1375. done: Em.clb
  1376. });
  1377. sinon.stub(App.StackService, 'find').returns(Em.A([
  1378. Em.Object.create({
  1379. isSelected: true,
  1380. serviceName: 's1'
  1381. })
  1382. ]));
  1383. this.stub = sinon.stub(App, 'get');
  1384. });
  1385. afterEach(function () {
  1386. App.get.restore();
  1387. App.StackService.find.restore();
  1388. App.config.loadConfigsFromStack.restore();
  1389. App.themesMapper.generateAdvancedTabs.restore();
  1390. wizardController.loadConfigThemeForServices.restore();
  1391. });
  1392. it('Should load config themes', function(done) {
  1393. this.stub.returns(true);
  1394. wizardController.loadConfigThemes().then(function() {
  1395. done();
  1396. });
  1397. });
  1398. it('Should load config themes (2)', function(done) {
  1399. this.stub.returns(false);
  1400. wizardController.loadConfigThemes().then(function() {
  1401. done();
  1402. });
  1403. });
  1404. });
  1405. describe('#dataLoading', function () {
  1406. var clusterController = Em.Object.create({
  1407. isLoaded: false
  1408. });
  1409. beforeEach(function(){
  1410. sinon.stub(App.router,'get').returns(clusterController);
  1411. sinon.stub(wizardController, 'connectOutlet', Em.K);
  1412. clusterController.set('isLoaded', false);
  1413. });
  1414. afterEach(function(){
  1415. App.router.get.restore();
  1416. wizardController.connectOutlet.restore();
  1417. });
  1418. it('should load data', function () {
  1419. clusterController.set('isLoaded', true);
  1420. wizardController.dataLoading().then(function(data){
  1421. expect(data).to.be.undefined;
  1422. });
  1423. });
  1424. it('should load data after 25ms', function () {
  1425. clusterController.set('isLoaded', false);
  1426. setTimeout(function(){
  1427. clusterController.set('isLoaded', true);
  1428. },25);
  1429. wizardController.dataLoading().then(function(data){
  1430. expect(data).to.be.undefined;
  1431. });
  1432. });
  1433. });
  1434. describe('#saveMasterComponentHosts', function () {
  1435. var stepController = Em.Object.create({
  1436. selectedServicesMasters: [
  1437. Em.Object.create({
  1438. display_name: 'd0',
  1439. component_name: 'c0',
  1440. selectedHost: 'h0',
  1441. serviceId: 's0',
  1442. isInstalled: true
  1443. }),
  1444. Em.Object.create({
  1445. display_name: 'd1',
  1446. component_name: 'c1',
  1447. selectedHost: 'h1',
  1448. serviceId: 's1',
  1449. isInstalled: false
  1450. })
  1451. ]
  1452. }),
  1453. masterComponentHosts = [
  1454. {
  1455. display_name: 'd0',
  1456. component: 'c0',
  1457. hostName: 'h0',
  1458. serviceId: 's0',
  1459. isInstalled: true
  1460. },
  1461. {
  1462. display_name: 'd1',
  1463. component: 'c1',
  1464. hostName: 'h1',
  1465. serviceId: 's1',
  1466. isInstalled: false
  1467. }
  1468. ];
  1469. beforeEach(function () {
  1470. sinon.stub(wizardController, 'setDBProperty', Em.K);
  1471. });
  1472. afterEach(function () {
  1473. wizardController.setDBProperty.restore();
  1474. });
  1475. it('should save master component hosts', function () {
  1476. wizardController.saveMasterComponentHosts(stepController);
  1477. expect(wizardController.setDBProperty.calledOnce).to.be.true;
  1478. expect(wizardController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
  1479. expect(wizardController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
  1480. });
  1481. });
  1482. describe('#clearMasterComponentHosts', function () {
  1483. beforeEach(function () {
  1484. sinon.stub(wizardController, 'setDBProperty', Em.K);
  1485. });
  1486. afterEach(function () {
  1487. wizardController.setDBProperty.restore();
  1488. });
  1489. it('should clear master component hosts', function () {
  1490. wizardController.set('content.masterComponentHosts', {});
  1491. wizardController.clearMasterComponentHosts();
  1492. expect(wizardController.setDBProperty.calledOnce).to.be.true;
  1493. expect(wizardController.setDBProperty.calledWith('masterComponentHosts', null)).to.be.true;
  1494. expect(wizardController.get('content.masterComponentHosts')).to.be.null;
  1495. });
  1496. });
  1497. describe('#loadRecommendations', function () {
  1498. beforeEach(function () {
  1499. sinon.stub(c, 'getDBProperty').returns({});
  1500. });
  1501. afterEach(function () {
  1502. c.getDBProperty.restore();
  1503. });
  1504. it('should set recommendations', function () {
  1505. c.set('content', {});
  1506. c.loadRecommendations();
  1507. expect(c.get('content.recommendations')).to.eql({});
  1508. });
  1509. });
  1510. describe("#resetOnClose()", function () {
  1511. var ctrl = Em.Object.create({
  1512. finish: Em.K,
  1513. popup: {
  1514. hide: Em.K
  1515. }
  1516. });
  1517. var mock = Em.Object.create({
  1518. resetUser: Em.K
  1519. });
  1520. beforeEach(function () {
  1521. sinon.stub(ctrl, 'finish');
  1522. sinon.stub(ctrl.popup, 'hide');
  1523. sinon.stub(App.router, 'get').returns(mock);
  1524. sinon.stub(App.clusterStatus, 'setClusterStatus', function (arg1, arg2) {
  1525. arg2.alwaysCallback();
  1526. });
  1527. sinon.stub(Em.run, 'next');
  1528. sinon.stub(mock, 'resetUser');
  1529. sinon.stub(App.router, 'transitionTo');
  1530. c.resetOnClose(ctrl, 'path');
  1531. });
  1532. afterEach(function () {
  1533. ctrl.finish.restore();
  1534. ctrl.popup.hide.restore();
  1535. App.router.get.restore();
  1536. App.clusterStatus.setClusterStatus.restore();
  1537. Em.run.next.restore();
  1538. mock.resetUser.restore();
  1539. App.router.transitionTo.restore();
  1540. });
  1541. it("resetUser should be called", function () {
  1542. expect(mock.resetUser.calledOnce).to.be.true;
  1543. });
  1544. it("finish should be called", function () {
  1545. expect(ctrl.finish.calledOnce).to.be.true;
  1546. });
  1547. it("isWorking should be true", function () {
  1548. expect(mock.get('isWorking')).to.be.true;
  1549. });
  1550. it("App.clusterStatus.setClusterStatus should be called", function () {
  1551. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1552. });
  1553. it("popup should be hidden", function () {
  1554. expect(ctrl.get('popup').hide.calledOnce).to.be.true;
  1555. });
  1556. it("App.router.transitionTo should be called", function () {
  1557. expect(App.router.transitionTo.calledOnce).to.be.true;
  1558. });
  1559. it("Em.run.next should be called", function () {
  1560. expect(Em.run.next.calledOnce).to.be.true;
  1561. });
  1562. });
  1563. });