host_progress_popup_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('controllers/global/background_operations_controller');
  21. require('views/common/modal_popup');
  22. require('utils/helper');
  23. require('utils/host_progress_popup');
  24. describe('App.HostPopup', function () {
  25. var services = [
  26. {
  27. displayName: "Start service WebHCat",
  28. hosts: [
  29. {
  30. logTasks: [
  31. {
  32. Tasks: {
  33. command: "START",
  34. host_name: "ip-10-12-123-90.ec2.internal",
  35. role: "WEBHCAT_SERVER",
  36. status: "QUEUED"
  37. },
  38. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/23/tasks/94"
  39. }
  40. ],
  41. name: "ip-10-12-123-90.ec2.internal",
  42. publicName: "ip-10-12-123-90.ec2.internal",
  43. serviceName: "Start service WebHCat"
  44. }
  45. ],
  46. isRunning: false
  47. },
  48. {
  49. displayName: "Start service Hive/HCat",
  50. hosts: [
  51. {
  52. logTasks: [
  53. {
  54. Tasks: {
  55. command: "INSTALL",
  56. host_name: "ip-10-12-123-90.ec2.internal",
  57. status: "COMPLETED"
  58. },
  59. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/76"
  60. }
  61. ],
  62. name: "ip-10-12-123-90.ec2.internal",
  63. publicName: "ip-10-12-123-90.ec2.internal",
  64. serviceName: "Start service Hive/HCat"
  65. },
  66. {
  67. logTasks: [
  68. {
  69. Tasks: {
  70. command: "START",
  71. host_name: "ip-10-33-7-23.ec2.internal",
  72. status: "COMPLETED"
  73. },
  74. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/78"
  75. },
  76. {
  77. Tasks: {
  78. command: "START",
  79. host_name: "ip-10-33-7-23.ec2.internal",
  80. status: "COMPLETED"
  81. },
  82. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/79"
  83. }
  84. ],
  85. name: "ip-10-33-7-23.ec2.internal",
  86. publicName: "ip-10-33-7-23.ec2.internal",
  87. serviceName: "Start service Hive/HCat"
  88. }
  89. ],
  90. isRunning: false
  91. }
  92. ];
  93. var test_tasks = [
  94. {
  95. t: [
  96. {
  97. Tasks: {
  98. status: 'COMPLETED',
  99. id: 2
  100. }
  101. },
  102. {
  103. Tasks: {
  104. status: 'COMPLETED',
  105. id: 3
  106. }
  107. },
  108. {
  109. Tasks: {
  110. status: 'COMPLETED',
  111. id: 1
  112. }
  113. }
  114. ],
  115. m: 'All COMPLETED',
  116. r: 'SUCCESS',
  117. p: 100,
  118. ids: [1,2,3]
  119. },
  120. {
  121. t: [
  122. {
  123. Tasks: {
  124. status: 'FAILED',
  125. id: 2
  126. }
  127. },
  128. {
  129. Tasks: {
  130. status: 'COMPLETED',
  131. id: 1
  132. }
  133. }
  134. ,
  135. {
  136. Tasks: {
  137. status: 'COMPLETED',
  138. id: 3
  139. }
  140. }
  141. ],
  142. m: 'One FAILED',
  143. r: 'FAILED',
  144. p: 100,
  145. ids: [1,2,3]
  146. },
  147. {
  148. t: [
  149. {
  150. Tasks: {
  151. status: 'ABORTED',
  152. id: 1
  153. }
  154. },
  155. {
  156. Tasks: {
  157. status: 'COMPLETED',
  158. id: 2
  159. }
  160. }
  161. ],
  162. m: 'One ABORTED',
  163. r: 'ABORTED',
  164. p: 100,
  165. ids: [1,2]
  166. },
  167. {
  168. t: [
  169. {
  170. Tasks: {
  171. status: 'TIMEDOUT',
  172. id: 3
  173. }
  174. },
  175. {
  176. Tasks: {
  177. status: 'COMPLETED',
  178. id: 1
  179. }
  180. }
  181. ],
  182. m: 'One TIMEDOUT',
  183. r: 'TIMEDOUT',
  184. p: 100,
  185. ids: [1,3]
  186. },
  187. {
  188. t: [
  189. {
  190. Tasks: {
  191. status: 'IN_PROGRESS',
  192. id: 1
  193. }
  194. },
  195. {
  196. Tasks: {
  197. status: 'COMPLETED',
  198. id: 2
  199. }
  200. }
  201. ],
  202. m: 'One IN_PROGRESS',
  203. r: 'IN_PROGRESS',
  204. p: 68,
  205. ids: [1,2]
  206. },
  207. {
  208. t: [
  209. {
  210. Tasks: {
  211. status: 'QUEUED',
  212. id: 2
  213. }
  214. },
  215. {
  216. Tasks: {
  217. status: 'COMPLETED',
  218. id: 3
  219. }
  220. }
  221. ],
  222. m: 'Something else',
  223. r: 'PENDING',
  224. p: 55,
  225. ids: [2,3]
  226. }
  227. ];
  228. var statusCases = [
  229. {
  230. status: 'FAILED',
  231. result: false
  232. },
  233. {
  234. status: 'ABORTED',
  235. result: false
  236. },
  237. {
  238. status: 'TIMEDOUT',
  239. result: false
  240. },
  241. {
  242. status: 'IN_PROGRESS',
  243. result: true
  244. },
  245. {
  246. status: 'COMPLETED',
  247. result: false
  248. },
  249. {
  250. status: 'PENDING',
  251. result: true
  252. }
  253. ];
  254. describe('#setSelectCount', function () {
  255. var itemsForStatusTest = [
  256. {
  257. title: 'Empty',
  258. data: [],
  259. result: [0, 0, 0, 0, 0, 0, 0]
  260. },
  261. {
  262. title: 'All Pending',
  263. data: [
  264. {status: 'pending'},
  265. {status: 'queued'}
  266. ],
  267. result: [2, 2, 0, 0, 0, 0, 0]
  268. },
  269. {
  270. title: 'All Completed',
  271. data: [
  272. {status: 'success'},
  273. {status: 'completed'}
  274. ],
  275. result: [2, 0, 0, 0, 2, 0, 0]
  276. },
  277. {
  278. title: 'All Failed',
  279. data: [
  280. {status: 'failed'},
  281. {status: 'failed'}
  282. ],
  283. result: [2, 0, 0, 2, 0, 0, 0]
  284. },
  285. {
  286. title: 'All InProgress',
  287. data: [
  288. {status: 'in_progress'},
  289. {status: 'in_progress'}
  290. ],
  291. result: [2, 0, 2, 0, 0, 0, 0]
  292. },
  293. {
  294. title: 'All Aborted',
  295. data: [
  296. {status: 'aborted'},
  297. {status: 'aborted'}
  298. ],
  299. result: [2, 0, 0, 0, 0, 2, 0]
  300. },
  301. {
  302. title: 'All Timedout',
  303. data: [
  304. {status: 'timedout'},
  305. {status: 'timedout'}
  306. ],
  307. result: [2, 0, 0, 0, 0, 0, 2]
  308. },
  309. {
  310. title: 'Every Category',
  311. data: [
  312. {status: 'pending'},
  313. {status: 'queued'},
  314. {status: 'success'},
  315. {status: 'completed'},
  316. {status: 'failed'},
  317. {status: 'in_progress'},
  318. {status: 'aborted'},
  319. {status: 'timedout'}
  320. ],
  321. result: [8, 2, 1, 1, 2, 1, 1]
  322. }
  323. ];
  324. var categories = [
  325. Ember.Object.create({value: 'all'}),
  326. Ember.Object.create({value: 'pending'}),
  327. Ember.Object.create({value: 'in_progress'}),
  328. Ember.Object.create({value: 'failed'}),
  329. Ember.Object.create({value: 'completed'}),
  330. Ember.Object.create({value: 'aborted'}),
  331. Ember.Object.create({value: 'timedout'})
  332. ];
  333. itemsForStatusTest.forEach(function(statusTest) {
  334. it(statusTest.title, function() {
  335. App.HostPopup.setSelectCount(statusTest.data, categories);
  336. expect(categories.mapProperty('count')).to.deep.equal(statusTest.result);
  337. });
  338. });
  339. });
  340. describe('#getStatus', function() {
  341. test_tasks.forEach(function(test_task) {
  342. it(test_task.m, function() {
  343. expect(App.HostPopup.getStatus(test_task.t)[0]).to.equal(test_task.r);
  344. });
  345. });
  346. });
  347. describe('#getProgress', function() {
  348. test_tasks.forEach(function(test_task) {
  349. it(test_task.m, function() {
  350. expect(App.HostPopup.getProgress(test_task.t)).to.equal(test_task.p);
  351. });
  352. });
  353. });
  354. describe('#isAbortableByStatus', function () {
  355. statusCases.forEach(function (item) {
  356. it('should return ' + item.result + ' for ' + item.status, function () {
  357. expect(App.HostPopup.isAbortableByStatus(item.status)).to.equal(item.result);
  358. });
  359. });
  360. });
  361. describe('#abortRequest', function () {
  362. beforeEach(function () {
  363. sinon.stub(App.ajax, 'send', Em.K);
  364. sinon.spy(App, 'showConfirmationPopup');
  365. });
  366. afterEach(function () {
  367. App.ajax.send.restore();
  368. App.showConfirmationPopup.restore();
  369. });
  370. it('should show confirmation popup', function () {
  371. App.HostPopup.abortRequest(Em.Object.create({
  372. name: 'name'
  373. }));
  374. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  375. });
  376. });
  377. describe('#abortRequestSuccessCallback', function () {
  378. beforeEach(function () {
  379. sinon.spy(App.ModalPopup, 'show');
  380. });
  381. afterEach(function () {
  382. App.ModalPopup.show.restore();
  383. });
  384. it('should open popup', function () {
  385. App.HostPopup.abortRequestSuccessCallback(null, null, {
  386. requestName: 'name',
  387. serviceInfo: Em.Object.create()
  388. });
  389. expect(App.ModalPopup.show.calledOnce).to.be.true;
  390. });
  391. });
  392. describe('#abortRequestErrorCallback', function () {
  393. var popup = App.HostPopup;
  394. beforeEach(function () {
  395. sinon.stub(App.ajax, 'get', function(k) {
  396. if (k === 'modalPopup') return null;
  397. return Em.get(App, k);
  398. });
  399. sinon.spy(App.ModalPopup, 'show');
  400. });
  401. afterEach(function () {
  402. App.ModalPopup.show.restore();
  403. App.ajax.get.restore();
  404. });
  405. it('should open popup', function () {
  406. popup.abortRequestErrorCallback({
  407. responseText: {
  408. message: 'message'
  409. },
  410. status: 404
  411. }, 'status', 'error', {
  412. url: 'url'
  413. }, {
  414. requestId: 0,
  415. serviceInfo: Em.Object.create()
  416. });
  417. expect(App.ModalPopup.show.calledOnce).to.be.true;
  418. });
  419. statusCases.forEach(function (item) {
  420. it('should set serviceInfo.isAbortable to' + item.result + ' if status is ' + item.status, function () {
  421. popup.abortRequestErrorCallback({
  422. responseText: {
  423. message: 'message'
  424. },
  425. status: 404
  426. }, 'status', 'error', {
  427. url: 'url'
  428. }, {
  429. requestId: 0,
  430. serviceInfo: Em.Object.create({
  431. status: item.status
  432. })
  433. });
  434. expect(App.HostPopup.isAbortableByStatus(item.status)).to.equal(item.result);
  435. });
  436. });
  437. });
  438. describe('#setBackgroundOperationHeader', function(){
  439. beforeEach(function (){
  440. sinon.stub(App.HostPopup, "get").returns(true);
  441. sinon.spy(App.HostPopup, "set");
  442. });
  443. afterEach(function (){
  444. App.HostPopup.get.restore();
  445. App.HostPopup.set.restore();
  446. App.router.get.restore();
  447. });
  448. it("should display '2 Background Operations Running' when there are 2 background operations running", function(){
  449. sinon.stub(App.router, "get").returns(2);
  450. App.HostPopup.setBackgroundOperationHeader(false);
  451. expect(App.HostPopup.set.calledWith("popupHeaderName", "2 Background Operations Running")).to.be.true;
  452. });
  453. it("should display '1 Background Operation Running' when there is 1 background operation running", function(){
  454. sinon.stub(App.router, "get").returns(1);
  455. App.HostPopup.setBackgroundOperationHeader(false);
  456. expect(App.HostPopup.set.calledWith("popupHeaderName", "1 Background Operation Running")).to.be.true;
  457. });
  458. });
  459. });