stack_config_property_test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 model;
  20. function getModel() {
  21. return App.StackConfigProperty.createRecord();
  22. }
  23. describe('App.StackConfigProperty', function () {
  24. beforeEach(function () {
  25. model = getModel();
  26. });
  27. describe("#Attributes", function() {
  28. var testCases = [
  29. {
  30. propertyKey: 'type',
  31. propertyName: 'displayType',
  32. value: 't1',
  33. expectedValue: 't1',
  34. defaultValue: 'string'
  35. },
  36. {
  37. propertyKey: 'overridable',
  38. propertyName: 'isOverridable',
  39. value: false,
  40. expectedValue: false,
  41. defaultValue: true
  42. },
  43. {
  44. propertyKey: 'visible',
  45. propertyName: 'isVisible',
  46. value: false,
  47. expectedValue: false,
  48. defaultValue: true
  49. },
  50. {
  51. propertyKey: 'empty_value_valid',
  52. propertyName: 'isRequired',
  53. value: true,
  54. expectedValue: false,
  55. defaultValue: true
  56. },
  57. {
  58. propertyKey: 'editable_only_at_install',
  59. propertyName: 'isReconfigurable',
  60. value: true,
  61. expectedValue: false,
  62. defaultValue: true
  63. },
  64. {
  65. propertyKey: 'show_property_name',
  66. propertyName: 'showLabel',
  67. value: false,
  68. expectedValue: false,
  69. defaultValue: true
  70. },
  71. {
  72. propertyKey: 'read_only',
  73. propertyName: 'isEditable',
  74. value: false,
  75. expectedValue: false,
  76. defaultValue: true
  77. },
  78. {
  79. propertyKey: 'unit',
  80. propertyName: 'unit',
  81. value: 'mb',
  82. expectedValue: 'mb',
  83. defaultValue: ''
  84. }
  85. ];
  86. testCases.forEach(function(test) {
  87. it("valueAttributes is null, " + test.propertyName + " should be " + test.defaultValue, function() {
  88. model.set('valueAttributes', null);
  89. expect(model.get(test.propertyName)).to.equal(test.defaultValue);
  90. });
  91. it("valueAttributes is object, " + test.propertyName + " should be " + test.expectedValue, function() {
  92. var valueAttributes = {};
  93. valueAttributes[test.propertyKey] = test.value;
  94. model.set('valueAttributes', valueAttributes);
  95. expect(model.get(test.propertyName)).to.equal(test.expectedValue);
  96. });
  97. });
  98. });
  99. describe("#getAttribute()", function() {
  100. it("valueAttributes is null", function() {
  101. model.set('valueAttributes', null);
  102. expect(model.getAttribute('attr1', 'defVal')).to.equal('defVal');
  103. });
  104. it("valueAttributes is empty object", function() {
  105. model.set('valueAttributes', {});
  106. expect(model.getAttribute('attr1', 'defVal')).to.equal('defVal');
  107. });
  108. it("valueAttributes is correct object", function() {
  109. model.set('valueAttributes', {attr1: 'val'});
  110. expect(model.getAttribute('attr1', 'defVal')).to.equal('val');
  111. });
  112. });
  113. });