cluster_states_test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. afterEach(function () {
  68. App.get.restore();
  69. });
  70. it('should return false in test mode', function () {
  71. sinon.stub(App, 'get', function(k) {
  72. if (k === 'testMode') return true;
  73. return Em.get(App, k);
  74. });
  75. expect(status.setClusterStatus()).to.be.false;
  76. });
  77. it('should set cluster status in non-test mode', function () {
  78. sinon.stub(App, 'get', function(k) {
  79. if (k === 'testMode') return false;
  80. return Em.get(App, k);
  81. });
  82. var clusterStatus = status.setClusterStatus(newValue);
  83. expect(clusterStatus).to.eql(newValue);
  84. });
  85. });
  86. describe('#makeRequestAsync', function () {
  87. it('should be false after synchronous updateFromServer', function () {
  88. status.updateFromServer();
  89. expect(status.get('makeRequestAsync')).to.be.false;
  90. });
  91. it('should be true after asynchronous updateFromServer', function () {
  92. status.updateFromServer(true);
  93. expect(status.get('makeRequestAsync')).to.be.true;
  94. });
  95. it('should be false after synchronous setClusterStatus with no opt specified', function () {
  96. status.setClusterStatus({clusterName: 'name'});
  97. expect(status.get('makeRequestAsync')).to.be.false;
  98. });
  99. });
  100. });