host_component_view_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/host_component');
  20. require('views/main/host/details/host_component_view');
  21. var hostComponentView;
  22. describe('App.HostComponentView', function() {
  23. beforeEach(function() {
  24. sinon.stub(App.router, 'get', function (k) {
  25. if (k === 'mainHostDetailsController.content') return Em.Object.create({
  26. hostComponents: [
  27. {
  28. componentName: 'component'
  29. }
  30. ]
  31. });
  32. return Em.get(App.router, k);
  33. });
  34. hostComponentView = App.HostComponentView.create({
  35. startBlinking: function(){},
  36. doBlinking: function(){},
  37. getDesiredAdminState: function(){return $.ajax({});},
  38. content: Em.Object.create({
  39. componentName: 'component'
  40. }),
  41. hostComponent: Em.Object.create()
  42. });
  43. });
  44. afterEach(function () {
  45. App.router.get.restore();
  46. });
  47. describe('#disabled', function() {
  48. var tests = Em.A([
  49. {
  50. parentView: {content: {healthClass: 'health-status-DEAD-YELLOW'}},
  51. e: 'disabled'
  52. },
  53. {
  54. parentView: {content: {healthClass: 'another-class'}},
  55. e: ''
  56. }
  57. ]);
  58. tests.forEach(function(test) {
  59. it(test.m, function() {
  60. hostComponentView = App.HostComponentView.create({
  61. startBlinking: function(){},
  62. doBlinking: function(){},
  63. parentView: test.parentView
  64. });
  65. expect(hostComponentView.get('disabled')).to.equal(test.e);
  66. });
  67. });
  68. });
  69. describe('#isUpgradeFailed', function() {
  70. var tests = ['UPGRADE_FAILED'];
  71. var testE = true;
  72. var defaultE = false;
  73. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  74. it(status, function() {
  75. hostComponentView.get('hostComponent').set('workStatus', status);
  76. var e = tests.contains(status) ? testE : defaultE;
  77. expect(hostComponentView.get('isUpgradeFailed')).to.equal(e);
  78. });
  79. });
  80. });
  81. describe('#isInstallFailed', function() {
  82. var tests = ['INSTALL_FAILED'];
  83. var testE = true;
  84. var defaultE = false;
  85. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  86. it(status, function() {
  87. hostComponentView.get('hostComponent').set('workStatus', status);
  88. var e = tests.contains(status) ? testE : defaultE;
  89. expect(hostComponentView.get('isInstallFailed')).to.equal(e);
  90. });
  91. });
  92. });
  93. describe('#isStart', function() {
  94. var tests = ['STARTED','STARTING'];
  95. var testE = true;
  96. var defaultE = false;
  97. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  98. it(status, function() {
  99. hostComponentView.get('hostComponent').set('workStatus', status);
  100. var e = tests.contains(status) ? testE : defaultE;
  101. expect(hostComponentView.get('isStart')).to.equal(e);
  102. });
  103. });
  104. });
  105. describe('#isStop', function() {
  106. var tests = ['INSTALLED'];
  107. var testE = true;
  108. var defaultE = false;
  109. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  110. it(status, function() {
  111. hostComponentView.get('hostComponent').set('workStatus', status);
  112. var e = tests.contains(status) ? testE : defaultE;
  113. expect(hostComponentView.get('isStop')).to.equal(e);
  114. });
  115. });
  116. });
  117. describe('#isInstalling', function() {
  118. var tests = ['INSTALLING'];
  119. var testE = true;
  120. var defaultE = false;
  121. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  122. it(status, function() {
  123. hostComponentView.get('hostComponent').set('workStatus', status);
  124. var e = tests.contains(status) ? testE : defaultE;
  125. expect(hostComponentView.get('isInstalling')).to.equal(e);
  126. });
  127. });
  128. });
  129. describe('#isInit', function() {
  130. var tests = ['INIT'];
  131. var testE = true;
  132. var defaultE = false;
  133. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  134. it(status, function() {
  135. hostComponentView.get('hostComponent').set('workStatus', status);
  136. var e = tests.contains(status) ? testE : defaultE;
  137. expect(hostComponentView.get('isInit')).to.equal(e);
  138. });
  139. });
  140. });
  141. describe('#noActionAvailable', function() {
  142. var tests = ['STARTING', 'STOPPING', 'UNKNOWN', 'DISABLED'];
  143. var testE = 'hidden';
  144. var defaultE = '';
  145. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  146. it(status, function() {
  147. hostComponentView.get('hostComponent').set('workStatus', status);
  148. var e = tests.contains(status) ? testE : defaultE;
  149. expect(hostComponentView.get('noActionAvailable')).to.equal(e);
  150. });
  151. });
  152. });
  153. describe('#isActive', function() {
  154. var tests = Em.A([
  155. {passiveState: 'OFF', e: true},
  156. {passiveState: 'ON', e: false},
  157. {passiveState: 'IMPLIED', e: false}
  158. ]);
  159. tests.forEach(function(test) {
  160. it(test.workStatus, function() {
  161. hostComponentView.get('content').set('passiveState', test.passiveState);
  162. expect(hostComponentView.get('isActive')).to.equal(test.e);
  163. });
  164. });
  165. });
  166. describe('#isRestartComponentDisabled', function() {
  167. var tests = ['STARTED'];
  168. var testE = false;
  169. var defaultE = true;
  170. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  171. it(status, function() {
  172. hostComponentView.get('hostComponent').set('workStatus', status);
  173. var e = tests.contains(status) ? testE : defaultE;
  174. expect(hostComponentView.get('isRestartComponentDisabled')).to.equal(e);
  175. });
  176. });
  177. });
  178. describe('#isDeleteComponentDisabled', function() {
  179. var tests = ['INSTALLED', 'UNKNOWN', 'INSTALL_FAILED', 'UPGRADE_FAILED', 'INIT'];
  180. var testE = false;
  181. var defaultE = true;
  182. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  183. it(status, function() {
  184. hostComponentView.get('hostComponent').set('workStatus', status);
  185. var e = tests.contains(status) ? testE : defaultE;
  186. expect(hostComponentView.get('isDeleteComponentDisabled')).to.equal(e);
  187. });
  188. });
  189. });
  190. describe('#componentTextStatus', function() {
  191. var tests = Em.A([
  192. {
  193. componentTextStatus: 'status',
  194. hostComponent: null,
  195. e: 'status',
  196. m: 'get content status'
  197. },
  198. {
  199. componentTextStatus: 'status',
  200. hostComponent: Em.Object.create({componentTextStatus: 'new_status'}),
  201. e: 'new_status',
  202. m: 'get hostComponent status'
  203. }
  204. ]);
  205. tests.forEach(function(test) {
  206. it(test.m, function() {
  207. hostComponentView = App.HostComponentView.create({
  208. startBlinking: function(){},
  209. doBlinking: function(){},
  210. getDesiredAdminState: function(){return $.ajax({});},
  211. hostComponent: test.hostComponent,
  212. content: Em.Object.create()
  213. });
  214. hostComponentView.get('content').set('componentTextStatus', test.componentTextStatus);
  215. expect(hostComponentView.get('componentTextStatus')).to.equal(test.e);
  216. });
  217. });
  218. });
  219. describe('#workStatus', function() {
  220. var tests = Em.A([
  221. {
  222. workStatus: 'status',
  223. hostComponent: null,
  224. e: 'status',
  225. m: 'get content workStatus'
  226. },
  227. {
  228. workStatus: 'status',
  229. hostComponent: Em.Object.create({workStatus: 'new_status'}),
  230. e: 'new_status',
  231. m: 'get hostComponent workStatus'
  232. }
  233. ]);
  234. tests.forEach(function(test) {
  235. it(test.m, function() {
  236. hostComponentView = App.HostComponentView.create({
  237. startBlinking: function(){},
  238. doBlinking: function(){},
  239. getDesiredAdminState: function(){return $.ajax({});},
  240. hostComponent: test.hostComponent,
  241. content: Em.Object.create()
  242. });
  243. hostComponentView.get('content').set('workStatus', test.workStatus);
  244. expect(hostComponentView.get('workStatus')).to.equal(test.e);
  245. });
  246. });
  247. });
  248. describe('#statusClass', function() {
  249. var tests = Em.A([
  250. {
  251. workStatus: App.HostComponentStatus.install_failed,
  252. passiveState: 'OFF',
  253. e: 'health-status-color-red icon-cog'
  254. },
  255. {
  256. workStatus: App.HostComponentStatus.installing,
  257. passiveState: 'OFF',
  258. e: 'health-status-color-blue icon-cog'
  259. },
  260. {
  261. workStatus: 'STARTED',
  262. passiveState: 'ON',
  263. e: 'health-status-started'
  264. },
  265. {
  266. workStatus: 'STARTED',
  267. passiveState: 'IMPLIED',
  268. e: 'health-status-started'
  269. },
  270. {
  271. workStatus: 'STARTED',
  272. passiveState: 'OFF',
  273. e: 'health-status-started'
  274. }
  275. ]);
  276. tests.forEach(function(test) {
  277. it(test.workStatus + ' ' + test.passiveState, function() {
  278. hostComponentView = App.HostComponentView.create({
  279. startBlinking: function(){},
  280. doBlinking: function(){},
  281. getDesiredAdminState: function(){return $.ajax({});},
  282. content: Em.Object.create(),
  283. hostComponent: Em.Object.create()
  284. });
  285. hostComponentView.get('hostComponent').set('workStatus',test.workStatus);
  286. hostComponentView.get('content').set('passiveState', test.passiveState);
  287. expect(hostComponentView.get('statusClass')).to.equal(test.e);
  288. });
  289. });
  290. });
  291. describe('#isInProgress', function() {
  292. var tests = ['STOPPING', 'STARTING'];
  293. var testE = true;
  294. var defaultE = false;
  295. App.HostComponentStatus.getStatusesList().forEach(function(status) {
  296. it(status, function() {
  297. hostComponentView.get('hostComponent').set('workStatus', status);
  298. var e = tests.contains(status) ? testE : defaultE;
  299. expect(hostComponentView.get('isInProgress')).to.equal(e);
  300. });
  301. });
  302. });
  303. describe('#statusIconClass', function() {
  304. var tests = Em.A([
  305. {s: 'health-status-started', e: App.healthIconClassGreen},
  306. {s: 'health-status-starting', e: App.healthIconClassGreen},
  307. {s: 'health-status-installed', e: App.healthIconClassRed},
  308. {s: 'health-status-stopping', e: App.healthIconClassRed},
  309. {s: 'health-status-unknown', e: App.healthIconClassYellow},
  310. {s: 'health-status-DEAD-ORANGE', e: App.healthIconClassOrange},
  311. {s: 'other', e: ''}
  312. ]);
  313. tests.forEach(function(test) {
  314. it(test.s, function() {
  315. hostComponentView.reopen({statusClass: test.s});
  316. expect(hostComponentView.get('statusIconClass')).to.equal(test.e);
  317. })
  318. });
  319. });
  320. });