hostLogPopupBody_view_test.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. function getView() {
  22. return App.WizardStep9HostLogPopupBodyView.create({
  23. parentView: Em.Object.create({
  24. host: Em.Object.create()
  25. })
  26. });
  27. }
  28. describe('App.WizardStep9HostLogPopupBodyView', function() {
  29. beforeEach(function() {
  30. view = getView();
  31. });
  32. App.TestAliases.testAsComputedAlias(getView(), 'isNoTasksScheduled', 'parentView.host.isNoTasksForInstall', 'boolean');
  33. describe('#isHeartbeatLost', function() {
  34. it('should depends on parentView.host.status', function() {
  35. view.set('parentView.host.status', 'success');
  36. expect(view.get('isHeartbeatLost')).to.equal(false);
  37. view.set('parentView.host.status', 'heartbeat_lost');
  38. expect(view.get('isHeartbeatLost')).to.equal(true);
  39. });
  40. });
  41. describe('#visibleTasks', function() {
  42. Em.A([
  43. {
  44. value: 'pending',
  45. f: ['pending', 'queued']
  46. },
  47. {
  48. value: 'in_progress',
  49. f: ['in_progress']
  50. },
  51. {
  52. value: 'failed',
  53. f: ['failed']
  54. },
  55. {
  56. value: 'completed',
  57. f: ['completed']
  58. },
  59. {
  60. value: 'aborted',
  61. f: ['aborted']
  62. },
  63. {
  64. value: 'timedout',
  65. f: ['timedout']
  66. },
  67. {
  68. value: 'all'
  69. }
  70. ]).forEach(function(test) {
  71. it(test.value, function() {
  72. view.reopen({
  73. category: Em.Object.create({value: test.value}),
  74. tasks: Em.A([
  75. {status: 'pending', isVisible: false},
  76. {status: 'queued', isVisible: false},
  77. {status: 'in_progress', isVisible: false},
  78. {status: 'failed', isVisible: false},
  79. {status: 'completed', isVisible: false},
  80. {status: 'aborted', isVisible: false},
  81. {status: 'timedout', isVisible: false}
  82. ])
  83. });
  84. view.visibleTasks();
  85. var visibleTasks = view.get('tasks').filter(function(task) {
  86. if (test.f) {
  87. return test.f.contains(task.status);
  88. }
  89. return true;
  90. });
  91. expect(visibleTasks.everyProperty('isVisible', true)).to.equal(true);
  92. });
  93. });
  94. });
  95. describe('#backToTaskList', function() {
  96. beforeEach(function () {
  97. sinon.stub(view, 'destroyClipBoard', Em.K);
  98. });
  99. afterEach(function () {
  100. view.destroyClipBoard.restore();
  101. });
  102. it('should call destroyClipBoard', function() {
  103. view.backToTaskList();
  104. expect(view.destroyClipBoard.calledOnce).to.equal(true);
  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. command_detail: 'TEST SERVICE/COMPONENT_DESCRIPTION'
  147. }
  148. };
  149. beforeEach(function () {
  150. view.set('parentView.host.logTasks', [testTask]);
  151. this.t = view.get('tasks');
  152. this.first = this.t[0];
  153. });
  154. it('should map tasks', function() {
  155. expect(this.t.length).to.equal(1);
  156. });
  157. it('should map id', function() {
  158. expect(this.first.get('id')).to.equal(1);
  159. });
  160. it('should map requestId', function() {
  161. expect(this.first.get('requestId')).to.equal(2);
  162. });
  163. it('should map command', function() {
  164. expect(this.first.get('command')).to.equal('cmd');
  165. });
  166. it('should map commandDetail', function() {
  167. expect(this.first.get('commandDetail')).to.equal(' Test Component Description');
  168. });
  169. it('should map role', function() {
  170. expect(this.first.get('role')).to.equal('Pig');
  171. });
  172. it('should map stderr', function() {
  173. expect(this.first.get('stderr')).to.equal('stderr');
  174. });
  175. it('should map stdout', function() {
  176. expect(this.first.get('stdout')).to.equal('stdout');
  177. });
  178. it('should map isVisible', function() {
  179. expect(this.first.get('isVisible')).to.equal(true);
  180. });
  181. it('should map hostName', function() {
  182. expect(this.first.get('hostName')).to.equal('host1');
  183. });
  184. describe('icons', function () {
  185. Em.A([
  186. {
  187. status: 'pending',
  188. icon:'icon-cog'
  189. },
  190. {
  191. status: 'queued',
  192. icon:'icon-cog'
  193. },
  194. {
  195. status: 'in_progress',
  196. icon:'icon-cogs'
  197. },
  198. {
  199. status: 'completed',
  200. icon:'icon-ok'
  201. },
  202. {
  203. status: 'failed',
  204. icon:'icon-exclamation-sign'
  205. },
  206. {
  207. status: 'aborted',
  208. icon:'icon-minus'
  209. },
  210. {
  211. status: 'timedout',
  212. icon:'icon-time'
  213. }
  214. ]).forEach(function (test) {
  215. it(test.status + ' -> ' + test.icon, function () {
  216. var t = Em.copy(testTask);
  217. t.Tasks.status = test.status;
  218. view.set('parentView.host.logTasks', [t]);
  219. view.propertyDidChange('tasks');
  220. expect(view.get('tasks')[0].icon).to.equal(test.icon);
  221. });
  222. });
  223. });
  224. });
  225. describe('#toggleTaskLog', function() {
  226. beforeEach(function () {
  227. view.set('parentView.c', Em.Object.create({loadCurrentTaskLog: Em.K}));
  228. sinon.spy(view.get('parentView.c'), 'loadCurrentTaskLog');
  229. });
  230. afterEach(function () {
  231. view.get('parentView.c').loadCurrentTaskLog.restore();
  232. });
  233. describe('isLogWrapHidden is true', function () {
  234. var taskInfo = {
  235. id: 1,
  236. requestId: 2
  237. };
  238. beforeEach(function () {
  239. view.set('isLogWrapHidden', true);
  240. view.toggleTaskLog({context: taskInfo});
  241. });
  242. it('isLogWrapHidden is set false', function() {
  243. expect(view.get('isLogWrapHidden')).to.equal(false);
  244. });
  245. it('currentOpenTaskId is equal to id', function() {
  246. expect(view.get('parentView.c.currentOpenTaskId')).to.equal(taskInfo.id);
  247. });
  248. it('currentOpenTaskRequestId is equal to requestId', function() {
  249. expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(taskInfo.requestId);
  250. });
  251. it('loadCurrentTaskLog called once', function() {
  252. expect(view.get('parentView.c').loadCurrentTaskLog.calledOnce).to.equal(true);
  253. });
  254. });
  255. describe('isLogWrapHidden is false', function () {
  256. var taskInfo = {};
  257. beforeEach(function () {
  258. view.set('isLogWrapHidden', false);
  259. view.toggleTaskLog({context: taskInfo});
  260. });
  261. it('isLogWrapHidden is set true', function() {
  262. expect(view.get('isLogWrapHidden')).to.equal(true);
  263. });
  264. it('currentOpenTaskId is 0', function() {
  265. expect(view.get('parentView.c.currentOpenTaskId')).to.equal(0);
  266. });
  267. it('currentOpenTaskRequestId is 0', function() {
  268. expect(view.get('parentView.c.currentOpenTaskRequestId')).to.equal(0);
  269. });
  270. });
  271. });
  272. });