cluster_states_test.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. describe('response', function () {
  55. beforeEach(function () {
  56. status.getUserPrefSuccessCallback(response);
  57. });
  58. Em.keys(response).forEach(function (key) {
  59. it(key, function () {
  60. expect(status.get(key)).to.equal(response[key]);
  61. });
  62. });
  63. });
  64. describe('compressedResponse', function () {
  65. beforeEach(function () {
  66. status.getUserPrefSuccessCallback(compressedResponse);
  67. });
  68. Em.keys(response2).forEach(function (key) {
  69. it(key, function () {
  70. expect(status.get(key)).to.equal(response2[key]);
  71. });
  72. });
  73. });
  74. });
  75. describe('#setClusterStatus', function () {
  76. beforeEach(function() {
  77. sinon.stub(status, 'postUserPref', function() {
  78. return $.ajax();
  79. });
  80. });
  81. afterEach(function () {
  82. status.postUserPref.restore();
  83. });
  84. it('should set cluster status in non-test mode', function () {
  85. var clusterStatus = status.setClusterStatus(newValue);
  86. expect(clusterStatus).to.eql(newValue);
  87. });
  88. });
  89. });