host_test.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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/main/host');
  20. function getView() {
  21. return App.MainHostView.create({
  22. controller: App.MainHostController.create()
  23. });
  24. }
  25. describe('App.MainHostView', function () {
  26. var view;
  27. beforeEach(function () {
  28. view = getView();
  29. });
  30. App.TestAliases.testAsComputedAlias(getView(), 'colPropAssoc', 'controller.colPropAssoc', 'array');
  31. describe('#didInsertElement', function () {
  32. var cases = [
  33. {
  34. methodName: 'clearFiltersObs',
  35. propertyToChange: 'controller.clearFilters',
  36. callCount: 2
  37. },
  38. {
  39. methodName: 'toggleAllHosts',
  40. propertyToChange: 'selectAllHosts',
  41. callCount: 1
  42. },
  43. {
  44. methodName: 'updatePagination',
  45. propertyToChange: 'displayLength',
  46. callCount: 1
  47. },
  48. {
  49. methodName: 'updatePaging',
  50. propertyToChange: 'filteredCount',
  51. callCount: 2
  52. }
  53. ],
  54. title = '{0} changed';
  55. beforeEach(function () {
  56. cases.forEach(function (item) {
  57. sinon.stub(view, item.methodName, Em.K);
  58. });
  59. });
  60. afterEach(function () {
  61. cases.forEach(function (item) {
  62. view[item.methodName].restore();
  63. });
  64. });
  65. cases.forEach(function (item) {
  66. it(title.format(item.propertyToChange), function () {
  67. view.didInsertElement();
  68. view.propertyDidChange(item.propertyToChange);
  69. expect(view[item.methodName].callCount).to.equal(item.callCount);
  70. });
  71. });
  72. });
  73. describe('#HostView', function () {
  74. var hostView;
  75. beforeEach(function () {
  76. hostView = view.HostView.create({
  77. content: {
  78. hostName: null
  79. },
  80. controller: App.MainHostController.create()
  81. });
  82. });
  83. describe('#displayComponents', function () {
  84. var cases = [
  85. {
  86. hostComponents: [
  87. {
  88. displayName: 'c0'
  89. },
  90. {
  91. displayName: 'c1'
  92. }
  93. ],
  94. showHostsTableListPopupCallCount: 1,
  95. title: 'should display host components in modal popup'
  96. },
  97. {
  98. hostComponents: [],
  99. showHostsTableListPopupCallCount: 0,
  100. title: 'should not display modal popup'
  101. }
  102. ];
  103. beforeEach(function () {
  104. sinon.stub(App, 'showHostsTableListPopup', Em.K);
  105. });
  106. afterEach(function () {
  107. App.showHostsTableListPopup.restore();
  108. });
  109. cases.forEach(function (item) {
  110. it(item.title, function () {
  111. hostView.set('content', {
  112. hostName: 'h',
  113. hostComponents: item.hostComponents
  114. });
  115. hostView.displayComponents();
  116. expect(App.showHostsTableListPopup.callCount).to.equal(item.showHostsTableListPopupCallCount);
  117. if (item.showHostsTableListPopupCallCount) {
  118. expect(App.showHostsTableListPopup.calledWith(Em.I18n.t('common.components'), 'h', ['c0', 'c1'])).to.be.true;
  119. }
  120. });
  121. });
  122. });
  123. describe('#displayVersions', function () {
  124. var cases = [
  125. {
  126. stackVersions: [
  127. Em.Object.create({
  128. displayName: 'v0',
  129. status: 'CURRENT',
  130. isVisible: true
  131. }),
  132. Em.Object.create({
  133. displayName: 'v1',
  134. status: 'OUT_OF_SYNC',
  135. isVisible: true
  136. }),
  137. Em.Object.create({
  138. displayName: 'v2',
  139. status: 'INSTALL_FAILED',
  140. isVisible: false
  141. })
  142. ],
  143. showHostsTableListPopupCallCount: 1,
  144. title: 'should display stack versions in modal popup'
  145. },
  146. {
  147. stackVersions: [
  148. Em.Object.create({
  149. displayName: 'v0',
  150. status: 'CURRENT',
  151. isVisible: true
  152. }),
  153. Em.Object.create({
  154. displayName: 'v2',
  155. status: 'INSTALL_FAILED',
  156. isVisible: false
  157. })
  158. ],
  159. showHostsTableListPopupCallCount: 0,
  160. title: 'should not display modal popup if there\'s only one visible stack version'
  161. },
  162. {
  163. stackVersions: [
  164. Em.Object.create({
  165. displayName: 'v2',
  166. status: 'INSTALL_FAILED',
  167. isVisible: false
  168. })
  169. ],
  170. showHostsTableListPopupCallCount: 0,
  171. title: 'should not display modal popup if there are no visible stack versions available'
  172. },
  173. {
  174. stackVersions: [],
  175. showHostsTableListPopupCallCount: 0,
  176. title: 'should not display modal popup if there are no stack versions available'
  177. }
  178. ];
  179. beforeEach(function () {
  180. sinon.stub(App, 'showHostsTableListPopup', Em.K);
  181. });
  182. afterEach(function () {
  183. App.showHostsTableListPopup.restore();
  184. });
  185. cases.forEach(function (item) {
  186. it('should display stack versions in modal popup', function () {
  187. hostView.set('content', {
  188. hostName: 'h',
  189. stackVersions: item.stackVersions
  190. });
  191. hostView.displayVersions();
  192. expect(App.showHostsTableListPopup.callCount).to.equal(item.showHostsTableListPopupCallCount);
  193. if (item.showHostsTableListPopupCallCount) {
  194. expect(App.showHostsTableListPopup.calledWith(Em.I18n.t('common.versions'), 'h', [
  195. {
  196. name: 'v0',
  197. status: 'Current'
  198. },
  199. {
  200. name: 'v1',
  201. status: 'Out Of Sync'
  202. }
  203. ])).to.be.true;
  204. }
  205. });
  206. });
  207. });
  208. describe('#currentVersion', function () {
  209. var cases = [
  210. {
  211. stackVersions: [
  212. Em.Object.create({
  213. displayName: 'HDP-2.2.0.0-2000'
  214. }),
  215. Em.Object.create({
  216. displayName: 'HDP-2.2.0.0-1000',
  217. isCurrent: true
  218. })
  219. ],
  220. currentVersion: 'HDP-2.2.0.0-1000',
  221. title: 'current version specified explicitly'
  222. },
  223. {
  224. stackVersions: [
  225. Em.Object.create({
  226. displayName: 'HDP-2.2.0.0-2000'
  227. }),
  228. Em.Object.create({
  229. displayName: 'HDP-2.3.0.0-1000'
  230. })
  231. ],
  232. currentVersion: 'HDP-2.2.0.0-2000',
  233. title: 'current version not specified explicitly'
  234. },
  235. {
  236. stackVersions: [Em.Object.create()],
  237. currentVersion: undefined,
  238. title: 'version display name isn\'t defined'
  239. },
  240. {
  241. stackVersions: [null],
  242. currentVersion: '',
  243. title: 'no version data available'
  244. },
  245. {
  246. stackVersions: [],
  247. currentVersion: '',
  248. title: 'no versions available'
  249. }
  250. ];
  251. cases.forEach(function (item) {
  252. it(item.title, function () {
  253. hostView.set('content.stackVersions', item.stackVersions);
  254. expect(hostView.get('currentVersion')).to.equal(item.currentVersion);
  255. });
  256. });
  257. });
  258. });
  259. });