host_progress_popup_body_view_test.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 view;
  20. describe('App.HostProgressPopupBodyView', function () {
  21. beforeEach(function () {
  22. view = App.HostProgressPopupBodyView.create({
  23. controller: Em.Object.create({
  24. dataSourceController: Em.Object.create({})
  25. })
  26. });
  27. });
  28. describe('#switchLevel', function () {
  29. var map = App.HostProgressPopupBodyView.create().get('customControllersSwitchLevelMap');
  30. Object.keys(map).forEach(function (controllerName) {
  31. var methodName = map [controllerName];
  32. var levelName = 'REQUESTS_LIST';
  33. beforeEach(function () {
  34. sinon.stub(view, methodName, Em.K);
  35. });
  36. afterEach(function () {
  37. view[methodName].restore();
  38. });
  39. it('should call ' + methodName, function () {
  40. view.set('controller.dataSourceController.name', controllerName);
  41. view.switchLevel(levelName);
  42. expect(view[methodName].args[0]).to.eql([levelName]);
  43. });
  44. });
  45. });
  46. describe('_determineRoleRelation', function() {
  47. var cases;
  48. beforeEach(function() {
  49. sinon.stub(App.StackServiceComponent, 'find').returns([{componentName: 'DATANODE'}]);
  50. sinon.stub(App.StackService, 'find').returns([{serviceName: 'HDFS'}])
  51. });
  52. afterEach(function() {
  53. App.StackServiceComponent.find.restore();
  54. App.StackService.find.restore();
  55. });
  56. cases = [
  57. {
  58. task: { role: 'HDFS_SERVICE_CHECK'},
  59. m: 'Role is HDFS_SERVICE_CHECK',
  60. e: {
  61. type: 'service',
  62. value: 'HDFS'
  63. }
  64. },
  65. {
  66. task: { role: 'DATANODE'},
  67. m: 'Role is DATANODE',
  68. e: {
  69. type: 'component',
  70. value: 'DATANODE'
  71. }
  72. },
  73. {
  74. task: { role: 'UNDEFINED'},
  75. m: 'Role is UNDEFINED',
  76. e: false
  77. }
  78. ];
  79. cases.forEach(function(test) {
  80. it(test.m, function() {
  81. view.reopen({
  82. currentHost: Em.Object.create({
  83. logTasks: [
  84. { Tasks: { id: 1, role: test.task.role }}
  85. ]
  86. })
  87. });
  88. var ret = view._determineRoleRelation(Em.Object.create({ id: 1 }));
  89. expect(ret).to.be.eql(test.e);
  90. });
  91. });
  92. });
  93. describe('#didInsertElement', function () {
  94. beforeEach(function () {
  95. sinon.stub(view, 'updateHostInfo', Em.K);
  96. view.didInsertElement();
  97. });
  98. afterEach(function () {
  99. view.updateHostInfo.restore();
  100. });
  101. it('should display relevant info', function () {
  102. expect(view.updateHostInfo.calledOnce).to.be.true;
  103. });
  104. });
  105. describe('#preloadHostModel', function() {
  106. describe('When Log Search installed', function() {
  107. var cases;
  108. beforeEach(function() {
  109. this.HostModelStub = sinon.stub(App.Host, 'find');
  110. this.isLogSearchInstalled = sinon.stub(view, 'get').withArgs('isLogSearchInstalled');
  111. this.logSearchSupported = sinon.stub(App, 'get').withArgs('supports.logSearch');
  112. this.updateCtrlStub = sinon.stub(App.router.get('updateController'), 'updateLogging');
  113. });
  114. afterEach(function () {
  115. App.Host.find.restore();
  116. view.get.restore();
  117. App.get.restore();
  118. App.router.get('updateController').updateLogging.restore();
  119. });
  120. cases = [
  121. {
  122. hostName: 'host1',
  123. logSearchSupported: true,
  124. isLogSearchInstalled: true,
  125. requestFailed: false,
  126. hosts: [
  127. {
  128. hostName: 'host2'
  129. }
  130. ],
  131. e: {
  132. updateLoggingCalled: true
  133. },
  134. m: 'Host absent, log search installed and supported'
  135. },
  136. {
  137. hostName: 'host1',
  138. logSearchSupported: true,
  139. isLogSearchInstalled: true,
  140. requestFailed: false,
  141. hosts: [
  142. {
  143. hostName: 'host1'
  144. }
  145. ],
  146. e: {
  147. updateLoggingCalled: false
  148. },
  149. m: 'Host present, log search installed and supported'
  150. },
  151. {
  152. hostName: 'host1',
  153. logSearchSupported: false,
  154. isLogSearchInstalled: true,
  155. requestFailed: false,
  156. hosts: [
  157. {
  158. hostName: 'host1'
  159. }
  160. ],
  161. e: {
  162. updateLoggingCalled: false
  163. },
  164. m: 'Host present, log search installed and support is off'
  165. },
  166. {
  167. hostName: 'host1',
  168. logSearchSupported: true,
  169. isLogSearchInstalled: true,
  170. requestFailed: true,
  171. hosts: [
  172. {
  173. hostName: 'host2'
  174. }
  175. ],
  176. e: {
  177. updateLoggingCalled: true
  178. },
  179. m: 'Host is absent, log search installed and supported, update request was failed'
  180. },
  181. {
  182. hostName: 'host1',
  183. logSearchSupported: true,
  184. isLogSearchInstalled: false,
  185. requestFailed: true,
  186. hosts: [
  187. {
  188. hostName: 'host2'
  189. }
  190. ],
  191. e: {
  192. updateLoggingCalled: false
  193. },
  194. m: 'Host is absent, log search not installed and supported'
  195. }
  196. ];
  197. cases.forEach(function(test) {
  198. describe(test.m, function() {
  199. beforeEach(function () {
  200. this.HostModelStub.returns(test.hosts);
  201. this.isLogSearchInstalled.returns(test.isLogSearchInstalled);
  202. this.logSearchSupported.returns(test.logSearchSupported);
  203. if (test.requestFailed) {
  204. this.updateCtrlStub.returns($.Deferred().reject().promise());
  205. } else {
  206. this.updateCtrlStub.returns($.Deferred().resolve().promise());
  207. }
  208. });
  209. it('hostInfoLoaded should be true on init', function () {
  210. expect(Em.get(view, 'hostInfoLoaded')).to.be.true;
  211. });
  212. it('updateLogging call validation', function () {
  213. Em.set(view, 'hostInfoLoaded', false);
  214. view.preloadHostModel(test.hostName);
  215. expect(App.router.get('updateController').updateLogging.called).to.be.equal(test.e.updateLoggingCalled);
  216. });
  217. it('in result hostInfoLoaded should be always true', function () {
  218. Em.set(view, 'hostInfoLoaded', false);
  219. view.preloadHostModel(test.hostName);
  220. expect(Em.get(view, 'hostInfoLoaded')).to.be.true;
  221. });
  222. });
  223. }, this);
  224. });
  225. });
  226. });