cluster_states_test.js 3.2 KB

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