upgrade_entity_test.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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/upgrade_entity');
  20. function getModel() {
  21. return App.upgradeEntity.create();
  22. }
  23. describe('App.upgradeEntity', function () {
  24. var model;
  25. beforeEach(function () {
  26. model = getModel();
  27. });
  28. App.TestAliases.testAsComputedNotEqual(getModel(), 'isVisible', 'status', 'PENDING');
  29. describe("#isRunning", function() {
  30. it("status IN_PROGRESS", function() {
  31. model.set('status', 'IN_PROGRESS');
  32. model.propertyDidChange('isRunning');
  33. expect(model.get('isRunning')).to.be.true;
  34. });
  35. it("status PENDING", function() {
  36. model.set('status', 'PENDING');
  37. model.propertyDidChange('isRunning');
  38. expect(model.get('isRunning')).to.be.false;
  39. });
  40. });
  41. describe("#progress", function() {
  42. it("progress_percent = 1.9", function() {
  43. model.set('progress_percent', 1.9);
  44. model.propertyDidChange('progress');
  45. expect(model.get('progress')).to.equal(1);
  46. });
  47. it("progress_percent = 1", function() {
  48. model.set('progress_percent', 1);
  49. model.propertyDidChange('progress');
  50. expect(model.get('progress')).to.equal(1);
  51. });
  52. });
  53. describe("#isActive", function() {
  54. it("status IN_PROGRESS", function() {
  55. model.set('status', 'IN_PROGRESS');
  56. model.propertyDidChange('isActive');
  57. expect(model.get('isActive')).to.be.true;
  58. });
  59. it("status PENDING", function() {
  60. model.set('status', 'PENDING');
  61. model.propertyDidChange('isActive');
  62. expect(model.get('isActive')).to.be.false;
  63. });
  64. });
  65. describe('#isExpandableGroup', function () {
  66. var cases = [
  67. {
  68. input: {
  69. type: 'ITEM'
  70. },
  71. isExpandableGroup: false,
  72. title: 'not upgrade group'
  73. },
  74. {
  75. input: {
  76. type: 'GROUP',
  77. status: 'PENDING',
  78. hasExpandableItems: false
  79. },
  80. isExpandableGroup: false,
  81. title: 'pending upgrade group without expandable items'
  82. },
  83. {
  84. input: {
  85. type: 'GROUP',
  86. status: 'ABORTED',
  87. hasExpandableItems: false
  88. },
  89. isExpandableGroup: false,
  90. title: 'aborted upgrade group without expandable items'
  91. },
  92. {
  93. input: {
  94. type: 'GROUP',
  95. status: 'ABORTED',
  96. hasExpandableItems: true
  97. },
  98. isExpandableGroup: true,
  99. title: 'aborted upgrade group with expandable items'
  100. },
  101. {
  102. input: {
  103. type: 'GROUP',
  104. status: 'IN_PROGRESS',
  105. hasExpandableItems: false
  106. },
  107. isExpandableGroup: true,
  108. title: 'active upgrade group'
  109. }
  110. ];
  111. cases.forEach(function (item) {
  112. it(item.title, function () {
  113. model.setProperties(item.input);
  114. expect(model.get('isExpandableGroup')).to.equal(item.isExpandableGroup);
  115. });
  116. });
  117. });
  118. describe('#upgradeGroupStatus', function () {
  119. var cases = [
  120. {
  121. input: {
  122. type: 'ITEM',
  123. upgradeSuspended: false
  124. },
  125. upgradeGroupStatus: undefined,
  126. title: 'not upgrade group'
  127. },
  128. {
  129. input: {
  130. type: 'GROUP',
  131. status: 'PENDING',
  132. hasExpandableItems: false,
  133. upgradeSuspended: false
  134. },
  135. upgradeGroupStatus: 'PENDING',
  136. title: 'pending upgrade group'
  137. },
  138. {
  139. input: {
  140. type: 'GROUP',
  141. status: 'PENDING',
  142. hasExpandableItems: true,
  143. upgradeSuspended: false
  144. },
  145. upgradeGroupStatus: 'SUBITEM_FAILED',
  146. title: 'pending upgrade group with expandable items'
  147. },
  148. {
  149. input: {
  150. type: 'GROUP',
  151. status: 'ABORTED',
  152. hasExpandableItems: false,
  153. upgradeSuspended: false
  154. },
  155. upgradeGroupStatus: 'ABORTED',
  156. title: 'aborted upgrade group with expandable items'
  157. },
  158. {
  159. input: {
  160. type: 'GROUP',
  161. status: 'ABORTED',
  162. hasExpandableItems: true,
  163. upgradeSuspended: true
  164. },
  165. upgradeGroupStatus: 'SUSPENDED',
  166. title: 'suspended upgrade group with expandable items'
  167. },
  168. {
  169. input: {
  170. type: 'GROUP',
  171. status: 'IN_PROGRESS',
  172. hasExpandableItems: false,
  173. upgradeSuspended: false
  174. },
  175. upgradeGroupStatus: 'IN_PROGRESS',
  176. title: 'active upgrade'
  177. }
  178. ];
  179. beforeEach(function() {
  180. this.mock = sinon.stub(App, 'get');
  181. });
  182. afterEach(function() {
  183. this.mock.restore();
  184. });
  185. cases.forEach(function (item) {
  186. it(item.title, function () {
  187. this.mock.returns(item.input.upgradeSuspended);
  188. model.setProperties(item.input);
  189. expect(model.get('upgradeGroupStatus')).to.equal(item.upgradeGroupStatus);
  190. });
  191. });
  192. });
  193. });