finished_upgrade_entity_test.js 5.2 KB

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