hostLogPopupBody_view_test.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('views/wizard/step9/hostLogPopupBody_view');
  20. var view;
  21. describe('App.WizardStep9HostLogPopupBodyView', function() {
  22. beforeEach(function() {
  23. view = App.WizardStep9HostLogPopupBodyView.create({
  24. parentView: Em.Object.create({
  25. host: Em.Object.create()
  26. })
  27. });
  28. });
  29. describe('#isHeartbeatLost', function() {
  30. it('should depends on parentView.host.status', function() {
  31. view.set('parentView.host.status', 'success');
  32. expect(view.get('isHeartbeatLost')).to.equal(false);
  33. view.set('parentView.host.status', 'heartbeat_lost');
  34. expect(view.get('isHeartbeatLost')).to.equal(true);
  35. });
  36. });
  37. describe('#isNoTasksScheduled', function() {
  38. it('should be same to parentView.host.isNoTasksForInstall', function() {
  39. view.set('parentView.host.isNoTasksForInstall', true);
  40. expect(view.get('isNoTasksScheduled')).to.equal(true);
  41. view.set('parentView.host.isNoTasksForInstall', false);
  42. expect(view.get('isNoTasksScheduled')).to.equal(false);
  43. });
  44. });
  45. describe('#visibleTasks', function() {
  46. Em.A([
  47. {
  48. value: 'pending',
  49. f: ['pending', 'queued']
  50. },
  51. {
  52. value: 'in_progress',
  53. f: ['in_progress']
  54. },
  55. {
  56. value: 'failed',
  57. f: ['failed']
  58. },
  59. {
  60. value: 'completed',
  61. f: ['completed']
  62. },
  63. {
  64. value: 'aborted',
  65. f: ['aborted']
  66. },
  67. {
  68. value: 'timedout',
  69. f: ['timedout']
  70. },
  71. {
  72. value: 'all'
  73. }
  74. ]).forEach(function(test) {
  75. it(test.value, function() {
  76. view.reopen({
  77. category: Em.Object.create({value: test.value}),
  78. tasks: Em.A([
  79. {status: 'pending', isVisible: false},
  80. {status: 'queued', isVisible: false},
  81. {status: 'in_progress', isVisible: false},
  82. {status: 'failed', isVisible: false},
  83. {status: 'completed', isVisible: false},
  84. {status: 'aborted', isVisible: false},
  85. {status: 'timedout', isVisible: false}
  86. ])
  87. });
  88. view.visibleTasks();
  89. var visibleTasks = view.get('tasks').filter(function(task) {
  90. if (test.f) {
  91. return test.f.contains(task.status);
  92. }
  93. return true;
  94. });
  95. expect(visibleTasks.everyProperty('isVisible', true)).to.equal(true);
  96. });
  97. });
  98. });
  99. describe('#backToTaskList', function() {
  100. it('should call destroyClipBoard', function() {
  101. sinon.stub(view, 'destroyClipBoard', Em.K);
  102. view.backToTaskList();
  103. expect(view.destroyClipBoard.calledOnce).to.equal(true);
  104. view.destroyClipBoard.restore();
  105. });
  106. it('should set isLogWrapHidden to true', function() {
  107. view.set('isLogWrapHidden', false);
  108. view.backToTaskList();
  109. expect(view.get('isLogWrapHidden')).to.equal(true);
  110. });
  111. });
  112. describe('#getStartedTasks', function() {
  113. it('should return tasks with some status', function() {
  114. var logTasks = Em.A([
  115. {Tasks: {}}, {Tasks: {status: 's'}}, {Tasks: {status: null}}, {Tasks: {status: 'v'}}
  116. ]);
  117. expect(view.getStartedTasks({logTasks: logTasks}).length).to.equal(2);
  118. });
  119. });
  120. describe('#openedTask', function() {
  121. it('should return currently open task', function() {
  122. var task = Em.Object.create({id: 2});
  123. view.reopen({
  124. tasks: Em.A([
  125. Em.Object.create({id: 1}),
  126. Em.Object.create({id: 3}),
  127. task,
  128. Em.Object.create({id: 4})
  129. ])
  130. });
  131. view.set('parentView.c', {currentOpenTaskId: 2});
  132. expect(view.get('openedTask.id')).to.equal(2);
  133. });
  134. });
  135. describe('#tasks', function() {
  136. var testTask = {
  137. Tasks: {
  138. status: 'init',
  139. id: 1,
  140. request_id: 2,
  141. role: 'PIG',
  142. stderr: 'stderr',
  143. stdout: 'stdout',
  144. host_name: 'host1',
  145. command: 'Cmd'
  146. }
  147. };
  148. it('should map tasks', function() {
  149. view.set('parentView.host.logTasks', [testTask]);
  150. var t = view.get('tasks');
  151. expect(t.length).to.equal(1);
  152. var first = t[0];
  153. expect(first.get('id')).to.equal(1);
  154. expect(first.get('requestId')).to.equal(2);
  155. expect(first.get('command')).to.equal('cmd');
  156. expect(first.get('role')).to.equal('Pig');
  157. expect(first.get('stderr')).to.equal('stderr');
  158. expect(first.get('stdout')).to.equal('stdout');
  159. expect(first.get('isVisible')).to.equal(true);
  160. expect(first.get('hostName')).to.equal('host1');
  161. });
  162. it('should set cog icon', function() {
  163. var t = Em.copy(testTask);
  164. t.Tasks.status = 'pending';
  165. view.set('parentView.host.logTasks', [t]);
  166. var first = view.get('tasks')[0];
  167. expect(first.get('icon')).to.equal('icon-cog');
  168. });
  169. it('should set cog icon (2)', function() {
  170. var t = Em.copy(testTask);
  171. t.Tasks.status = 'queued';
  172. view.set('parentView.host.logTasks', [t]);
  173. var first = view.get('tasks')[0];
  174. expect(first.get('icon')).to.equal('icon-cog');
  175. });
  176. it('should set cogs icon', function() {
  177. var t = Em.copy(testTask);
  178. t.Tasks.status = 'in_progress';
  179. view.set('parentView.host.logTasks', [t]);
  180. var first = view.get('tasks')[0];
  181. expect(first.get('icon')).to.equal('icon-cogs');
  182. });
  183. it('should set ok icon', function() {
  184. var t = Em.copy(testTask);
  185. t.Tasks.status = 'completed';
  186. view.set('parentView.host.logTasks', [t]);
  187. var first = view.get('tasks')[0];
  188. expect(first.get('icon')).to.equal('icon-ok');
  189. });
  190. it('should set icon-exclamation-sign icon', function() {
  191. var t = Em.copy(testTask);
  192. t.Tasks.status = 'failed';
  193. view.set('parentView.host.logTasks', [t]);
  194. var first = view.get('tasks')[0];
  195. expect(first.get('icon')).to.equal('icon-exclamation-sign');
  196. });
  197. it('should set minus icon', function() {
  198. var t = Em.copy(testTask);
  199. t.Tasks.status = 'aborted';
  200. view.set('parentView.host.logTasks', [t]);
  201. var first = view.get('tasks')[0];
  202. expect(first.get('icon')).to.equal('icon-minus');
  203. });
  204. it('should set time icon', function() {
  205. var t = Em.copy(testTask);
  206. t.Tasks.status = 'timedout';
  207. view.set('parentView.host.logTasks', [t]);
  208. var first = view.get('tasks')[0];
  209. expect(first.get('icon')).to.equal('icon-time');
  210. });
  211. });
  212. describe('#toggleTaskLog', function() {
  213. it('isLogWrapHidden is true', function() {
  214. var taskInfo = {
  215. id: 1,
  216. requestId: 2
  217. };
  218. view.set('isLogWrapHidden', true);
  219. view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K}));
  220. sinon.spy(view.get('parentView.c'), 'loadCurrentTaskLog');
  221. view.toggleTaskLog({context: taskInfo});
  222. expect(view.get('isLogWrapHidden')).to.equal(false);
  223. expect(view.get('parentView.c.currentOpenTaskId')).to.equal(taskInfo.id);
  224. expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(taskInfo.requestId);
  225. expect(view.get('parentView.c').loadCurrentTaskLog.calledOnce).to.equal(true);
  226. view.get('parentView.c').loadCurrentTaskLog.restore();
  227. });
  228. it('isLogWrapHidden is false', function() {
  229. var taskInfo = {};
  230. view.set('isLogWrapHidden', false);
  231. view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K}));
  232. view.toggleTaskLog({context: taskInfo});
  233. expect(view.get('isLogWrapHidden')).to.equal(true);
  234. expect(view.get('parentView.c.currentOpenTaskId')).to.equal(0);
  235. expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(0);
  236. });
  237. });
  238. });