wizard_watcher_controller_test.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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('controllers/global/wizard_watcher_controller');
  20. var controller;
  21. describe('App.wizardWatcherController', function () {
  22. beforeEach(function() {
  23. controller = App.WizardWatcherController.create();
  24. });
  25. describe("#isWizardRunning", function() {
  26. it("wizardUser is null", function() {
  27. controller.set('wizardUser', null);
  28. controller.propertyDidChange('isWizardRunning');
  29. expect(controller.get('isWizardRunning')).to.be.false;
  30. });
  31. it("wizardUser is correct", function() {
  32. controller.set('wizardUser', 'admin');
  33. controller.propertyDidChange('isWizardRunning');
  34. expect(controller.get('isWizardRunning')).to.be.true;
  35. });
  36. });
  37. describe("#wizardDisplayName", function() {
  38. beforeEach(function () {
  39. sinon.stub(App.router, 'get').returns(Em.Object.create({displayName: 'Wizard'}));
  40. });
  41. afterEach(function () {
  42. App.router.get.restore();
  43. });
  44. it("controllerName is null", function() {
  45. controller.set('controllerName', null);
  46. controller.propertyDidChange('wizardDisplayName');
  47. expect(controller.get('wizardDisplayName')).to.be.empty;
  48. });
  49. it("controllerName is correct", function() {
  50. controller.set('controllerName', 'ctrl1');
  51. controller.propertyDidChange('wizardDisplayName');
  52. expect(controller.get('wizardDisplayName')).to.equal(Em.I18n.t('wizard.inProgress').format('Wizard'));
  53. });
  54. });
  55. describe("#isNonWizardUser", function() {
  56. beforeEach(function () {
  57. sinon.stub(App.router, 'get').returns('admin');
  58. });
  59. afterEach(function () {
  60. App.router.get.restore();
  61. });
  62. it("isWizardRunning is false", function() {
  63. controller.reopen({
  64. isWizardRunning: false
  65. });
  66. controller.propertyDidChange('isNonWizardUser');
  67. expect(controller.get('isNonWizardUser')).to.be.false;
  68. });
  69. it("isWizardRunning is true, wizardUser is admin", function() {
  70. controller.setProperties({
  71. isWizardRunning: true,
  72. wizardUser: 'admin'
  73. });
  74. controller.propertyDidChange('isNonWizardUser');
  75. expect(controller.get('isNonWizardUser')).to.be.false;
  76. });
  77. it("isWizardRunning is true, wizardUser is admin2", function() {
  78. controller.setProperties({
  79. isWizardRunning: true,
  80. wizardUser: 'admin2'
  81. });
  82. controller.propertyDidChange('isNonWizardUser');
  83. expect(controller.get('isNonWizardUser')).to.be.true;
  84. });
  85. });
  86. describe("#setUser()", function() {
  87. beforeEach(function () {
  88. sinon.stub(controller, 'postUserPref', Em.K);
  89. sinon.stub(App.router, 'get').returns('admin');
  90. });
  91. afterEach(function () {
  92. controller.postUserPref.restore();
  93. App.router.get.restore();
  94. });
  95. it("post user pref", function() {
  96. controller.setUser('ctrl1');
  97. expect(controller.postUserPref.calledWith(controller.get('PREF_KEY'), {
  98. userName: 'admin',
  99. controllerName: 'ctrl1'
  100. })).to.be.true;
  101. });
  102. });
  103. describe("#resetUser()", function() {
  104. beforeEach(function () {
  105. sinon.stub(controller, 'postUserPref', Em.K);
  106. });
  107. afterEach(function () {
  108. controller.postUserPref.restore();
  109. });
  110. it("post user pref", function() {
  111. controller.resetUser('ctrl1');
  112. expect(controller.postUserPref.calledWith(controller.get('PREF_KEY'), null)).to.be.true;
  113. });
  114. });
  115. describe("#getUser()", function() {
  116. beforeEach(function () {
  117. sinon.stub(controller, 'getUserPref', Em.K);
  118. });
  119. afterEach(function () {
  120. controller.getUserPref.restore();
  121. });
  122. it("get user pref", function() {
  123. controller.getUser('ctrl1');
  124. expect(controller.getUserPref.calledWith(controller.get('PREF_KEY'))).to.be.true;
  125. });
  126. });
  127. describe("#getUserPrefSuccessCallback()", function() {
  128. it("data is null", function() {
  129. controller.getUserPrefSuccessCallback(null);
  130. expect(controller.get('wizardUser')).to.be.null;
  131. expect(controller.get('controllerName')).to.be.null;
  132. });
  133. it("data is correct", function() {
  134. controller.getUserPrefSuccessCallback({userName: 'admin', controllerName: 'ctrl1'});
  135. expect(controller.get('wizardUser')).to.equal('admin');
  136. expect(controller.get('controllerName')).to.equal('ctrl1');
  137. });
  138. });
  139. describe("#getUserPrefErrorCallback()", function() {
  140. beforeEach(function () {
  141. sinon.stub(controller, 'resetUser', Em.K);
  142. });
  143. afterEach(function () {
  144. controller.resetUser.restore();
  145. });
  146. it("reset wizard-data", function() {
  147. controller.getUserPrefErrorCallback();
  148. expect(controller.resetUser.calledOnce).to.be.true;
  149. });
  150. });
  151. });