upgrade_entity_test.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. },
  124. upgradeGroupStatus: undefined,
  125. title: 'not upgrade group'
  126. },
  127. {
  128. input: {
  129. type: 'GROUP',
  130. status: 'PENDING',
  131. hasExpandableItems: false
  132. },
  133. upgradeGroupStatus: 'PENDING',
  134. title: 'pending upgrade group'
  135. },
  136. {
  137. input: {
  138. type: 'GROUP',
  139. status: 'PENDING',
  140. hasExpandableItems: true
  141. },
  142. upgradeGroupStatus: 'SUBITEM_FAILED',
  143. title: 'pending upgrade group with expandable items'
  144. },
  145. {
  146. input: {
  147. type: 'GROUP',
  148. status: 'ABORTED',
  149. hasExpandableItems: true
  150. },
  151. upgradeGroupStatus: 'SUSPENDED',
  152. title: 'aborted upgrade group with expandable items'
  153. },
  154. {
  155. input: {
  156. type: 'GROUP',
  157. status: 'IN_PROGRESS',
  158. hasExpandableItems: false
  159. },
  160. upgradeGroupStatus: 'IN_PROGRESS',
  161. title: 'active upgrade'
  162. }
  163. ];
  164. cases.forEach(function (item) {
  165. it(item.title, function () {
  166. model.setProperties(item.input);
  167. expect(model.get('upgradeGroupStatus')).to.equal(item.upgradeGroupStatus);
  168. });
  169. });
  170. });
  171. });