cluster_states_test.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/cluster_states');
  20. var status = App.clusterStatus,
  21. notInstalledStates = ['CLUSTER_NOT_CREATED_1', 'CLUSTER_DEPLOY_PREP_2', 'CLUSTER_INSTALLING_3', 'SERVICE_STARTING_3'],
  22. values = {
  23. clusterName: 'name',
  24. clusterState: 'STACK_UPGRADING',
  25. wizardControllerName: 'wizardStep0Controller',
  26. localdb: {}
  27. },
  28. response = {
  29. clusterState: 'DEFAULT',
  30. clusterName: 'cluster'
  31. },
  32. newValue = {
  33. clusterName: 'name',
  34. clusterState: 'STACK_UPGRADING',
  35. wizardControllerName: 'wizardStep0Controller'
  36. };
  37. describe('App.clusterStatus', function () {
  38. describe('#isInstalled', function () {
  39. notInstalledStates.forEach(function (item) {
  40. it('should be false', function () {
  41. status.set('clusterState', item);
  42. expect(status.get('isInstalled')).to.be.false;
  43. });
  44. });
  45. it('should be true', function () {
  46. status.set('clusterState', 'DEFAULT');
  47. expect(status.get('isInstalled')).to.be.true;
  48. });
  49. });
  50. describe('#value', function () {
  51. it('should be set from properties', function () {
  52. Em.keys(values).forEach(function (key) {
  53. status.set(key, values[key]);
  54. });
  55. expect(status.get('value')).to.eql(values);
  56. });
  57. });
  58. describe('#getUserPrefSuccessCallback', function () {
  59. it('should set the cluster parameters', function () {
  60. status.getUserPrefSuccessCallback(response);
  61. Em.keys(response).forEach(function (key) {
  62. expect(status.get(key)).to.equal(response[key]);
  63. });
  64. });
  65. });
  66. describe('#setClusterStatus', function () {
  67. beforeEach(function() {
  68. sinon.stub(status, 'postUserPref', function() {
  69. return $.ajax();
  70. });
  71. });
  72. afterEach(function () {
  73. status.postUserPref.restore();
  74. App.get.restore();
  75. });
  76. it('should return false in test mode', function () {
  77. sinon.stub(App, 'get', function(k) {
  78. if (k === 'testMode') return true;
  79. return Em.get(App, k);
  80. });
  81. expect(status.setClusterStatus()).to.be.false;
  82. });
  83. it('should set cluster status in non-test mode', function () {
  84. sinon.stub(App, 'get', function(k) {
  85. if (k === 'testMode') return false;
  86. return Em.get(App, k);
  87. });
  88. var clusterStatus = status.setClusterStatus(newValue);
  89. expect(clusterStatus).to.eql(newValue);
  90. });
  91. });
  92. });