user_settings_controller_test.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. var userSettingsController;
  20. describe('App.UserSettingsController', function () {
  21. beforeEach(function () {
  22. userSettingsController = App.UserSettingsController.create();
  23. });
  24. describe('#userSettingsKeys', function () {
  25. it('should not be empty', function () {
  26. expect(Object.keys(userSettingsController.get('userSettingsKeys'))).to.have.length.gt(0);
  27. });
  28. });
  29. describe('#showSettingsPopup', function() {
  30. var dataToShowRes = {};
  31. beforeEach(function () {
  32. sinon.stub(App.ModalPopup, 'show', function(dataToShow){
  33. dataToShowRes = dataToShow;
  34. });
  35. sinon.stub(App, 'isAccessible').returns(true);
  36. var emulatorClass = function() {};
  37. emulatorClass.prototype.done = function(func) {
  38. if (func) {
  39. func();
  40. }
  41. };
  42. var emulator = new emulatorClass();
  43. sinon.stub(userSettingsController, 'dataLoading').returns(emulator);
  44. });
  45. afterEach(function () {
  46. App.isAccessible.restore();
  47. App.ModalPopup.show.restore();
  48. userSettingsController.dataLoading.restore();
  49. });
  50. it ('Should show settings popup', function() {
  51. userSettingsController.showSettingsPopup();
  52. dataToShowRes = JSON.parse(JSON.stringify(dataToShowRes));
  53. expect(dataToShowRes).to.eql({
  54. "header": "User Settings",
  55. "primary": "Save"
  56. });
  57. });
  58. });
  59. describe('#getUserPrefErrorCallback', function() {
  60. it ('Should set currentPrefObject', function() {
  61. applicationController.getUserPrefErrorCallback({status: 404}, {}, {});
  62. expect(applicationController.get('currentPrefObject')).to.be.true;
  63. });
  64. });
  65. describe('#getUserPrefSuccessCallback', function() {
  66. it ('Should set currentPrefObject', function() {
  67. applicationController.getUserPrefSuccessCallback({status: 200}, {}, {});
  68. expect(applicationController.get('currentPrefObject')).to.be.eql({status: 200});
  69. });
  70. });
  71. describe('#updateUserPrefWithDefaultValues', function () {
  72. beforeEach(function () {
  73. sinon.stub(userSettingsController, 'postUserPref', Em.K);
  74. });
  75. afterEach(function () {
  76. userSettingsController.postUserPref.restore();
  77. });
  78. it('should update user pref with default values', function () {
  79. userSettingsController.updateUserPrefWithDefaultValues(null, true);
  80. expect(userSettingsController.postUserPref.called).to.be.false;
  81. });
  82. it('should not update user pref with default values', function () {
  83. userSettingsController.updateUserPrefWithDefaultValues(null, false);
  84. expect(userSettingsController.postUserPref.called).to.be.true;
  85. });
  86. });
  87. });