sub_section_test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.SubSection.createRecord();
  22. }
  23. describe('App.SubSection', function () {
  24. beforeEach(function () {
  25. model = getModel();
  26. });
  27. App.TestAliases.testAsComputedAnd(getModel(), 'showTabs', ['hasTabs', 'someSubSectionTabIsVisible']);
  28. App.TestAliases.testAsComputedAnd(getModel(), 'addLeftVerticalSplitter', ['!isFirstColumn', 'leftVerticalSplitter']);
  29. App.TestAliases.testAsComputedAnd(getModel(), 'showTopSplitter', ['!isFirstRow', '!border']);
  30. App.TestAliases.testAsComputedAnd(getModel(), 'isSectionVisible', ['!isHiddenByFilter', '!isHiddenByConfig', 'someConfigIsVisible']);
  31. describe('#errorsCount', function () {
  32. beforeEach(function () {
  33. model.set('configs', [
  34. App.ServiceConfigProperty.create({isValid: true}),
  35. App.ServiceConfigProperty.create({isValid: false}),
  36. App.ServiceConfigProperty.create({isValid: false}),
  37. App.ServiceConfigProperty.create({isValid: false}),
  38. ]);
  39. });
  40. it('should use configs.@each.isValid', function () {
  41. expect(model.get('errorsCount')).to.equal(3);
  42. });
  43. it('should use configs.@each.isValidOverride', function() {
  44. // original value is valid
  45. var validOriginalSCP = model.get('configs').objectAt(0);
  46. // add override with not valid value
  47. validOriginalSCP.set('isValidOverride', false);
  48. validOriginalSCP.set('isValid', true);
  49. expect(model.get('errorsCount')).to.equal(3);
  50. });
  51. });
  52. describe('#isHiddenByFilter', function () {
  53. Em.A([
  54. {
  55. configs: [],
  56. e: false,
  57. m: 'Can\'t be hidden if there is no configs'
  58. },
  59. {
  60. configs: [Em.Object.create({isHiddenByFilter: true, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
  61. e: true,
  62. m: 'All configs are hidden'
  63. },
  64. {
  65. configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
  66. e: false,
  67. m: 'Some configs are hidden'
  68. },
  69. {
  70. configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
  71. e: false,
  72. m: 'Some configs are hidden'
  73. },
  74. {
  75. configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: false, isVisible: true})],
  76. e: false,
  77. m: 'No configs are hidden'
  78. }
  79. ]).forEach(function (test) {
  80. it(test.m, function () {
  81. model.set('configs', test.configs);
  82. expect(model.get('isHiddenByFilter')).to.equal(test.e);
  83. })
  84. });
  85. });
  86. });