progress_view_test.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/admin/highAvailability/progress_view');
  20. describe('App.HighAvailabilityProgressPageView', function () {
  21. var view = App.HighAvailabilityProgressPageView.create({
  22. controller: Em.Object.create({
  23. loadStep: Em.K
  24. })
  25. });
  26. describe("#didInsertElement()", function () {
  27. beforeEach(function () {
  28. sinon.spy(view.get('controller'), 'loadStep');
  29. });
  30. afterEach(function () {
  31. view.get('controller').loadStep.restore();
  32. });
  33. it("loadStep is called once", function () {
  34. view.didInsertElement();
  35. expect(view.get('controller').loadStep.calledOnce).to.be.true;
  36. });
  37. });
  38. describe("#headerTitle", function () {
  39. beforeEach(function () {
  40. this.mock = sinon.stub(App.router, 'get');
  41. });
  42. afterEach(function () {
  43. this.mock.restore();
  44. });
  45. it("currentStep is 1", function () {
  46. this.mock.returns(1);
  47. view.propertyDidChange('headerTitle');
  48. expect(view.get('headerTitle')).to.equal(Em.I18n.t('admin.highAvailability.wizard.rollback.header.title'));
  49. });
  50. it("currentStep is 2", function () {
  51. this.mock.returns(2);
  52. view.propertyDidChange('headerTitle');
  53. expect(view.get('headerTitle')).to.equal(Em.I18n.t('admin.highAvailability.wizard.step2.header'));
  54. });
  55. });
  56. describe("#noticeInProgress", function () {
  57. beforeEach(function () {
  58. this.mock = sinon.stub(App.router, 'get');
  59. });
  60. afterEach(function () {
  61. this.mock.restore();
  62. });
  63. it("currentStep is 1", function () {
  64. this.mock.returns(1);
  65. view.propertyDidChange('noticeInProgress');
  66. expect(view.get('noticeInProgress')).to.equal(Em.I18n.t('admin.highAvailability.rollback.notice.inProgress'));
  67. });
  68. it("currentStep is 2", function () {
  69. this.mock.returns(2);
  70. view.propertyDidChange('noticeInProgress');
  71. expect(view.get('noticeInProgress')).to.equal(Em.I18n.t('admin.highAvailability.wizard.progressPage.notice.inProgress'));
  72. });
  73. });
  74. describe("#onStatusChange()", function() {
  75. it("COMPLETED status", function() {
  76. view.reopen({
  77. noticeCompleted: 'noticeCompleted'
  78. });
  79. view.set('controller.status', 'COMPLETED');
  80. expect(view.get('notice')).to.equal('noticeCompleted');
  81. expect(view.get('noticeClass')).to.equal('alert alert-success');
  82. });
  83. it("FAILED status", function() {
  84. view.reopen({
  85. noticeFailed: 'noticeFailed'
  86. });
  87. view.set('controller.status', 'FAILED');
  88. expect(view.get('notice')).to.equal('noticeFailed');
  89. expect(view.get('noticeClass')).to.equal('alert alert-error');
  90. });
  91. it("IN_PROGRESS status", function() {
  92. view.reopen({
  93. noticeInProgress: 'noticeInProgress'
  94. });
  95. view.set('controller.status', 'IN_PROGRESS');
  96. expect(view.get('notice')).to.equal('noticeInProgress');
  97. expect(view.get('noticeClass')).to.equal('alert alert-info');
  98. });
  99. });
  100. describe("#taskView", function() {
  101. var taskView = view.get('taskView').create({
  102. content: Em.Object.create()
  103. });
  104. describe("#didInsertElement()", function () {
  105. beforeEach(function () {
  106. sinon.spy(taskView, 'onStatus');
  107. });
  108. afterEach(function () {
  109. taskView.onStatus.restore();
  110. });
  111. it("onStatus is called once", function () {
  112. taskView.didInsertElement();
  113. expect(taskView.onStatus.calledOnce).to.be.true;
  114. });
  115. });
  116. describe("#barWidth", function () {
  117. it("currentStep is 1", function () {
  118. taskView.set('content.progress', 1);
  119. taskView.propertyDidChange('barWidth');
  120. expect(taskView.get('barWidth')).to.equal('width: 1%;');
  121. });
  122. });
  123. describe("#onStatus", function() {
  124. it("IN_PROGRESS status", function() {
  125. taskView.set('content.status', 'IN_PROGRESS');
  126. taskView.set('content.requestIds', []);
  127. taskView.onStatus();
  128. expect(taskView.get('linkClass')).to.equal('active-text');
  129. expect(taskView.get('icon')).to.equal('icon-cog');
  130. expect(taskView.get('iconColor')).to.equal('text-info');
  131. });
  132. it("FAILED status", function() {
  133. taskView.set('content.status', 'FAILED');
  134. taskView.set('content.requestIds', [{}]);
  135. taskView.onStatus();
  136. expect(taskView.get('linkClass')).to.equal('active-link');
  137. expect(taskView.get('icon')).to.equal('icon-exclamation-sign');
  138. expect(taskView.get('iconColor')).to.equal('text-error');
  139. });
  140. it("COMPLETED status", function() {
  141. taskView.set('content.status', 'COMPLETED');
  142. taskView.set('content.requestIds', []);
  143. taskView.onStatus();
  144. expect(taskView.get('linkClass')).to.equal('active-text');
  145. expect(taskView.get('icon')).to.equal('icon-ok');
  146. expect(taskView.get('iconColor')).to.equal('text-success');
  147. });
  148. it("else status", function() {
  149. taskView.set('content.status', '');
  150. taskView.set('content.requestIds', []);
  151. taskView.onStatus();
  152. expect(taskView.get('linkClass')).to.equal('not-active-link');
  153. expect(taskView.get('icon')).to.equal('icon-cog');
  154. expect(taskView.get('iconColor')).to.be.empty;
  155. });
  156. });
  157. });
  158. });