config_group_test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 modelSetup = require('test/init_model_test');
  20. require('models/config_group');
  21. require('models/host');
  22. var configGroup,
  23. hostRecord,
  24. hosts = [
  25. Em.Object.create({
  26. id: 'host0',
  27. hostName: 'host0'
  28. }),
  29. Em.Object.create({
  30. id: 'host1',
  31. hostName: 'host1'
  32. })
  33. ],
  34. host = {
  35. id: 'host0',
  36. host_name: 'host0'
  37. },
  38. properties = [
  39. {
  40. name: 'n0',
  41. value: 'v0'
  42. },
  43. {
  44. name: 'n1',
  45. value: 'v1'
  46. }
  47. ],
  48. setParentConfigGroup = function (configGroup, hosts) {
  49. configGroup.set('parentConfigGroup', App.ConfigGroup.create());
  50. configGroup.set('parentConfigGroup.hosts', hosts);
  51. };
  52. describe('App.ConfigGroup', function () {
  53. beforeEach(function () {
  54. configGroup = App.ConfigGroup.create();
  55. });
  56. describe('#displayName', function () {
  57. it('should equal name if maximum length is not exceeded', function () {
  58. configGroup.set('name', 'n');
  59. expect(configGroup.get('displayName')).to.equal(configGroup.get('name'));
  60. });
  61. it('should be shortened if maximum length is exceeded', function () {
  62. var maxLength = App.config.CONFIG_GROUP_NAME_MAX_LENGTH;
  63. for (var i = maxLength + 1, name = ''; i--; ) {
  64. name += 'n';
  65. }
  66. configGroup.set('name', name);
  67. expect(configGroup.get('displayName')).to.contain('...');
  68. expect(configGroup.get('displayName')).to.have.length(2 * Math.floor(maxLength / 2) + 3);
  69. });
  70. });
  71. describe('#displayNameHosts', function () {
  72. it('should indicate the number of hosts', function () {
  73. var displayName = configGroup.get('displayName');
  74. configGroup.set('hosts', []);
  75. expect(configGroup.get('displayNameHosts')).to.equal(displayName + ' (0)');
  76. configGroup.set('hosts', hosts);
  77. expect(configGroup.get('displayNameHosts')).to.equal(displayName + ' (2)');
  78. });
  79. });
  80. describe('#availableHosts', function () {
  81. beforeEach(function () {
  82. App.clusterStatus.set('clusterState', 'DEFAULT');
  83. App.store.load(App.Host, host);
  84. hostRecord = App.Host.find().findProperty('hostName', 'host0');
  85. setParentConfigGroup(configGroup, hosts);
  86. });
  87. afterEach(function () {
  88. modelSetup.deleteRecord(hostRecord);
  89. });
  90. it('should return an empty array as default', function () {
  91. configGroup.set('isDefault', true);
  92. expect(configGroup.get('availableHosts')).to.eql([]);
  93. });
  94. it('should return an empty array if there are no unused hosts', function () {
  95. configGroup.set('parentConfigGroup', App.ConfigGroup.create());
  96. expect(configGroup.get('availableHosts')).to.eql([]);
  97. });
  98. it('should take hosts from parentConfigGroup', function () {
  99. setParentConfigGroup(configGroup, hosts);
  100. expect(configGroup.get('availableHosts')).to.have.length(2);
  101. });
  102. });
  103. describe('#isAddHostsDisabled', function () {
  104. beforeEach(function () {
  105. hostRecord = App.Host.createRecord(host);
  106. setParentConfigGroup(configGroup, hosts);
  107. configGroup.set('isDefault', false);
  108. configGroup.set('availableHosts', []);
  109. });
  110. afterEach(function () {
  111. modelSetup.deleteRecord(hostRecord);
  112. });
  113. it('should be false', function () {
  114. expect(configGroup.get('isAddHostsDisabled')).to.be.false;
  115. });
  116. it('should be true', function () {
  117. App.clusterStatus.set('clusterState', 'DEFAULT');
  118. configGroup.set('isDefault', true);
  119. expect(configGroup.get('isAddHostsDisabled')).to.be.true;
  120. configGroup.set('availableHosts', hosts);
  121. expect(configGroup.get('isAddHostsDisabled')).to.be.true;
  122. });
  123. });
  124. describe('#propertiesList', function () {
  125. it('should be formed from properties', function () {
  126. configGroup.set('properties', properties);
  127. properties.forEach(function (item) {
  128. Em.keys(item).forEach(function (prop) {
  129. expect(configGroup.get('propertiesList')).to.contain(item[prop]);
  130. });
  131. });
  132. expect(configGroup.get('propertiesList')).to.have.length(24);
  133. });
  134. });
  135. });