hosts_test.js 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467
  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 hostsUtils = require('utils/hosts');
  20. var validator = require('utils/validator');
  21. var testHelpers = require('test/helpers');
  22. describe('hosts utils', function () {
  23. describe('#launchHostsSelectionDialog', function () {
  24. var popup,
  25. mock = {
  26. callback: Em.K
  27. };
  28. beforeEach(function () {
  29. sinon.stub(App.ModalPopup, 'show', Em.K);
  30. });
  31. afterEach(function () {
  32. App.ModalPopup.show.restore();
  33. });
  34. describe('popup header and message', function () {
  35. var cases = [
  36. {
  37. popupDescription: {},
  38. header: Em.I18n.t('hosts.selectHostsDialog.title'),
  39. dialogMessage: Em.I18n.t('hosts.selectHostsDialog.message'),
  40. title: 'default header and message'
  41. },
  42. {
  43. popupDescription: {
  44. dialogMessage: 'Message 0'
  45. },
  46. header: Em.I18n.t('hosts.selectHostsDialog.title'),
  47. dialogMessage: 'Message 0',
  48. title: 'default header, custom message'
  49. },
  50. {
  51. popupDescription: {
  52. header: 'Header 0'
  53. },
  54. header: 'Header 0',
  55. dialogMessage: Em.I18n.t('hosts.selectHostsDialog.message'),
  56. title: 'custom header, default message'
  57. },
  58. {
  59. popupDescription: {
  60. header: 'Header 1',
  61. dialogMessage: 'Message 1'
  62. },
  63. header: 'Header 1',
  64. dialogMessage: 'Message 1',
  65. title: 'custom header and message'
  66. }
  67. ];
  68. cases.forEach(function (item) {
  69. describe(item.title, function () {
  70. beforeEach(function () {
  71. hostsUtils.launchHostsSelectionDialog(null, null, null, null, null, item.popupDescription);
  72. popup = Em.Object.create(App.ModalPopup.show.firstCall.args[0]);
  73. });
  74. it('header', function () {
  75. expect(popup.get('header')).to.equal(item.header);
  76. });
  77. it('message', function () {
  78. expect(popup.get('dialogMessage')).to.equal(item.dialogMessage);
  79. });
  80. });
  81. });
  82. });
  83. describe('#onPrimary', function () {
  84. var cases = [
  85. {
  86. selectAtleastOneHost: true,
  87. availableHosts: [],
  88. warningMessage: Em.I18n.t('hosts.selectHostsDialog.message.warning'),
  89. callbackCallCount: 0,
  90. hideCallCount: 0,
  91. title: 'no hosts available'
  92. },
  93. {
  94. selectAtleastOneHost: false,
  95. availableHosts: [],
  96. warningMessage: null,
  97. callbackCallCount: 1,
  98. arrayOfSelectedHosts: [],
  99. hideCallCount: 1,
  100. title: 'no hosts available, no selection requirement'
  101. },
  102. {
  103. selectAtleastOneHost: true,
  104. availableHosts: [
  105. {},
  106. {
  107. selected: 1
  108. },
  109. {
  110. selected: 'true'
  111. }
  112. ],
  113. warningMessage: Em.I18n.t('hosts.selectHostsDialog.message.warning'),
  114. callbackCallCount: 0,
  115. hideCallCount: 0,
  116. title: 'no selection state info'
  117. },
  118. {
  119. selectAtleastOneHost: false,
  120. availableHosts: [
  121. {},
  122. {
  123. selected: 1
  124. },
  125. {
  126. selected: 'true'
  127. }
  128. ],
  129. warningMessage: null,
  130. callbackCallCount: 1,
  131. arrayOfSelectedHosts: [],
  132. hideCallCount: 1,
  133. title: 'no selection state info, no selection requirement'
  134. },
  135. {
  136. selectAtleastOneHost: true,
  137. availableHosts: [
  138. {
  139. selected: false
  140. },
  141. {
  142. selected: false
  143. },
  144. {},
  145. {
  146. selected: 1
  147. },
  148. {
  149. selected: 'true'
  150. }
  151. ],
  152. warningMessage: Em.I18n.t('hosts.selectHostsDialog.message.warning'),
  153. callbackCallCount: 0,
  154. hideCallCount: 0,
  155. title: 'no hosts selected'
  156. },
  157. {
  158. selectAtleastOneHost: false,
  159. availableHosts: [
  160. {
  161. selected: false
  162. },
  163. {
  164. selected: false
  165. },
  166. {},
  167. {
  168. selected: 1
  169. },
  170. {
  171. selected: 'true'
  172. }
  173. ],
  174. warningMessage: null,
  175. callbackCallCount: 1,
  176. arrayOfSelectedHosts: [],
  177. hideCallCount: 1,
  178. title: 'no hosts selected, no selection requirement'
  179. },
  180. {
  181. selectAtleastOneHost: true,
  182. availableHosts: [
  183. {
  184. selected: true
  185. },
  186. {
  187. selected: false
  188. },
  189. {},
  190. {
  191. selected: 1
  192. },
  193. {
  194. selected: 'true'
  195. }
  196. ],
  197. warningMessage: null,
  198. callbackCallCount: 1,
  199. arrayOfSelectedHosts: [undefined],
  200. hideCallCount: 1,
  201. title: '1 host selected, no host info'
  202. },
  203. {
  204. selectAtleastOneHost: false,
  205. availableHosts: [
  206. {
  207. selected: true
  208. },
  209. {
  210. selected: false
  211. },
  212. {},
  213. {
  214. selected: 1
  215. },
  216. {
  217. selected: 'true'
  218. }
  219. ],
  220. warningMessage: null,
  221. callbackCallCount: 1,
  222. arrayOfSelectedHosts: [undefined],
  223. hideCallCount: 1,
  224. title: '1 host selected, no host info, no selection requirement'
  225. },
  226. {
  227. selectAtleastOneHost: true,
  228. availableHosts: [
  229. {
  230. selected: true,
  231. host: {}
  232. },
  233. {
  234. selected: false
  235. },
  236. {},
  237. {
  238. selected: 1
  239. },
  240. {
  241. selected: 'true'
  242. }
  243. ],
  244. warningMessage: null,
  245. callbackCallCount: 1,
  246. arrayOfSelectedHosts: [undefined],
  247. hideCallCount: 1,
  248. title: '1 host selected, no host id'
  249. },
  250. {
  251. selectAtleastOneHost: false,
  252. availableHosts: [
  253. {
  254. selected: true,
  255. host: {}
  256. },
  257. {
  258. selected: false
  259. },
  260. {},
  261. {
  262. selected: 1
  263. },
  264. {
  265. selected: 'true'
  266. }
  267. ],
  268. warningMessage: null,
  269. callbackCallCount: 1,
  270. arrayOfSelectedHosts: [undefined],
  271. hideCallCount: 1,
  272. title: '1 host selected, no host id, no selection requirement'
  273. },
  274. {
  275. selectAtleastOneHost: true,
  276. availableHosts: [
  277. {
  278. selected: true,
  279. host: {
  280. id: 'h0'
  281. }
  282. },
  283. {
  284. selected: false,
  285. host: {
  286. id: 'h1'
  287. }
  288. },
  289. {
  290. host: {
  291. id: 'h2'
  292. }
  293. },
  294. {
  295. selected: 1,
  296. host: {
  297. id: 'h3'
  298. }
  299. },
  300. {
  301. selected: 'true',
  302. host: {
  303. id: 'h4'
  304. }
  305. }
  306. ],
  307. warningMessage: null,
  308. callbackCallCount: 1,
  309. arrayOfSelectedHosts: ['h0'],
  310. hideCallCount: 1,
  311. title: '1 host selected, host id available'
  312. },
  313. {
  314. selectAtleastOneHost: false,
  315. availableHosts: [
  316. {
  317. selected: true,
  318. host: {
  319. id: 'h5'
  320. }
  321. },
  322. {
  323. selected: false,
  324. host: {
  325. id: 'h6'
  326. }
  327. },
  328. {
  329. host: {
  330. id: 'h7'
  331. }
  332. },
  333. {
  334. selected: 1,
  335. host: {
  336. id: 'h8'
  337. }
  338. },
  339. {
  340. selected: 'true',
  341. host: {
  342. id: 'h9'
  343. }
  344. }
  345. ],
  346. warningMessage: null,
  347. callbackCallCount: 1,
  348. arrayOfSelectedHosts: ['h5'],
  349. hideCallCount: 1,
  350. title: '1 host selected, host id available, no selection requirement'
  351. },
  352. {
  353. selectAtleastOneHost: true,
  354. availableHosts: [
  355. {
  356. selected: true
  357. },
  358. {
  359. selected: true
  360. },
  361. {
  362. selected: false
  363. },
  364. {},
  365. {
  366. selected: 1
  367. },
  368. {
  369. selected: 'true'
  370. }
  371. ],
  372. warningMessage: null,
  373. callbackCallCount: 1,
  374. arrayOfSelectedHosts: [undefined, undefined],
  375. hideCallCount: 1,
  376. title: 'more than 1 host selected, no host info'
  377. },
  378. {
  379. selectAtleastOneHost: false,
  380. availableHosts: [
  381. {
  382. selected: true
  383. },
  384. {
  385. selected: true
  386. },
  387. {
  388. selected: false
  389. },
  390. {},
  391. {
  392. selected: 1
  393. },
  394. {
  395. selected: 'true'
  396. }
  397. ],
  398. warningMessage: null,
  399. callbackCallCount: 1,
  400. arrayOfSelectedHosts: [undefined, undefined],
  401. hideCallCount: 1,
  402. title: 'more than 1 host selected, no host info, no selection requirement'
  403. },
  404. {
  405. selectAtleastOneHost: true,
  406. availableHosts: [
  407. {
  408. selected: true,
  409. host: {}
  410. },
  411. {
  412. selected: true,
  413. host: {}
  414. },
  415. {
  416. selected: false
  417. },
  418. {},
  419. {
  420. selected: 1
  421. },
  422. {
  423. selected: 'true'
  424. }
  425. ],
  426. warningMessage: null,
  427. callbackCallCount: 1,
  428. arrayOfSelectedHosts: [undefined, undefined],
  429. hideCallCount: 1,
  430. title: 'more than 1 host selected, no host id'
  431. },
  432. {
  433. selectAtleastOneHost: false,
  434. availableHosts: [
  435. {
  436. selected: true,
  437. host: {}
  438. },
  439. {
  440. selected: true,
  441. host: {}
  442. },
  443. {
  444. selected: false
  445. },
  446. {},
  447. {
  448. selected: 1
  449. },
  450. {
  451. selected: 'true'
  452. }
  453. ],
  454. warningMessage: null,
  455. callbackCallCount: 1,
  456. arrayOfSelectedHosts: [undefined, undefined],
  457. hideCallCount: 1,
  458. title: 'more than 1 host selected, no host id, no selection requirement'
  459. },
  460. {
  461. selectAtleastOneHost: true,
  462. availableHosts: [
  463. {
  464. selected: true,
  465. host: {
  466. id: 'h10'
  467. }
  468. },
  469. {
  470. selected: true,
  471. host: {
  472. id: 'h11'
  473. }
  474. },
  475. {
  476. selected: false,
  477. host: {
  478. id: 'h12'
  479. }
  480. },
  481. {
  482. host: {
  483. id: 'h13'
  484. }
  485. },
  486. {
  487. selected: 1,
  488. host: {
  489. id: 'h14'
  490. }
  491. },
  492. {
  493. selected: 'true',
  494. host: {
  495. id: 'h15'
  496. }
  497. }
  498. ],
  499. warningMessage: null,
  500. callbackCallCount: 1,
  501. arrayOfSelectedHosts: ['h10', 'h11'],
  502. hideCallCount: 1,
  503. title: 'more than 1 host selected, host ids available'
  504. },
  505. {
  506. selectAtleastOneHost: false,
  507. availableHosts: [
  508. {
  509. selected: true,
  510. host: {
  511. id: 'h16'
  512. }
  513. },
  514. {
  515. selected: true,
  516. host: {
  517. id: 'h17'
  518. }
  519. },
  520. {
  521. selected: false,
  522. host: {
  523. id: 'h18'
  524. }
  525. },
  526. {
  527. host: {
  528. id: 'h19'
  529. }
  530. },
  531. {
  532. selected: 1,
  533. host: {
  534. id: 'h20'
  535. }
  536. },
  537. {
  538. selected: 'true',
  539. host: {
  540. id: 'h21'
  541. }
  542. }
  543. ],
  544. warningMessage: null,
  545. callbackCallCount: 1,
  546. arrayOfSelectedHosts: ['h16', 'h17'],
  547. hideCallCount: 1,
  548. title: 'more than 1 host selected, host ids available, no selection requirement'
  549. }
  550. ];
  551. cases.forEach(function (item) {
  552. describe(item.title, function () {
  553. beforeEach(function () {
  554. sinon.spy(mock, 'callback');
  555. hostsUtils.launchHostsSelectionDialog(null, null, item.selectAtleastOneHost, null, mock.callback, {});
  556. popup = Em.Object.create(App.ModalPopup.show.firstCall.args[0], {
  557. warningMessage: '',
  558. availableHosts: item.availableHosts,
  559. hide: Em.K
  560. });
  561. sinon.spy(popup, 'hide');
  562. popup.onPrimary();
  563. });
  564. afterEach(function () {
  565. mock.callback.restore();
  566. popup.hide.restore();
  567. });
  568. it('warning message', function () {
  569. expect(popup.get('warningMessage')).to.equal(item.warningMessage);
  570. });
  571. it('callback', function () {
  572. expect(mock.callback.callCount).to.equal(item.callbackCallCount);
  573. });
  574. if (item.callbackCallCount) {
  575. it('callback argument', function () {
  576. expect(mock.callback.firstCall.args).to.eql([item.arrayOfSelectedHosts]);
  577. });
  578. }
  579. it('hide popup', function () {
  580. expect(popup.hide.callCount).to.equal(item.hideCallCount);
  581. });
  582. });
  583. });
  584. });
  585. describe('#disablePrimary', function () {
  586. var cases = [
  587. {
  588. isLoaded: true,
  589. disablePrimary: false,
  590. title: 'enable button'
  591. },
  592. {
  593. isLoaded: false,
  594. disablePrimary: true,
  595. title: 'disable button'
  596. }
  597. ];
  598. cases.forEach(function (item) {
  599. it(item.title, function () {
  600. hostsUtils.launchHostsSelectionDialog(null, null, null, null, null, item.popupDescription);
  601. popup = Em.Object.create(App.ModalPopup.show.firstCall.args[0], {
  602. isLoaded: item.isLoaded
  603. });
  604. expect(popup.get('disablePrimary')).to.equal(item.disablePrimary);
  605. });
  606. });
  607. });
  608. describe('#onSecondary', function () {
  609. beforeEach(function () {
  610. sinon.spy(mock, 'callback');
  611. hostsUtils.launchHostsSelectionDialog(null, null, null, null, mock.callback, {});
  612. popup = Em.Object.create(App.ModalPopup.show.firstCall.args[0], {
  613. hide: Em.K
  614. });
  615. sinon.spy(popup, 'hide');
  616. popup.onSecondary();
  617. });
  618. afterEach(function () {
  619. mock.callback.restore();
  620. popup.hide.restore();
  621. });
  622. it('callback', function () {
  623. expect(mock.callback.calledOnce).to.be.true;
  624. });
  625. it('callback argument', function () {
  626. expect(mock.callback.firstCall.args).to.eql([null]);
  627. });
  628. it('hide popup', function () {
  629. expect(popup.hide.calledOnce).to.be.true;
  630. });
  631. });
  632. describe('#bodyClass', function () {
  633. var view,
  634. validComponents = [
  635. {
  636. componentName: 'c0'
  637. },
  638. {
  639. componentName: 'c1'
  640. }
  641. ];
  642. beforeEach(function () {
  643. hostsUtils.launchHostsSelectionDialog([
  644. {
  645. host: {
  646. id: 'h0'
  647. },
  648. filtered: false
  649. },
  650. {
  651. host: {
  652. id: 'h1'
  653. }
  654. }
  655. ], null, null, validComponents, null, {});
  656. popup = Em.Object.create(App.ModalPopup.show.firstCall.args[0]);
  657. view = popup.get('bodyClass').create({
  658. parentView: popup
  659. });
  660. });
  661. describe('#filteredContentObs', function () {
  662. beforeEach(function () {
  663. sinon.stub(view, 'filteredContentObsOnce', Em.K);
  664. sinon.stub(view, 'filterHosts', Em.K);
  665. sinon.stub(Em.run, 'once', function (context, callback) {
  666. callback.call(context);
  667. });
  668. });
  669. afterEach(function () {
  670. view.filteredContentObsOnce.restore();
  671. view.filterHosts.restore();
  672. Em.run.once.restore();
  673. });
  674. it('should run filteredContentObsOnce', function () {
  675. popup.set('availableHosts', [
  676. {
  677. filtered: true
  678. }
  679. ]);
  680. expect(view.filteredContentObsOnce.calledOnce).to.be.true;
  681. });
  682. });
  683. describe('#filteredContentObsOnce', function () {
  684. var cases = [
  685. {
  686. availableHosts: [],
  687. filteredContent: [],
  688. title: 'no hosts available'
  689. },
  690. {
  691. availableHosts: [
  692. {},
  693. {
  694. filtered: false
  695. },
  696. {
  697. filtered: null
  698. },
  699. {
  700. filtered: 0
  701. }
  702. ],
  703. filteredContent: [],
  704. title: 'no hosts filtered'
  705. },
  706. {
  707. availableHosts: [
  708. {},
  709. {
  710. filtered: false
  711. },
  712. {
  713. filtered: null
  714. },
  715. {
  716. filtered: 0
  717. },
  718. {
  719. filtered: true
  720. },
  721. {
  722. filtered: 'true'
  723. },
  724. {
  725. filtered: 1
  726. }
  727. ],
  728. filteredContent: [
  729. {
  730. filtered: true
  731. },
  732. {
  733. filtered: 'true'
  734. },
  735. {
  736. filtered: 1
  737. }
  738. ],
  739. title: 'filtered hosts present'
  740. }
  741. ];
  742. beforeEach(function () {
  743. sinon.stub(view, 'filteredContentObs', Em.K);
  744. sinon.stub(view, 'filterHosts', Em.K);
  745. });
  746. afterEach(function () {
  747. view.filteredContentObs.restore();
  748. view.filterHosts.restore();
  749. });
  750. cases.forEach(function (item) {
  751. it(item.title, function () {
  752. popup.set('availableHosts', item.availableHosts);
  753. view.filteredContentObsOnce();
  754. expect(view.get('filteredContent')).to.eql(item.filteredContent);
  755. });
  756. });
  757. });
  758. describe('#filterComponents', function () {
  759. it('should be set from validComponents', function () {
  760. expect(view.get('filterComponents')).to.eql(validComponents);
  761. });
  762. });
  763. describe('#isDisabled', function () {
  764. var cases = [
  765. {
  766. isLoaded: true,
  767. isDisabled: false,
  768. title: 'enabled'
  769. },
  770. {
  771. isLoaded: false,
  772. isDisabled: true,
  773. title: 'disabled'
  774. }
  775. ];
  776. cases.forEach(function (item) {
  777. it(item.title, function () {
  778. popup.set('isLoaded', item.isLoaded);
  779. expect(view.get('isDisabled')).to.equal(item.isDisabled);
  780. });
  781. });
  782. });
  783. describe('#didInsertElement', function () {
  784. beforeEach(function () {
  785. sinon.stub(view, 'filterHosts', Em.K);
  786. sinon.stub(view, 'filteredContentObs', Em.K);
  787. sinon.stub(view, 'filteredContentObsOnce', Em.K);
  788. view.get('filterColumns').setEach('selected', false);
  789. view.get('filterColumns').findProperty('id', 'cpu').set('selected', true);
  790. view.didInsertElement();
  791. });
  792. afterEach(function () {
  793. view.filterHosts.restore();
  794. view.filteredContentObs.restore();
  795. view.filteredContentObsOnce.restore();
  796. });
  797. it('column for filter', function () {
  798. expect(view.get('filterColumn')).to.eql(Em.Object.create({
  799. id: 'cpu',
  800. name: 'CPU',
  801. selected: true
  802. }));
  803. });
  804. it('available hosts', function () {
  805. expect(view.get('parentView.availableHosts').toArray()).to.eql([
  806. {
  807. host: {
  808. id: 'h0'
  809. },
  810. filtered: true
  811. },
  812. {
  813. host: {
  814. id: 'h1'
  815. },
  816. filtered: true
  817. }
  818. ]);
  819. });
  820. it('isLoaded', function () {
  821. expect(view.get('parentView.isLoaded')).to.be.true;
  822. });
  823. it('observer called', function () {
  824. expect(view.filteredContentObsOnce.calledOnce).to.be.true;
  825. });
  826. });
  827. describe('#filterHosts', function () {
  828. var cases = [
  829. {
  830. filterText: '',
  831. filterComponent: null,
  832. showOnlySelectedHosts: true,
  833. availableHosts: [
  834. Em.Object.create({
  835. host: Em.Object.create({
  836. osType: 'centos6'
  837. }),
  838. selected: true
  839. }),
  840. Em.Object.create({
  841. host: Em.Object.create({
  842. osType: 'centos7'
  843. }),
  844. selected: false
  845. })
  846. ],
  847. result: [
  848. Em.Object.create({
  849. host: Em.Object.create({
  850. osType: 'centos6'
  851. }),
  852. selected: true,
  853. filterColumnValue: 'centos6',
  854. filtered: true
  855. }),
  856. Em.Object.create({
  857. host: Em.Object.create({
  858. osType: 'centos7'
  859. }),
  860. selected: false,
  861. filterColumnValue: 'centos7',
  862. filtered: false
  863. })
  864. ],
  865. title: 'no filter text, no component for filter, show selected hosts only'
  866. },
  867. {
  868. filterText: '',
  869. filterComponent: null,
  870. showOnlySelectedHosts: false,
  871. availableHosts: [
  872. Em.Object.create({
  873. host: Em.Object.create({
  874. osType: 'centos6'
  875. }),
  876. selected: true
  877. }),
  878. Em.Object.create({
  879. host: Em.Object.create({
  880. osType: 'centos7'
  881. }),
  882. selected: false
  883. })
  884. ],
  885. result: [
  886. Em.Object.create({
  887. host: Em.Object.create({
  888. osType: 'centos6'
  889. }),
  890. selected: true,
  891. filterColumnValue: 'centos6',
  892. filtered: true
  893. }),
  894. Em.Object.create({
  895. host: Em.Object.create({
  896. osType: 'centos7'
  897. }),
  898. selected: false,
  899. filterColumnValue: 'centos7',
  900. filtered: true
  901. })
  902. ],
  903. title: 'no filter text, no component for filter, show all hosts'
  904. },
  905. {
  906. filterText: 'n',
  907. filterComponent: null,
  908. showOnlySelectedHosts: true,
  909. availableHosts: [
  910. Em.Object.create({
  911. host: Em.Object.create({
  912. publicHostName: 'h0'
  913. }),
  914. selected: true
  915. }),
  916. Em.Object.create({
  917. host: Em.Object.create({
  918. publicHostName: 'h1'
  919. }),
  920. selected: false
  921. }),
  922. Em.Object.create({
  923. host: Em.Object.create({
  924. publicHostName: 'hn2'
  925. }),
  926. selected: true
  927. }),
  928. Em.Object.create({
  929. host: Em.Object.create({
  930. publicHostName: 'hn3'
  931. }),
  932. selected: false
  933. }),
  934. Em.Object.create({
  935. host: Em.Object.create({
  936. publicHostName: 'h4',
  937. osType: 'centos6'
  938. }),
  939. selected: true
  940. }),
  941. Em.Object.create({
  942. host: Em.Object.create({
  943. publicHostName: 'h5',
  944. osType: 'centos6'
  945. }),
  946. selected: false
  947. }),
  948. Em.Object.create({
  949. host: Em.Object.create({
  950. publicHostName: 'hn6',
  951. osType: 'centos6'
  952. }),
  953. selected: true
  954. }),
  955. Em.Object.create({
  956. host: Em.Object.create({
  957. publicHostName: 'hn7',
  958. osType: 'centos6'
  959. }),
  960. selected: false
  961. }),
  962. Em.Object.create({
  963. host: Em.Object.create({
  964. publicHostName: 'h8',
  965. osType: 'suse11'
  966. }),
  967. selected: true
  968. }),
  969. Em.Object.create({
  970. host: Em.Object.create({
  971. publicHostName: 'h9',
  972. osType: 'suse11'
  973. }),
  974. selected: false
  975. }),
  976. Em.Object.create({
  977. host: Em.Object.create({
  978. publicHostName: 'hn10',
  979. osType: 'suse11'
  980. }),
  981. selected: true
  982. }),
  983. Em.Object.create({
  984. host: Em.Object.create({
  985. publicHostName: 'hn11',
  986. osType: 'suse11'
  987. }),
  988. selected: false
  989. })
  990. ],
  991. result: [
  992. Em.Object.create({
  993. host: Em.Object.create({
  994. publicHostName: 'h0'
  995. }),
  996. selected: true,
  997. filtered: false
  998. }),
  999. Em.Object.create({
  1000. host: Em.Object.create({
  1001. publicHostName: 'h1'
  1002. }),
  1003. selected: false,
  1004. filtered: false
  1005. }),
  1006. Em.Object.create({
  1007. host: Em.Object.create({
  1008. publicHostName: 'hn2'
  1009. }),
  1010. selected: true,
  1011. filtered: true
  1012. }),
  1013. Em.Object.create({
  1014. host: Em.Object.create({
  1015. publicHostName: 'hn3'
  1016. }),
  1017. selected: false,
  1018. filtered: false
  1019. }),
  1020. Em.Object.create({
  1021. host: Em.Object.create({
  1022. publicHostName: 'h4',
  1023. osType: 'centos6'
  1024. }),
  1025. selected: true,
  1026. filterColumnValue: 'centos6',
  1027. filtered: true
  1028. }),
  1029. Em.Object.create({
  1030. host: Em.Object.create({
  1031. publicHostName: 'h5',
  1032. osType: 'centos6'
  1033. }),
  1034. selected: false,
  1035. filterColumnValue: 'centos6',
  1036. filtered: false
  1037. }),
  1038. Em.Object.create({
  1039. host: Em.Object.create({
  1040. publicHostName: 'hn6',
  1041. osType: 'centos6'
  1042. }),
  1043. selected: true,
  1044. filterColumnValue: 'centos6',
  1045. filtered: true
  1046. }),
  1047. Em.Object.create({
  1048. host: Em.Object.create({
  1049. publicHostName: 'hn7',
  1050. osType: 'centos6'
  1051. }),
  1052. selected: false,
  1053. filterColumnValue: 'centos6',
  1054. filtered: false
  1055. }),
  1056. Em.Object.create({
  1057. host: Em.Object.create({
  1058. publicHostName: 'h8',
  1059. osType: 'suse11'
  1060. }),
  1061. selected: true,
  1062. filterColumnValue: 'suse11',
  1063. filtered: false
  1064. }),
  1065. Em.Object.create({
  1066. host: Em.Object.create({
  1067. publicHostName: 'h9',
  1068. osType: 'suse11'
  1069. }),
  1070. selected: false,
  1071. filterColumnValue: 'suse11',
  1072. filtered: false
  1073. }),
  1074. Em.Object.create({
  1075. host: Em.Object.create({
  1076. publicHostName: 'hn10',
  1077. osType: 'suse11'
  1078. }),
  1079. selected: true,
  1080. filterColumnValue: 'suse11',
  1081. filtered: true
  1082. }),
  1083. Em.Object.create({
  1084. host: Em.Object.create({
  1085. publicHostName: 'hn11',
  1086. osType: 'suse11'
  1087. }),
  1088. selected: false,
  1089. filterColumnValue: 'suse11',
  1090. filtered: false
  1091. })
  1092. ],
  1093. title: 'filter text set, no component for filter, show selected hosts only'
  1094. },
  1095. {
  1096. filterText: 'n',
  1097. filterComponent: null,
  1098. showOnlySelectedHosts: false,
  1099. availableHosts: [
  1100. Em.Object.create({
  1101. host: Em.Object.create({
  1102. publicHostName: 'h0'
  1103. }),
  1104. selected: true
  1105. }),
  1106. Em.Object.create({
  1107. host: Em.Object.create({
  1108. publicHostName: 'h1'
  1109. }),
  1110. selected: false
  1111. }),
  1112. Em.Object.create({
  1113. host: Em.Object.create({
  1114. publicHostName: 'hn2'
  1115. }),
  1116. selected: true
  1117. }),
  1118. Em.Object.create({
  1119. host: Em.Object.create({
  1120. publicHostName: 'hn3'
  1121. }),
  1122. selected: false
  1123. }),
  1124. Em.Object.create({
  1125. host: Em.Object.create({
  1126. publicHostName: 'h4',
  1127. osType: 'centos6'
  1128. }),
  1129. selected: true
  1130. }),
  1131. Em.Object.create({
  1132. host: Em.Object.create({
  1133. publicHostName: 'h5',
  1134. osType: 'centos6'
  1135. }),
  1136. selected: false
  1137. }),
  1138. Em.Object.create({
  1139. host: Em.Object.create({
  1140. publicHostName: 'hn6',
  1141. osType: 'centos6'
  1142. }),
  1143. selected: true
  1144. }),
  1145. Em.Object.create({
  1146. host: Em.Object.create({
  1147. publicHostName: 'hn7',
  1148. osType: 'centos6'
  1149. }),
  1150. selected: false
  1151. }),
  1152. Em.Object.create({
  1153. host: Em.Object.create({
  1154. publicHostName: 'h8',
  1155. osType: 'suse11'
  1156. }),
  1157. selected: true
  1158. }),
  1159. Em.Object.create({
  1160. host: Em.Object.create({
  1161. publicHostName: 'h9',
  1162. osType: 'suse11'
  1163. }),
  1164. selected: false
  1165. }),
  1166. Em.Object.create({
  1167. host: Em.Object.create({
  1168. publicHostName: 'hn10',
  1169. osType: 'suse11'
  1170. }),
  1171. selected: true
  1172. }),
  1173. Em.Object.create({
  1174. host: Em.Object.create({
  1175. publicHostName: 'hn11',
  1176. osType: 'suse11'
  1177. }),
  1178. selected: false
  1179. })
  1180. ],
  1181. result: [
  1182. Em.Object.create({
  1183. host: Em.Object.create({
  1184. publicHostName: 'h0'
  1185. }),
  1186. selected: true,
  1187. filtered: false
  1188. }),
  1189. Em.Object.create({
  1190. host: Em.Object.create({
  1191. publicHostName: 'h1'
  1192. }),
  1193. selected: false,
  1194. filtered: false
  1195. }),
  1196. Em.Object.create({
  1197. host: Em.Object.create({
  1198. publicHostName: 'hn2'
  1199. }),
  1200. selected: true,
  1201. filtered: true
  1202. }),
  1203. Em.Object.create({
  1204. host: Em.Object.create({
  1205. publicHostName: 'hn3'
  1206. }),
  1207. selected: false,
  1208. filtered: true
  1209. }),
  1210. Em.Object.create({
  1211. host: Em.Object.create({
  1212. publicHostName: 'h4',
  1213. osType: 'centos6'
  1214. }),
  1215. selected: true,
  1216. filterColumnValue: 'centos6',
  1217. filtered: true
  1218. }),
  1219. Em.Object.create({
  1220. host: Em.Object.create({
  1221. publicHostName: 'h5',
  1222. osType: 'centos6'
  1223. }),
  1224. selected: false,
  1225. filterColumnValue: 'centos6',
  1226. filtered: true
  1227. }),
  1228. Em.Object.create({
  1229. host: Em.Object.create({
  1230. publicHostName: 'hn6',
  1231. osType: 'centos6'
  1232. }),
  1233. selected: true,
  1234. filterColumnValue: 'centos6',
  1235. filtered: true
  1236. }),
  1237. Em.Object.create({
  1238. host: Em.Object.create({
  1239. publicHostName: 'hn7',
  1240. osType: 'centos6'
  1241. }),
  1242. selected: false,
  1243. filterColumnValue: 'centos6',
  1244. filtered: true
  1245. }),
  1246. Em.Object.create({
  1247. host: Em.Object.create({
  1248. publicHostName: 'h8',
  1249. osType: 'suse11'
  1250. }),
  1251. selected: true,
  1252. filterColumnValue: 'suse11',
  1253. filtered: false
  1254. }),
  1255. Em.Object.create({
  1256. host: Em.Object.create({
  1257. publicHostName: 'h9',
  1258. osType: 'suse11'
  1259. }),
  1260. selected: false,
  1261. filterColumnValue: 'suse11',
  1262. filtered: false
  1263. }),
  1264. Em.Object.create({
  1265. host: Em.Object.create({
  1266. publicHostName: 'hn10',
  1267. osType: 'suse11'
  1268. }),
  1269. selected: true,
  1270. filterColumnValue: 'suse11',
  1271. filtered: true
  1272. }),
  1273. Em.Object.create({
  1274. host: Em.Object.create({
  1275. publicHostName: 'hn11',
  1276. osType: 'suse11'
  1277. }),
  1278. selected: false,
  1279. filterColumnValue: 'suse11',
  1280. filtered: true
  1281. })
  1282. ],
  1283. title: 'filter text set, no component for filter, show all hosts'
  1284. },
  1285. {
  1286. filterText: '',
  1287. filterComponent: Em.Object.create({
  1288. componentName: 'c0'
  1289. }),
  1290. showOnlySelectedHosts: true,
  1291. availableHosts: [
  1292. Em.Object.create({
  1293. host: Em.Object.create({
  1294. osType: 'centos6'
  1295. }),
  1296. hostComponentNames: [],
  1297. selected: true
  1298. }),
  1299. Em.Object.create({
  1300. host: Em.Object.create({
  1301. osType: 'centos7'
  1302. }),
  1303. hostComponentNames: [],
  1304. selected: false
  1305. }),
  1306. Em.Object.create({
  1307. host: Em.Object.create({
  1308. osType: 'centos6'
  1309. }),
  1310. hostComponentNames: ['c1', 'c2'],
  1311. selected: true
  1312. }),
  1313. Em.Object.create({
  1314. host: Em.Object.create({
  1315. osType: 'centos7'
  1316. }),
  1317. hostComponentNames: ['c1', 'c2'],
  1318. selected: false
  1319. }),
  1320. Em.Object.create({
  1321. host: Em.Object.create({
  1322. osType: 'centos6'
  1323. }),
  1324. hostComponentNames: ['c0', 'c2'],
  1325. selected: true
  1326. }),
  1327. Em.Object.create({
  1328. host: Em.Object.create({
  1329. osType: 'centos7'
  1330. }),
  1331. hostComponentNames: ['c0', 'c2'],
  1332. selected: false
  1333. })
  1334. ],
  1335. result: [
  1336. Em.Object.create({
  1337. host: Em.Object.create({
  1338. osType: 'centos6'
  1339. }),
  1340. hostComponentNames: [],
  1341. selected: true,
  1342. filterColumnValue: 'centos6',
  1343. filtered: true
  1344. }),
  1345. Em.Object.create({
  1346. host: Em.Object.create({
  1347. osType: 'centos7'
  1348. }),
  1349. hostComponentNames: [],
  1350. selected: false,
  1351. filterColumnValue: 'centos7',
  1352. filtered: false
  1353. }),
  1354. Em.Object.create({
  1355. host: Em.Object.create({
  1356. osType: 'centos6'
  1357. }),
  1358. hostComponentNames: ['c1', 'c2'],
  1359. selected: true,
  1360. filterColumnValue: 'centos6',
  1361. filtered: false
  1362. }),
  1363. Em.Object.create({
  1364. host: Em.Object.create({
  1365. osType: 'centos7'
  1366. }),
  1367. hostComponentNames: ['c1', 'c2'],
  1368. selected: false,
  1369. filterColumnValue: 'centos7',
  1370. filtered: false
  1371. }),
  1372. Em.Object.create({
  1373. host: Em.Object.create({
  1374. osType: 'centos6'
  1375. }),
  1376. hostComponentNames: ['c0', 'c2'],
  1377. selected: true,
  1378. filterColumnValue: 'centos6',
  1379. filtered: true
  1380. }),
  1381. Em.Object.create({
  1382. host: Em.Object.create({
  1383. osType: 'centos7'
  1384. }),
  1385. hostComponentNames: ['c0', 'c2'],
  1386. selected: false,
  1387. filterColumnValue: 'centos7',
  1388. filtered: false
  1389. })
  1390. ],
  1391. title: 'no filter text, component filter set, show selected hosts only'
  1392. },
  1393. {
  1394. filterText: '',
  1395. filterComponent: Em.Object.create({
  1396. componentName: 'c1'
  1397. }),
  1398. showOnlySelectedHosts: false,
  1399. availableHosts: [
  1400. Em.Object.create({
  1401. host: Em.Object.create({
  1402. osType: 'centos6'
  1403. }),
  1404. hostComponentNames: [],
  1405. selected: true
  1406. }),
  1407. Em.Object.create({
  1408. host: Em.Object.create({
  1409. osType: 'centos7'
  1410. }),
  1411. hostComponentNames: [],
  1412. selected: false
  1413. }),
  1414. Em.Object.create({
  1415. host: Em.Object.create({
  1416. osType: 'centos6'
  1417. }),
  1418. hostComponentNames: ['c0', 'c2'],
  1419. selected: true
  1420. }),
  1421. Em.Object.create({
  1422. host: Em.Object.create({
  1423. osType: 'centos7'
  1424. }),
  1425. hostComponentNames: ['c0', 'c2'],
  1426. selected: false
  1427. }),
  1428. Em.Object.create({
  1429. host: Em.Object.create({
  1430. osType: 'centos6'
  1431. }),
  1432. hostComponentNames: ['c1', 'c2'],
  1433. selected: true
  1434. }),
  1435. Em.Object.create({
  1436. host: Em.Object.create({
  1437. osType: 'centos7'
  1438. }),
  1439. hostComponentNames: ['c1', 'c2'],
  1440. selected: false
  1441. })
  1442. ],
  1443. result: [
  1444. Em.Object.create({
  1445. host: Em.Object.create({
  1446. osType: 'centos6'
  1447. }),
  1448. hostComponentNames: [],
  1449. selected: true,
  1450. filterColumnValue: 'centos6',
  1451. filtered: true
  1452. }),
  1453. Em.Object.create({
  1454. host: Em.Object.create({
  1455. osType: 'centos7'
  1456. }),
  1457. hostComponentNames: [],
  1458. selected: false,
  1459. filterColumnValue: 'centos7',
  1460. filtered: true
  1461. }),
  1462. Em.Object.create({
  1463. host: Em.Object.create({
  1464. osType: 'centos6'
  1465. }),
  1466. hostComponentNames: ['c0', 'c2'],
  1467. selected: true,
  1468. filterColumnValue: 'centos6',
  1469. filtered: false
  1470. }),
  1471. Em.Object.create({
  1472. host: Em.Object.create({
  1473. osType: 'centos7'
  1474. }),
  1475. hostComponentNames: ['c0', 'c2'],
  1476. selected: false,
  1477. filterColumnValue: 'centos7',
  1478. filtered: false
  1479. }),
  1480. Em.Object.create({
  1481. host: Em.Object.create({
  1482. osType: 'centos6'
  1483. }),
  1484. hostComponentNames: ['c1', 'c2'],
  1485. selected: true,
  1486. filterColumnValue: 'centos6',
  1487. filtered: true
  1488. }),
  1489. Em.Object.create({
  1490. host: Em.Object.create({
  1491. osType: 'centos7'
  1492. }),
  1493. hostComponentNames: ['c1', 'c2'],
  1494. selected: false,
  1495. filterColumnValue: 'centos7',
  1496. filtered: true
  1497. })
  1498. ],
  1499. title: 'no filter text, component filter set, show all hosts'
  1500. },
  1501. {
  1502. filterText: 'n',
  1503. filterComponent: Em.Object.create({
  1504. componentName: 'c2'
  1505. }),
  1506. showOnlySelectedHosts: true,
  1507. availableHosts: [
  1508. Em.Object.create({
  1509. host: Em.Object.create({
  1510. publicHostName: 'h0'
  1511. }),
  1512. hostComponentNames: [],
  1513. selected: true
  1514. }),
  1515. Em.Object.create({
  1516. host: Em.Object.create({
  1517. publicHostName: 'h1'
  1518. }),
  1519. hostComponentNames: [],
  1520. selected: false
  1521. }),
  1522. Em.Object.create({
  1523. host: Em.Object.create({
  1524. publicHostName: 'hn2'
  1525. }),
  1526. hostComponentNames: [],
  1527. selected: true
  1528. }),
  1529. Em.Object.create({
  1530. host: Em.Object.create({
  1531. publicHostName: 'hn3'
  1532. }),
  1533. hostComponentNames: [],
  1534. selected: false
  1535. }),
  1536. Em.Object.create({
  1537. host: Em.Object.create({
  1538. publicHostName: 'h4',
  1539. osType: 'centos6'
  1540. }),
  1541. hostComponentNames: [],
  1542. selected: true
  1543. }),
  1544. Em.Object.create({
  1545. host: Em.Object.create({
  1546. publicHostName: 'h5',
  1547. osType: 'centos6'
  1548. }),
  1549. hostComponentNames: [],
  1550. selected: false
  1551. }),
  1552. Em.Object.create({
  1553. host: Em.Object.create({
  1554. publicHostName: 'hn6',
  1555. osType: 'centos6'
  1556. }),
  1557. hostComponentNames: [],
  1558. selected: true
  1559. }),
  1560. Em.Object.create({
  1561. host: Em.Object.create({
  1562. publicHostName: 'hn7',
  1563. osType: 'centos6'
  1564. }),
  1565. hostComponentNames: [],
  1566. selected: false
  1567. }),
  1568. Em.Object.create({
  1569. host: Em.Object.create({
  1570. publicHostName: 'h8',
  1571. osType: 'suse11'
  1572. }),
  1573. hostComponentNames: [],
  1574. selected: true
  1575. }),
  1576. Em.Object.create({
  1577. host: Em.Object.create({
  1578. publicHostName: 'h9',
  1579. osType: 'suse11'
  1580. }),
  1581. hostComponentNames: [],
  1582. selected: false
  1583. }),
  1584. Em.Object.create({
  1585. host: Em.Object.create({
  1586. publicHostName: 'hn10',
  1587. osType: 'suse11'
  1588. }),
  1589. hostComponentNames: [],
  1590. selected: true
  1591. }),
  1592. Em.Object.create({
  1593. host: Em.Object.create({
  1594. publicHostName: 'hn11',
  1595. osType: 'suse11'
  1596. }),
  1597. hostComponentNames: [],
  1598. selected: false
  1599. }),
  1600. Em.Object.create({
  1601. host: Em.Object.create({
  1602. publicHostName: 'h12'
  1603. }),
  1604. hostComponentNames: ['c0', 'c1'],
  1605. selected: true
  1606. }),
  1607. Em.Object.create({
  1608. host: Em.Object.create({
  1609. publicHostName: 'h13'
  1610. }),
  1611. hostComponentNames: ['c0', 'c1'],
  1612. selected: false
  1613. }),
  1614. Em.Object.create({
  1615. host: Em.Object.create({
  1616. publicHostName: 'hn14'
  1617. }),
  1618. hostComponentNames: ['c0', 'c1'],
  1619. selected: true
  1620. }),
  1621. Em.Object.create({
  1622. host: Em.Object.create({
  1623. publicHostName: 'hn15'
  1624. }),
  1625. hostComponentNames: ['c0', 'c1'],
  1626. selected: false
  1627. }),
  1628. Em.Object.create({
  1629. host: Em.Object.create({
  1630. publicHostName: 'h16',
  1631. osType: 'centos6'
  1632. }),
  1633. hostComponentNames: ['c0', 'c1'],
  1634. selected: true
  1635. }),
  1636. Em.Object.create({
  1637. host: Em.Object.create({
  1638. publicHostName: 'h17',
  1639. osType: 'centos6'
  1640. }),
  1641. hostComponentNames: ['c0', 'c1'],
  1642. selected: false
  1643. }),
  1644. Em.Object.create({
  1645. host: Em.Object.create({
  1646. publicHostName: 'hn18',
  1647. osType: 'centos6'
  1648. }),
  1649. hostComponentNames: ['c0', 'c1'],
  1650. selected: true
  1651. }),
  1652. Em.Object.create({
  1653. host: Em.Object.create({
  1654. publicHostName: 'hn19',
  1655. osType: 'centos6'
  1656. }),
  1657. hostComponentNames: ['c0', 'c1'],
  1658. selected: false
  1659. }),
  1660. Em.Object.create({
  1661. host: Em.Object.create({
  1662. publicHostName: 'h20',
  1663. osType: 'suse11'
  1664. }),
  1665. hostComponentNames: ['c0', 'c1'],
  1666. selected: true
  1667. }),
  1668. Em.Object.create({
  1669. host: Em.Object.create({
  1670. publicHostName: 'h21',
  1671. osType: 'suse11'
  1672. }),
  1673. hostComponentNames: ['c0', 'c1'],
  1674. selected: false
  1675. }),
  1676. Em.Object.create({
  1677. host: Em.Object.create({
  1678. publicHostName: 'hn22',
  1679. osType: 'suse11'
  1680. }),
  1681. hostComponentNames: ['c0', 'c1'],
  1682. selected: true
  1683. }),
  1684. Em.Object.create({
  1685. host: Em.Object.create({
  1686. publicHostName: 'hn23',
  1687. osType: 'suse11'
  1688. }),
  1689. hostComponentNames: ['c0', 'c1'],
  1690. selected: false
  1691. }),
  1692. Em.Object.create({
  1693. host: Em.Object.create({
  1694. publicHostName: 'h24'
  1695. }),
  1696. hostComponentNames: ['c0', 'c2'],
  1697. selected: true
  1698. }),
  1699. Em.Object.create({
  1700. host: Em.Object.create({
  1701. publicHostName: 'h25'
  1702. }),
  1703. hostComponentNames: ['c0', 'c2'],
  1704. selected: false
  1705. }),
  1706. Em.Object.create({
  1707. host: Em.Object.create({
  1708. publicHostName: 'hn26'
  1709. }),
  1710. hostComponentNames: ['c0', 'c2'],
  1711. selected: true
  1712. }),
  1713. Em.Object.create({
  1714. host: Em.Object.create({
  1715. publicHostName: 'hn27'
  1716. }),
  1717. hostComponentNames: ['c0', 'c2'],
  1718. selected: false
  1719. }),
  1720. Em.Object.create({
  1721. host: Em.Object.create({
  1722. publicHostName: 'h28',
  1723. osType: 'centos6'
  1724. }),
  1725. hostComponentNames: ['c0', 'c2'],
  1726. selected: true
  1727. }),
  1728. Em.Object.create({
  1729. host: Em.Object.create({
  1730. publicHostName: 'h29',
  1731. osType: 'centos6'
  1732. }),
  1733. hostComponentNames: ['c0', 'c2'],
  1734. selected: false
  1735. }),
  1736. Em.Object.create({
  1737. host: Em.Object.create({
  1738. publicHostName: 'hn30',
  1739. osType: 'centos6'
  1740. }),
  1741. hostComponentNames: ['c0', 'c2'],
  1742. selected: true
  1743. }),
  1744. Em.Object.create({
  1745. host: Em.Object.create({
  1746. publicHostName: 'hn31',
  1747. osType: 'centos6'
  1748. }),
  1749. hostComponentNames: ['c0', 'c2'],
  1750. selected: false
  1751. }),
  1752. Em.Object.create({
  1753. host: Em.Object.create({
  1754. publicHostName: 'h32',
  1755. osType: 'suse11'
  1756. }),
  1757. hostComponentNames: ['c0', 'c2'],
  1758. selected: true
  1759. }),
  1760. Em.Object.create({
  1761. host: Em.Object.create({
  1762. publicHostName: 'h33',
  1763. osType: 'suse11'
  1764. }),
  1765. hostComponentNames: ['c0', 'c2'],
  1766. selected: false
  1767. }),
  1768. Em.Object.create({
  1769. host: Em.Object.create({
  1770. publicHostName: 'hn34',
  1771. osType: 'suse11'
  1772. }),
  1773. hostComponentNames: ['c0', 'c2'],
  1774. selected: true
  1775. }),
  1776. Em.Object.create({
  1777. host: Em.Object.create({
  1778. publicHostName: 'hn35',
  1779. osType: 'suse11'
  1780. }),
  1781. hostComponentNames: ['c0', 'c2'],
  1782. selected: false
  1783. })
  1784. ],
  1785. result: [
  1786. Em.Object.create({
  1787. host: Em.Object.create({
  1788. publicHostName: 'h0'
  1789. }),
  1790. hostComponentNames: [],
  1791. selected: true,
  1792. filtered: false
  1793. }),
  1794. Em.Object.create({
  1795. host: Em.Object.create({
  1796. publicHostName: 'h1'
  1797. }),
  1798. hostComponentNames: [],
  1799. selected: false,
  1800. filtered: false
  1801. }),
  1802. Em.Object.create({
  1803. host: Em.Object.create({
  1804. publicHostName: 'hn2'
  1805. }),
  1806. hostComponentNames: [],
  1807. selected: true,
  1808. filtered: true
  1809. }),
  1810. Em.Object.create({
  1811. host: Em.Object.create({
  1812. publicHostName: 'hn3'
  1813. }),
  1814. hostComponentNames: [],
  1815. selected: false,
  1816. filtered: false
  1817. }),
  1818. Em.Object.create({
  1819. host: Em.Object.create({
  1820. publicHostName: 'h4',
  1821. osType: 'centos6'
  1822. }),
  1823. hostComponentNames: [],
  1824. selected: true,
  1825. filterColumnValue: 'centos6',
  1826. filtered: true
  1827. }),
  1828. Em.Object.create({
  1829. host: Em.Object.create({
  1830. publicHostName: 'h5',
  1831. osType: 'centos6'
  1832. }),
  1833. hostComponentNames: [],
  1834. selected: false,
  1835. filterColumnValue: 'centos6',
  1836. filtered: false
  1837. }),
  1838. Em.Object.create({
  1839. host: Em.Object.create({
  1840. publicHostName: 'hn6',
  1841. osType: 'centos6'
  1842. }),
  1843. hostComponentNames: [],
  1844. selected: true,
  1845. filterColumnValue: 'centos6',
  1846. filtered: true
  1847. }),
  1848. Em.Object.create({
  1849. host: Em.Object.create({
  1850. publicHostName: 'hn7',
  1851. osType: 'centos6'
  1852. }),
  1853. hostComponentNames: [],
  1854. selected: false,
  1855. filterColumnValue: 'centos6',
  1856. filtered: false
  1857. }),
  1858. Em.Object.create({
  1859. host: Em.Object.create({
  1860. publicHostName: 'h8',
  1861. osType: 'suse11'
  1862. }),
  1863. hostComponentNames: [],
  1864. selected: true,
  1865. filterColumnValue: 'suse11',
  1866. filtered: false
  1867. }),
  1868. Em.Object.create({
  1869. host: Em.Object.create({
  1870. publicHostName: 'h9',
  1871. osType: 'suse11'
  1872. }),
  1873. hostComponentNames: [],
  1874. selected: false,
  1875. filterColumnValue: 'suse11',
  1876. filtered: false
  1877. }),
  1878. Em.Object.create({
  1879. host: Em.Object.create({
  1880. publicHostName: 'hn10',
  1881. osType: 'suse11'
  1882. }),
  1883. hostComponentNames: [],
  1884. selected: true,
  1885. filterColumnValue: 'suse11',
  1886. filtered: true
  1887. }),
  1888. Em.Object.create({
  1889. host: Em.Object.create({
  1890. publicHostName: 'hn11',
  1891. osType: 'suse11'
  1892. }),
  1893. hostComponentNames: [],
  1894. selected: false,
  1895. filterColumnValue: 'suse11',
  1896. filtered: false
  1897. }),
  1898. Em.Object.create({
  1899. host: Em.Object.create({
  1900. publicHostName: 'h12'
  1901. }),
  1902. hostComponentNames: ['c0', 'c1'],
  1903. selected: true,
  1904. filtered: false
  1905. }),
  1906. Em.Object.create({
  1907. host: Em.Object.create({
  1908. publicHostName: 'h13'
  1909. }),
  1910. hostComponentNames: ['c0', 'c1'],
  1911. selected: false,
  1912. filtered: false
  1913. }),
  1914. Em.Object.create({
  1915. host: Em.Object.create({
  1916. publicHostName: 'hn14'
  1917. }),
  1918. hostComponentNames: ['c0', 'c1'],
  1919. selected: true,
  1920. filtered: false
  1921. }),
  1922. Em.Object.create({
  1923. host: Em.Object.create({
  1924. publicHostName: 'hn15'
  1925. }),
  1926. hostComponentNames: ['c0', 'c1'],
  1927. selected: false,
  1928. filtered: false
  1929. }),
  1930. Em.Object.create({
  1931. host: Em.Object.create({
  1932. publicHostName: 'h16',
  1933. osType: 'centos6'
  1934. }),
  1935. hostComponentNames: ['c0', 'c1'],
  1936. selected: true,
  1937. filterColumnValue: 'centos6',
  1938. filtered: false
  1939. }),
  1940. Em.Object.create({
  1941. host: Em.Object.create({
  1942. publicHostName: 'h17',
  1943. osType: 'centos6'
  1944. }),
  1945. hostComponentNames: ['c0', 'c1'],
  1946. selected: false,
  1947. filterColumnValue: 'centos6',
  1948. filtered: false
  1949. }),
  1950. Em.Object.create({
  1951. host: Em.Object.create({
  1952. publicHostName: 'hn18',
  1953. osType: 'centos6'
  1954. }),
  1955. hostComponentNames: ['c0', 'c1'],
  1956. selected: true,
  1957. filterColumnValue: 'centos6',
  1958. filtered: false
  1959. }),
  1960. Em.Object.create({
  1961. host: Em.Object.create({
  1962. publicHostName: 'hn19',
  1963. osType: 'centos6'
  1964. }),
  1965. hostComponentNames: ['c0', 'c1'],
  1966. selected: false,
  1967. filterColumnValue: 'centos6',
  1968. filtered: false
  1969. }),
  1970. Em.Object.create({
  1971. host: Em.Object.create({
  1972. publicHostName: 'h20',
  1973. osType: 'suse11'
  1974. }),
  1975. hostComponentNames: ['c0', 'c1'],
  1976. selected: true,
  1977. filterColumnValue: 'suse11',
  1978. filtered: false
  1979. }),
  1980. Em.Object.create({
  1981. host: Em.Object.create({
  1982. publicHostName: 'h21',
  1983. osType: 'suse11'
  1984. }),
  1985. hostComponentNames: ['c0', 'c1'],
  1986. selected: false,
  1987. filterColumnValue: 'suse11',
  1988. filtered: false
  1989. }),
  1990. Em.Object.create({
  1991. host: Em.Object.create({
  1992. publicHostName: 'hn22',
  1993. osType: 'suse11'
  1994. }),
  1995. hostComponentNames: ['c0', 'c1'],
  1996. selected: true,
  1997. filterColumnValue: 'suse11',
  1998. filtered: false
  1999. }),
  2000. Em.Object.create({
  2001. host: Em.Object.create({
  2002. publicHostName: 'hn23',
  2003. osType: 'suse11'
  2004. }),
  2005. hostComponentNames: ['c0', 'c1'],
  2006. selected: false,
  2007. filterColumnValue: 'suse11',
  2008. filtered: false
  2009. }),
  2010. Em.Object.create({
  2011. host: Em.Object.create({
  2012. publicHostName: 'h24'
  2013. }),
  2014. hostComponentNames: ['c0', 'c2'],
  2015. selected: true,
  2016. filtered: false
  2017. }),
  2018. Em.Object.create({
  2019. host: Em.Object.create({
  2020. publicHostName: 'h25'
  2021. }),
  2022. hostComponentNames: ['c0', 'c2'],
  2023. selected: false,
  2024. filtered: false
  2025. }),
  2026. Em.Object.create({
  2027. host: Em.Object.create({
  2028. publicHostName: 'hn26'
  2029. }),
  2030. hostComponentNames: ['c0', 'c2'],
  2031. selected: true,
  2032. filtered: true
  2033. }),
  2034. Em.Object.create({
  2035. host: Em.Object.create({
  2036. publicHostName: 'hn27'
  2037. }),
  2038. hostComponentNames: ['c0', 'c2'],
  2039. selected: false,
  2040. filtered: false
  2041. }),
  2042. Em.Object.create({
  2043. host: Em.Object.create({
  2044. publicHostName: 'h28',
  2045. osType: 'centos6'
  2046. }),
  2047. hostComponentNames: ['c0', 'c2'],
  2048. selected: true,
  2049. filterColumnValue: 'centos6',
  2050. filtered: true
  2051. }),
  2052. Em.Object.create({
  2053. host: Em.Object.create({
  2054. publicHostName: 'h29',
  2055. osType: 'centos6'
  2056. }),
  2057. hostComponentNames: ['c0', 'c2'],
  2058. selected: false,
  2059. filterColumnValue: 'centos6',
  2060. filtered: false
  2061. }),
  2062. Em.Object.create({
  2063. host: Em.Object.create({
  2064. publicHostName: 'hn30',
  2065. osType: 'centos6'
  2066. }),
  2067. hostComponentNames: ['c0', 'c2'],
  2068. selected: true,
  2069. filterColumnValue: 'centos6',
  2070. filtered: true
  2071. }),
  2072. Em.Object.create({
  2073. host: Em.Object.create({
  2074. publicHostName: 'hn31',
  2075. osType: 'centos6'
  2076. }),
  2077. hostComponentNames: ['c0', 'c2'],
  2078. selected: false,
  2079. filterColumnValue: 'centos6',
  2080. filtered: false
  2081. }),
  2082. Em.Object.create({
  2083. host: Em.Object.create({
  2084. publicHostName: 'h32',
  2085. osType: 'suse11'
  2086. }),
  2087. hostComponentNames: ['c0', 'c2'],
  2088. selected: true,
  2089. filterColumnValue: 'suse11',
  2090. filtered: false
  2091. }),
  2092. Em.Object.create({
  2093. host: Em.Object.create({
  2094. publicHostName: 'h33',
  2095. osType: 'suse11'
  2096. }),
  2097. hostComponentNames: ['c0', 'c2'],
  2098. selected: false,
  2099. filterColumnValue: 'suse11',
  2100. filtered: false
  2101. }),
  2102. Em.Object.create({
  2103. host: Em.Object.create({
  2104. publicHostName: 'hn34',
  2105. osType: 'suse11'
  2106. }),
  2107. hostComponentNames: ['c0', 'c2'],
  2108. selected: true,
  2109. filterColumnValue: 'suse11',
  2110. filtered: true
  2111. }),
  2112. Em.Object.create({
  2113. host: Em.Object.create({
  2114. publicHostName: 'hn35',
  2115. osType: 'suse11'
  2116. }),
  2117. hostComponentNames: ['c0', 'c2'],
  2118. selected: false,
  2119. filterColumnValue: 'suse11',
  2120. filtered: false
  2121. })
  2122. ],
  2123. title: 'filter text set, component filter set, show selected hosts only'
  2124. },
  2125. {
  2126. filterText: 'n',
  2127. filterComponent: Em.Object.create({
  2128. componentName: 'c3'
  2129. }),
  2130. showOnlySelectedHosts: false,
  2131. availableHosts: [
  2132. Em.Object.create({
  2133. host: Em.Object.create({
  2134. publicHostName: 'h0'
  2135. }),
  2136. hostComponentNames: [],
  2137. selected: true
  2138. }),
  2139. Em.Object.create({
  2140. host: Em.Object.create({
  2141. publicHostName: 'h1'
  2142. }),
  2143. hostComponentNames: [],
  2144. selected: false
  2145. }),
  2146. Em.Object.create({
  2147. host: Em.Object.create({
  2148. publicHostName: 'hn2'
  2149. }),
  2150. hostComponentNames: [],
  2151. selected: true
  2152. }),
  2153. Em.Object.create({
  2154. host: Em.Object.create({
  2155. publicHostName: 'hn3'
  2156. }),
  2157. hostComponentNames: [],
  2158. selected: false
  2159. }),
  2160. Em.Object.create({
  2161. host: Em.Object.create({
  2162. publicHostName: 'h4',
  2163. osType: 'centos6'
  2164. }),
  2165. hostComponentNames: [],
  2166. selected: true
  2167. }),
  2168. Em.Object.create({
  2169. host: Em.Object.create({
  2170. publicHostName: 'h5',
  2171. osType: 'centos6'
  2172. }),
  2173. hostComponentNames: [],
  2174. selected: false
  2175. }),
  2176. Em.Object.create({
  2177. host: Em.Object.create({
  2178. publicHostName: 'hn6',
  2179. osType: 'centos6'
  2180. }),
  2181. hostComponentNames: [],
  2182. selected: true
  2183. }),
  2184. Em.Object.create({
  2185. host: Em.Object.create({
  2186. publicHostName: 'hn7',
  2187. osType: 'centos6'
  2188. }),
  2189. hostComponentNames: [],
  2190. selected: false
  2191. }),
  2192. Em.Object.create({
  2193. host: Em.Object.create({
  2194. publicHostName: 'h8',
  2195. osType: 'suse11'
  2196. }),
  2197. hostComponentNames: [],
  2198. selected: true
  2199. }),
  2200. Em.Object.create({
  2201. host: Em.Object.create({
  2202. publicHostName: 'h9',
  2203. osType: 'suse11'
  2204. }),
  2205. hostComponentNames: [],
  2206. selected: false
  2207. }),
  2208. Em.Object.create({
  2209. host: Em.Object.create({
  2210. publicHostName: 'hn10',
  2211. osType: 'suse11'
  2212. }),
  2213. hostComponentNames: [],
  2214. selected: true
  2215. }),
  2216. Em.Object.create({
  2217. host: Em.Object.create({
  2218. publicHostName: 'hn11',
  2219. osType: 'suse11'
  2220. }),
  2221. hostComponentNames: [],
  2222. selected: false
  2223. }),
  2224. Em.Object.create({
  2225. host: Em.Object.create({
  2226. publicHostName: 'h12'
  2227. }),
  2228. hostComponentNames: ['c0', 'c1'],
  2229. selected: true
  2230. }),
  2231. Em.Object.create({
  2232. host: Em.Object.create({
  2233. publicHostName: 'h13'
  2234. }),
  2235. hostComponentNames: ['c0', 'c1'],
  2236. selected: false
  2237. }),
  2238. Em.Object.create({
  2239. host: Em.Object.create({
  2240. publicHostName: 'hn14'
  2241. }),
  2242. hostComponentNames: ['c0', 'c1'],
  2243. selected: true
  2244. }),
  2245. Em.Object.create({
  2246. host: Em.Object.create({
  2247. publicHostName: 'hn15'
  2248. }),
  2249. hostComponentNames: ['c0', 'c1'],
  2250. selected: false
  2251. }),
  2252. Em.Object.create({
  2253. host: Em.Object.create({
  2254. publicHostName: 'h16',
  2255. osType: 'centos6'
  2256. }),
  2257. hostComponentNames: ['c0', 'c1'],
  2258. selected: true
  2259. }),
  2260. Em.Object.create({
  2261. host: Em.Object.create({
  2262. publicHostName: 'h17',
  2263. osType: 'centos6'
  2264. }),
  2265. hostComponentNames: ['c0', 'c1'],
  2266. selected: false
  2267. }),
  2268. Em.Object.create({
  2269. host: Em.Object.create({
  2270. publicHostName: 'hn18',
  2271. osType: 'centos6'
  2272. }),
  2273. hostComponentNames: ['c0', 'c1'],
  2274. selected: true
  2275. }),
  2276. Em.Object.create({
  2277. host: Em.Object.create({
  2278. publicHostName: 'hn19',
  2279. osType: 'centos6'
  2280. }),
  2281. hostComponentNames: ['c0', 'c1'],
  2282. selected: false
  2283. }),
  2284. Em.Object.create({
  2285. host: Em.Object.create({
  2286. publicHostName: 'h20',
  2287. osType: 'suse11'
  2288. }),
  2289. hostComponentNames: ['c0', 'c1'],
  2290. selected: true
  2291. }),
  2292. Em.Object.create({
  2293. host: Em.Object.create({
  2294. publicHostName: 'h21',
  2295. osType: 'suse11'
  2296. }),
  2297. hostComponentNames: ['c0', 'c1'],
  2298. selected: false
  2299. }),
  2300. Em.Object.create({
  2301. host: Em.Object.create({
  2302. publicHostName: 'hn22',
  2303. osType: 'suse11'
  2304. }),
  2305. hostComponentNames: ['c0', 'c1'],
  2306. selected: true
  2307. }),
  2308. Em.Object.create({
  2309. host: Em.Object.create({
  2310. publicHostName: 'hn23',
  2311. osType: 'suse11'
  2312. }),
  2313. hostComponentNames: ['c0', 'c1'],
  2314. selected: false
  2315. }),
  2316. Em.Object.create({
  2317. host: Em.Object.create({
  2318. publicHostName: 'h24'
  2319. }),
  2320. hostComponentNames: ['c0', 'c3'],
  2321. selected: true
  2322. }),
  2323. Em.Object.create({
  2324. host: Em.Object.create({
  2325. publicHostName: 'h25'
  2326. }),
  2327. hostComponentNames: ['c0', 'c3'],
  2328. selected: false
  2329. }),
  2330. Em.Object.create({
  2331. host: Em.Object.create({
  2332. publicHostName: 'hn26'
  2333. }),
  2334. hostComponentNames: ['c0', 'c3'],
  2335. selected: true
  2336. }),
  2337. Em.Object.create({
  2338. host: Em.Object.create({
  2339. publicHostName: 'hn27'
  2340. }),
  2341. hostComponentNames: ['c0', 'c3'],
  2342. selected: false
  2343. }),
  2344. Em.Object.create({
  2345. host: Em.Object.create({
  2346. publicHostName: 'h28',
  2347. osType: 'centos6'
  2348. }),
  2349. hostComponentNames: ['c0', 'c3'],
  2350. selected: true
  2351. }),
  2352. Em.Object.create({
  2353. host: Em.Object.create({
  2354. publicHostName: 'h29',
  2355. osType: 'centos6'
  2356. }),
  2357. hostComponentNames: ['c0', 'c3'],
  2358. selected: false
  2359. }),
  2360. Em.Object.create({
  2361. host: Em.Object.create({
  2362. publicHostName: 'hn30',
  2363. osType: 'centos6'
  2364. }),
  2365. hostComponentNames: ['c0', 'c3'],
  2366. selected: true
  2367. }),
  2368. Em.Object.create({
  2369. host: Em.Object.create({
  2370. publicHostName: 'hn31',
  2371. osType: 'centos6'
  2372. }),
  2373. hostComponentNames: ['c0', 'c3'],
  2374. selected: false
  2375. }),
  2376. Em.Object.create({
  2377. host: Em.Object.create({
  2378. publicHostName: 'h32',
  2379. osType: 'suse11'
  2380. }),
  2381. hostComponentNames: ['c0', 'c3'],
  2382. selected: true
  2383. }),
  2384. Em.Object.create({
  2385. host: Em.Object.create({
  2386. publicHostName: 'h33',
  2387. osType: 'suse11'
  2388. }),
  2389. hostComponentNames: ['c0', 'c3'],
  2390. selected: false
  2391. }),
  2392. Em.Object.create({
  2393. host: Em.Object.create({
  2394. publicHostName: 'hn34',
  2395. osType: 'suse11'
  2396. }),
  2397. hostComponentNames: ['c0', 'c3'],
  2398. selected: true
  2399. }),
  2400. Em.Object.create({
  2401. host: Em.Object.create({
  2402. publicHostName: 'hn35',
  2403. osType: 'suse11'
  2404. }),
  2405. hostComponentNames: ['c0', 'c3'],
  2406. selected: false
  2407. })
  2408. ],
  2409. result: [
  2410. Em.Object.create({
  2411. host: Em.Object.create({
  2412. publicHostName: 'h0'
  2413. }),
  2414. hostComponentNames: [],
  2415. selected: true,
  2416. filtered: false
  2417. }),
  2418. Em.Object.create({
  2419. host: Em.Object.create({
  2420. publicHostName: 'h1'
  2421. }),
  2422. hostComponentNames: [],
  2423. selected: false,
  2424. filtered: false
  2425. }),
  2426. Em.Object.create({
  2427. host: Em.Object.create({
  2428. publicHostName: 'hn2'
  2429. }),
  2430. hostComponentNames: [],
  2431. selected: true,
  2432. filtered: true
  2433. }),
  2434. Em.Object.create({
  2435. host: Em.Object.create({
  2436. publicHostName: 'hn3'
  2437. }),
  2438. hostComponentNames: [],
  2439. selected: false,
  2440. filtered: true
  2441. }),
  2442. Em.Object.create({
  2443. host: Em.Object.create({
  2444. publicHostName: 'h4',
  2445. osType: 'centos6'
  2446. }),
  2447. hostComponentNames: [],
  2448. selected: true,
  2449. filterColumnValue: 'centos6',
  2450. filtered: true
  2451. }),
  2452. Em.Object.create({
  2453. host: Em.Object.create({
  2454. publicHostName: 'h5',
  2455. osType: 'centos6'
  2456. }),
  2457. hostComponentNames: [],
  2458. selected: false,
  2459. filterColumnValue: 'centos6',
  2460. filtered: true
  2461. }),
  2462. Em.Object.create({
  2463. host: Em.Object.create({
  2464. publicHostName: 'hn6',
  2465. osType: 'centos6'
  2466. }),
  2467. hostComponentNames: [],
  2468. selected: true,
  2469. filterColumnValue: 'centos6',
  2470. filtered: true
  2471. }),
  2472. Em.Object.create({
  2473. host: Em.Object.create({
  2474. publicHostName: 'hn7',
  2475. osType: 'centos6'
  2476. }),
  2477. hostComponentNames: [],
  2478. selected: false,
  2479. filterColumnValue: 'centos6',
  2480. filtered: true
  2481. }),
  2482. Em.Object.create({
  2483. host: Em.Object.create({
  2484. publicHostName: 'h8',
  2485. osType: 'suse11'
  2486. }),
  2487. hostComponentNames: [],
  2488. selected: true,
  2489. filterColumnValue: 'suse11',
  2490. filtered: false
  2491. }),
  2492. Em.Object.create({
  2493. host: Em.Object.create({
  2494. publicHostName: 'h9',
  2495. osType: 'suse11'
  2496. }),
  2497. hostComponentNames: [],
  2498. selected: false,
  2499. filterColumnValue: 'suse11',
  2500. filtered: false
  2501. }),
  2502. Em.Object.create({
  2503. host: Em.Object.create({
  2504. publicHostName: 'hn10',
  2505. osType: 'suse11'
  2506. }),
  2507. hostComponentNames: [],
  2508. selected: true,
  2509. filterColumnValue: 'suse11',
  2510. filtered: true
  2511. }),
  2512. Em.Object.create({
  2513. host: Em.Object.create({
  2514. publicHostName: 'hn11',
  2515. osType: 'suse11'
  2516. }),
  2517. hostComponentNames: [],
  2518. selected: false,
  2519. filterColumnValue: 'suse11',
  2520. filtered: true
  2521. }),
  2522. Em.Object.create({
  2523. host: Em.Object.create({
  2524. publicHostName: 'h12'
  2525. }),
  2526. hostComponentNames: ['c0', 'c1'],
  2527. selected: true,
  2528. filtered: false
  2529. }),
  2530. Em.Object.create({
  2531. host: Em.Object.create({
  2532. publicHostName: 'h13'
  2533. }),
  2534. hostComponentNames: ['c0', 'c1'],
  2535. selected: false,
  2536. filtered: false
  2537. }),
  2538. Em.Object.create({
  2539. host: Em.Object.create({
  2540. publicHostName: 'hn14'
  2541. }),
  2542. hostComponentNames: ['c0', 'c1'],
  2543. selected: true,
  2544. filtered: false
  2545. }),
  2546. Em.Object.create({
  2547. host: Em.Object.create({
  2548. publicHostName: 'hn15'
  2549. }),
  2550. hostComponentNames: ['c0', 'c1'],
  2551. selected: false,
  2552. filtered: false
  2553. }),
  2554. Em.Object.create({
  2555. host: Em.Object.create({
  2556. publicHostName: 'h16',
  2557. osType: 'centos6'
  2558. }),
  2559. hostComponentNames: ['c0', 'c1'],
  2560. selected: true,
  2561. filterColumnValue: 'centos6',
  2562. filtered: false
  2563. }),
  2564. Em.Object.create({
  2565. host: Em.Object.create({
  2566. publicHostName: 'h17',
  2567. osType: 'centos6'
  2568. }),
  2569. hostComponentNames: ['c0', 'c1'],
  2570. selected: false,
  2571. filterColumnValue: 'centos6',
  2572. filtered: false
  2573. }),
  2574. Em.Object.create({
  2575. host: Em.Object.create({
  2576. publicHostName: 'hn18',
  2577. osType: 'centos6'
  2578. }),
  2579. hostComponentNames: ['c0', 'c1'],
  2580. selected: true,
  2581. filterColumnValue: 'centos6',
  2582. filtered: false
  2583. }),
  2584. Em.Object.create({
  2585. host: Em.Object.create({
  2586. publicHostName: 'hn19',
  2587. osType: 'centos6'
  2588. }),
  2589. hostComponentNames: ['c0', 'c1'],
  2590. selected: false,
  2591. filterColumnValue: 'centos6',
  2592. filtered: false
  2593. }),
  2594. Em.Object.create({
  2595. host: Em.Object.create({
  2596. publicHostName: 'h20',
  2597. osType: 'suse11'
  2598. }),
  2599. hostComponentNames: ['c0', 'c1'],
  2600. selected: true,
  2601. filterColumnValue: 'suse11',
  2602. filtered: false
  2603. }),
  2604. Em.Object.create({
  2605. host: Em.Object.create({
  2606. publicHostName: 'h21',
  2607. osType: 'suse11'
  2608. }),
  2609. hostComponentNames: ['c0', 'c1'],
  2610. selected: false,
  2611. filterColumnValue: 'suse11',
  2612. filtered: false
  2613. }),
  2614. Em.Object.create({
  2615. host: Em.Object.create({
  2616. publicHostName: 'hn22',
  2617. osType: 'suse11'
  2618. }),
  2619. hostComponentNames: ['c0', 'c1'],
  2620. selected: true,
  2621. filterColumnValue: 'suse11',
  2622. filtered: false
  2623. }),
  2624. Em.Object.create({
  2625. host: Em.Object.create({
  2626. publicHostName: 'hn23',
  2627. osType: 'suse11'
  2628. }),
  2629. hostComponentNames: ['c0', 'c1'],
  2630. selected: false,
  2631. filterColumnValue: 'suse11',
  2632. filtered: false
  2633. }),
  2634. Em.Object.create({
  2635. host: Em.Object.create({
  2636. publicHostName: 'h24'
  2637. }),
  2638. hostComponentNames: ['c0', 'c3'],
  2639. selected: true,
  2640. filtered: false
  2641. }),
  2642. Em.Object.create({
  2643. host: Em.Object.create({
  2644. publicHostName: 'h25'
  2645. }),
  2646. hostComponentNames: ['c0', 'c3'],
  2647. selected: false,
  2648. filtered: false
  2649. }),
  2650. Em.Object.create({
  2651. host: Em.Object.create({
  2652. publicHostName: 'hn26'
  2653. }),
  2654. hostComponentNames: ['c0', 'c3'],
  2655. selected: true,
  2656. filtered: true
  2657. }),
  2658. Em.Object.create({
  2659. host: Em.Object.create({
  2660. publicHostName: 'hn27'
  2661. }),
  2662. hostComponentNames: ['c0', 'c3'],
  2663. selected: false,
  2664. filtered: true
  2665. }),
  2666. Em.Object.create({
  2667. host: Em.Object.create({
  2668. publicHostName: 'h28',
  2669. osType: 'centos6'
  2670. }),
  2671. hostComponentNames: ['c0', 'c3'],
  2672. selected: true,
  2673. filterColumnValue: 'centos6',
  2674. filtered: true
  2675. }),
  2676. Em.Object.create({
  2677. host: Em.Object.create({
  2678. publicHostName: 'h29',
  2679. osType: 'centos6'
  2680. }),
  2681. hostComponentNames: ['c0', 'c3'],
  2682. selected: false,
  2683. filterColumnValue: 'centos6',
  2684. filtered: true
  2685. }),
  2686. Em.Object.create({
  2687. host: Em.Object.create({
  2688. publicHostName: 'hn30',
  2689. osType: 'centos6'
  2690. }),
  2691. hostComponentNames: ['c0', 'c3'],
  2692. selected: true,
  2693. filterColumnValue: 'centos6',
  2694. filtered: true
  2695. }),
  2696. Em.Object.create({
  2697. host: Em.Object.create({
  2698. publicHostName: 'hn31',
  2699. osType: 'centos6'
  2700. }),
  2701. hostComponentNames: ['c0', 'c3'],
  2702. selected: false,
  2703. filterColumnValue: 'centos6',
  2704. filtered: true
  2705. }),
  2706. Em.Object.create({
  2707. host: Em.Object.create({
  2708. publicHostName: 'h32',
  2709. osType: 'suse11'
  2710. }),
  2711. hostComponentNames: ['c0', 'c3'],
  2712. selected: true,
  2713. filterColumnValue: 'suse11',
  2714. filtered: false
  2715. }),
  2716. Em.Object.create({
  2717. host: Em.Object.create({
  2718. publicHostName: 'h33',
  2719. osType: 'suse11'
  2720. }),
  2721. hostComponentNames: ['c0', 'c3'],
  2722. selected: false,
  2723. filterColumnValue: 'suse11',
  2724. filtered: false
  2725. }),
  2726. Em.Object.create({
  2727. host: Em.Object.create({
  2728. publicHostName: 'hn34',
  2729. osType: 'suse11'
  2730. }),
  2731. hostComponentNames: ['c0', 'c3'],
  2732. selected: true,
  2733. filterColumnValue: 'suse11',
  2734. filtered: true
  2735. }),
  2736. Em.Object.create({
  2737. host: Em.Object.create({
  2738. publicHostName: 'hn35',
  2739. osType: 'suse11'
  2740. }),
  2741. hostComponentNames: ['c0', 'c3'],
  2742. selected: false,
  2743. filterColumnValue: 'suse11',
  2744. filtered: true
  2745. })
  2746. ],
  2747. title: 'filter text set, component filter set, show all hosts'
  2748. }
  2749. ];
  2750. cases.forEach(function (item) {
  2751. var arrayForCheck;
  2752. it(item.title, function () {
  2753. view.setProperties({
  2754. 'showOnlySelectedHosts': item.showOnlySelectedHosts,
  2755. 'filterText': item.filterText,
  2756. 'filterComponent': item.filterComponent,
  2757. 'filterColumn': {
  2758. id: 'osType'
  2759. },
  2760. 'parentView.availableHosts': item.availableHosts
  2761. });
  2762. item.result.forEach(function (host) {
  2763. if (!host.hasOwnProperty('filterColumnValue')) {
  2764. host.set('filterColumnValue', undefined);
  2765. }
  2766. });
  2767. arrayForCheck = view.get('parentView.availableHosts').toArray();
  2768. arrayForCheck.forEach(function (host) {
  2769. var hostComponentNames = host.get('hostComponentNames');
  2770. if (host.get('hostComponentNames')) {
  2771. host.set('hostComponentNames', hostComponentNames.toArray());
  2772. }
  2773. });
  2774. expect(arrayForCheck).to.eql(item.result);
  2775. });
  2776. });
  2777. it('start index', function () {
  2778. view.set('startIndex', 0);
  2779. view.propertyDidChange('filterColumn');
  2780. expect(view.get('startIndex')).to.equal(1);
  2781. });
  2782. });
  2783. describe('#hostSelectMessage', function () {
  2784. beforeEach(function () {
  2785. sinon.stub(view, 'filterHosts', Em.K);
  2786. sinon.stub(view, 'filteredContentObs', Em.K);
  2787. sinon.stub(view, 'filteredContentObsOnce', Em.K);
  2788. });
  2789. afterEach(function () {
  2790. view.filterHosts.restore();
  2791. view.filteredContentObs.restore();
  2792. view.filteredContentObsOnce.restore();
  2793. });
  2794. it('correct message formatting', function () {
  2795. view.set('parentView.availableHosts', [
  2796. {
  2797. selected: true
  2798. },
  2799. {
  2800. selected: false
  2801. },
  2802. {
  2803. selected: true
  2804. }
  2805. ]);
  2806. expect(view.get('hostSelectMessage')).to.equal(Em.I18n.t('hosts.selectHostsDialog.selectedHostsLink').format(2, 3));
  2807. });
  2808. });
  2809. describe('#selectFilterColumn', function () {
  2810. var columnObject = {
  2811. selected: true
  2812. },
  2813. cases = [
  2814. {
  2815. event: null,
  2816. filterColumn: Em.Object.create(columnObject),
  2817. isPreviousColumnSelected: true,
  2818. title: 'no event data'
  2819. },
  2820. {
  2821. event: {},
  2822. filterColumn: Em.Object.create(columnObject),
  2823. isPreviousColumnSelected: true,
  2824. title: 'no context'
  2825. },
  2826. {
  2827. event: {
  2828. context: null
  2829. },
  2830. filterColumn: Em.Object.create(columnObject),
  2831. isPreviousColumnSelected: true,
  2832. title: 'empty context'
  2833. },
  2834. {
  2835. event: {
  2836. context: Em.Object.create()
  2837. },
  2838. filterColumn: Em.Object.create(columnObject),
  2839. isPreviousColumnSelected: true,
  2840. title: 'no id'
  2841. },
  2842. {
  2843. event: {
  2844. context: Em.Object.create({
  2845. id: null
  2846. })
  2847. },
  2848. filterColumn: Em.Object.create(columnObject),
  2849. isPreviousColumnSelected: true,
  2850. title: 'invalid id'
  2851. },
  2852. {
  2853. event: {
  2854. context: Em.Object.create({
  2855. id: 0
  2856. })
  2857. },
  2858. filterColumn: Em.Object.create({
  2859. id: 0,
  2860. selected: true
  2861. }),
  2862. isPreviousColumnSelected: false,
  2863. title: 'valid id'
  2864. }
  2865. ];
  2866. cases.forEach(function (item) {
  2867. describe(item.title, function () {
  2868. var column = Em.Object.create(columnObject);
  2869. beforeEach(function () {
  2870. view.set('filterColumn', column);
  2871. view.selectFilterColumn(item.event);
  2872. });
  2873. it('new column', function () {
  2874. expect(view.get('filterColumn')).to.eql(item.filterColumn);
  2875. });
  2876. it('should deselect previous column', function () {
  2877. expect(column.get('selected')).to.equal(item.isPreviousColumnSelected);
  2878. });
  2879. });
  2880. });
  2881. });
  2882. describe('#selectFilterComponent', function () {
  2883. var componentObject = {
  2884. selected: true
  2885. },
  2886. cases = [
  2887. {
  2888. event: null,
  2889. filterComponent: Em.Object.create(componentObject),
  2890. title: 'no event data'
  2891. },
  2892. {
  2893. event: {},
  2894. filterComponent: Em.Object.create(componentObject),
  2895. title: 'no context'
  2896. },
  2897. {
  2898. event: {
  2899. context: null
  2900. },
  2901. filterComponent: Em.Object.create(componentObject),
  2902. title: 'empty context'
  2903. },
  2904. {
  2905. event: {
  2906. context: Em.Object.create()
  2907. },
  2908. filterComponent: Em.Object.create(componentObject),
  2909. title: 'no component name'
  2910. },
  2911. {
  2912. event: {
  2913. context: Em.Object.create({
  2914. componentName: null
  2915. })
  2916. },
  2917. filterComponent: Em.Object.create(componentObject),
  2918. title: 'invalid component name'
  2919. },
  2920. {
  2921. event: {
  2922. context: Em.Object.create({
  2923. componentName: 'c0'
  2924. })
  2925. },
  2926. filterComponent: Em.Object.create({
  2927. componentName: 'c0',
  2928. selected: true
  2929. }),
  2930. title: 'valid component name'
  2931. },
  2932. {
  2933. event: {
  2934. context: Em.Object.create({
  2935. componentName: 'c0'
  2936. })
  2937. },
  2938. previousFilterComponent: Em.Object.create({
  2939. componentName: 'c0',
  2940. selected: true
  2941. }),
  2942. filterComponent: null,
  2943. title: 'manual deselection'
  2944. },
  2945. {
  2946. event: {
  2947. context: Em.Object.create({
  2948. componentName: 'c0'
  2949. })
  2950. },
  2951. previousFilterComponent: Em.Object.create({
  2952. componentName: 'c1',
  2953. selected: true
  2954. }),
  2955. filterComponent: Em.Object.create({
  2956. componentName: 'c0',
  2957. selected: true
  2958. }),
  2959. title: 'no manual deselection'
  2960. }
  2961. ];
  2962. cases.forEach(function (item) {
  2963. it(item.title, function () {
  2964. var component = item.previousFilterComponent || Em.Object.create(componentObject);
  2965. view.set('filterComponent', component);
  2966. view.selectFilterComponent(item.event);
  2967. expect(view.get('filterComponent')).to.eql(item.filterComponent);
  2968. });
  2969. });
  2970. });
  2971. describe('#toggleSelectAllHosts', function () {
  2972. var cases = [
  2973. {
  2974. allHostsSelected: true,
  2975. availableHosts: [
  2976. {
  2977. host: {
  2978. id: 'h0'
  2979. },
  2980. filtered: true,
  2981. selected: true
  2982. },
  2983. {
  2984. host: {
  2985. id: 'h1'
  2986. },
  2987. filtered: false
  2988. },
  2989. {
  2990. host: {
  2991. id: 'h2'
  2992. },
  2993. filtered: 'true',
  2994. selected: true
  2995. },
  2996. {
  2997. host: {
  2998. id: 'h3'
  2999. },
  3000. filtered: 1,
  3001. selected: true
  3002. },
  3003. {
  3004. host: {
  3005. id: 'h4'
  3006. }
  3007. }
  3008. ],
  3009. title: 'select all hosts'
  3010. },
  3011. {
  3012. allHostsSelected: false,
  3013. availableHosts: [
  3014. {
  3015. host: {
  3016. id: 'h0'
  3017. },
  3018. filtered: true,
  3019. selected: false
  3020. },
  3021. {
  3022. host: {
  3023. id: 'h1'
  3024. },
  3025. filtered: false
  3026. },
  3027. {
  3028. host: {
  3029. id: 'h2'
  3030. },
  3031. filtered: 'true',
  3032. selected: false
  3033. },
  3034. {
  3035. host: {
  3036. id: 'h3'
  3037. },
  3038. filtered: 1,
  3039. selected: false
  3040. },
  3041. {
  3042. host: {
  3043. id: 'h4'
  3044. }
  3045. }
  3046. ],
  3047. title: 'deselect all hosts'
  3048. }
  3049. ];
  3050. beforeEach(function () {
  3051. sinon.stub(view, 'filterHosts', Em.K);
  3052. sinon.stub(view, 'filteredContentObs', Em.K);
  3053. sinon.stub(view, 'filteredContentObsOnce', Em.K);
  3054. });
  3055. afterEach(function () {
  3056. view.filterHosts.restore();
  3057. view.filteredContentObs.restore();
  3058. view.filteredContentObsOnce.restore();
  3059. });
  3060. cases.forEach(function (item) {
  3061. it(item.title, function () {
  3062. view.setProperties({
  3063. 'allHostsSelected': !item.allHostsSelected,
  3064. 'parentView.availableHosts': [
  3065. {
  3066. host: {
  3067. id: 'h0'
  3068. },
  3069. filtered: true
  3070. },
  3071. {
  3072. host: {
  3073. id: 'h1'
  3074. },
  3075. filtered: false
  3076. },
  3077. {
  3078. host: {
  3079. id: 'h2'
  3080. },
  3081. filtered: 'true'
  3082. },
  3083. {
  3084. host: {
  3085. id: 'h3'
  3086. },
  3087. filtered: 1
  3088. },
  3089. {
  3090. host: {
  3091. id: 'h4'
  3092. }
  3093. }
  3094. ]
  3095. });
  3096. view.toggleProperty('allHostsSelected');
  3097. expect(view.get('parentView.availableHosts').toArray()).to.eql(item.availableHosts);
  3098. });
  3099. });
  3100. });
  3101. describe('#toggleShowSelectedHosts', function () {
  3102. var cases = [
  3103. {
  3104. showOnlySelectedHosts: true,
  3105. title: 'no component for filter'
  3106. },
  3107. {
  3108. showOnlySelectedHosts: false,
  3109. filterComponent: null,
  3110. title: 'empty component for filter'
  3111. },
  3112. {
  3113. showOnlySelectedHosts: true,
  3114. filterComponent: Em.Object.create(),
  3115. title: 'component for filter set'
  3116. }
  3117. ];
  3118. cases.forEach(function (item) {
  3119. describe(item.title, function () {
  3120. beforeEach(function () {
  3121. view.setProperties({
  3122. showOnlySelectedHosts: item.showOnlySelectedHosts,
  3123. filterComponent: item.filterComponent,
  3124. filterText: ''
  3125. });
  3126. view.toggleShowSelectedHosts();
  3127. });
  3128. it('clear component filter', function () {
  3129. expect(view.get('filterComponent')).to.be.null;
  3130. });
  3131. it('clear text filter', function () {
  3132. expect(view.get('filterText')).to.be.null;
  3133. });
  3134. it('toggle hosts display mode', function () {
  3135. expect(view.get('showOnlySelectedHosts')).to.equal(!item.showOnlySelectedHosts);
  3136. });
  3137. });
  3138. });
  3139. });
  3140. });
  3141. });
  3142. describe('#setRackInfo', function () {
  3143. beforeEach(function () {
  3144. sinon.stub(App.ModalPopup, 'show', function (obj) {
  3145. return Em.Object.create(obj);
  3146. });
  3147. });
  3148. afterEach(function () {
  3149. App.ModalPopup.show.restore();
  3150. });
  3151. describe('#bodyClass', function () {
  3152. describe('#validation', function () {
  3153. var popup,
  3154. view,
  3155. cases = [
  3156. {
  3157. isValidRackId: false,
  3158. errorMessage: Em.I18n.t('hostPopup.setRackId.invalid'),
  3159. disablePrimary: true,
  3160. title: 'invalid rack id'
  3161. },
  3162. {
  3163. isValidRackId: true,
  3164. errorMessage: '',
  3165. disablePrimary: false,
  3166. title: 'valid rack id'
  3167. }
  3168. ];
  3169. cases.forEach(function (item) {
  3170. describe(item.title, function () {
  3171. beforeEach(function () {
  3172. sinon.stub(validator, 'isValidRackId').returns(item.isValidRackId);
  3173. popup = hostsUtils.setRackInfo(null, [], '');
  3174. view = popup.get('bodyClass').create({
  3175. parentView: popup
  3176. });
  3177. view.propertyDidChange('parentView.rackId');
  3178. });
  3179. afterEach(function () {
  3180. validator.isValidRackId.restore();
  3181. });
  3182. it('isValid', function () {
  3183. expect(view.get('isValid')).to.equal(item.isValidRackId);
  3184. });
  3185. it('errorMessage', function () {
  3186. expect(view.get('errorMessage')).to.equal(item.errorMessage);
  3187. });
  3188. it('disablePrimary', function () {
  3189. expect(view.get('parentView.disablePrimary')).to.equal(item.disablePrimary);
  3190. });
  3191. });
  3192. });
  3193. });
  3194. });
  3195. describe('#onPrimary', function () {
  3196. var popup,
  3197. cases = [
  3198. {
  3199. hosts: [],
  3200. ajaxCallArguments: undefined,
  3201. title: 'no hosts'
  3202. },
  3203. {
  3204. hosts: [
  3205. {
  3206. hostName: 'h0'
  3207. },
  3208. {
  3209. hostName: 'h1'
  3210. }
  3211. ],
  3212. ajaxCallArguments: [{
  3213. name: 'bulk_request.hosts.update_rack_id',
  3214. sender: hostsUtils,
  3215. data: {
  3216. hostNames: 'h0,h1',
  3217. requestInfo: 'msg',
  3218. rackId: '/default-rack',
  3219. hostNamesArray: ['h0', 'h1']
  3220. },
  3221. success: 'successRackId',
  3222. error: 'errorRackId'
  3223. }],
  3224. title: 'hosts passed'
  3225. }
  3226. ];
  3227. cases.forEach(function (item) {
  3228. describe(item.title, function () {
  3229. beforeEach(function () {
  3230. popup = hostsUtils.setRackInfo({
  3231. message: 'msg'
  3232. }, item.hosts, '/default-rack');
  3233. popup.set('hide', Em.K);
  3234. sinon.spy(popup, 'hide');
  3235. popup.onPrimary();
  3236. });
  3237. afterEach(function () {
  3238. popup.hide.restore();
  3239. });
  3240. it('AJAX call', function () {
  3241. expect(testHelpers.findAjaxRequest('name', 'bulk_request.hosts.update_rack_id')).to.eql(item.ajaxCallArguments);
  3242. });
  3243. it('hide popup', function () {
  3244. expect(popup.hide.calledOnce).to.be.true;
  3245. });
  3246. });
  3247. });
  3248. });
  3249. });
  3250. describe('#successRackId', function () {
  3251. var hosts = [
  3252. Em.Object.create({
  3253. hostName: 'h0'
  3254. }),
  3255. Em.Object.create({
  3256. hostName: 'h1'
  3257. }),
  3258. Em.Object.create({
  3259. hostName: 'h2'
  3260. })
  3261. ];
  3262. beforeEach(function () {
  3263. sinon.stub(App.Host, 'find').returns(hosts);
  3264. });
  3265. afterEach(function () {
  3266. App.Host.find.restore();
  3267. });
  3268. it('should set rack ids for the proper hosts', function () {
  3269. hostsUtils.successRackId(null, null, {
  3270. hostNamesArray: ['h0', 'h2'],
  3271. rackId: '/default-rack'
  3272. });
  3273. expect(hosts).to.eql([
  3274. Em.Object.create({
  3275. hostName: 'h0',
  3276. rack: '/default-rack'
  3277. }),
  3278. Em.Object.create({
  3279. hostName: 'h1'
  3280. }),
  3281. Em.Object.create({
  3282. hostName: 'h2',
  3283. rack: '/default-rack'
  3284. })
  3285. ]);
  3286. });
  3287. });
  3288. describe('#errorRackId', function () {
  3289. beforeEach(function () {
  3290. sinon.stub(App, 'showAlertPopup', Em.K);
  3291. });
  3292. afterEach(function () {
  3293. App.showAlertPopup.restore();
  3294. });
  3295. it('should show alert popup', function () {
  3296. hostsUtils.errorRackId();
  3297. expect(App.showAlertPopup.calledOnce).to.be.true;
  3298. });
  3299. });
  3300. });