123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- require('views/common/chart/pie');
- require('views/common/configs/services_config');
- describe('App.ServiceConfigView', function () {
- var controller = App.WizardStep7Controller.create({
- selectedServiceObserver: function(){},
- switchConfigGroupConfigs: function(){}
- });
- var view = App.ServiceConfigView.create({
- controller: controller
- });
- var testCases = [
- {
- title: 'selectedConfigGroup is null',
- result: {
- 'category1': false,
- 'category2': true,
- 'category3': false
- },
- selectedConfigGroup: null,
- selectedService: {
- serviceName: 'TEST',
- configCategories: [
- App.ServiceConfigCategory.create({ name: 'category1', canAddProperty: false}),
- App.ServiceConfigCategory.create({ name: 'category2', siteFileName: 'xml', canAddProperty: true}),
- App.ServiceConfigCategory.create({ name: 'category3', siteFileName: 'xml', canAddProperty: false})
- ]
- }
- },
- {
- title: 'selectedConfigGroup is default group',
- result: {
- 'category1': true,
- 'category2': true,
- 'category3': false
- },
- selectedConfigGroup: {isDefault: true},
- selectedService: {
- serviceName: 'TEST',
- configCategories: [
- App.ServiceConfigCategory.create({ name: 'category1', canAddProperty: true}),
- App.ServiceConfigCategory.create({ name: 'category2', siteFileName: 'xml', canAddProperty: true}),
- App.ServiceConfigCategory.create({ name: 'category3', siteFileName: 'xml', canAddProperty: false})
- ]
- }
- },
- {
- title: 'selectedConfigGroup is not default group',
- result: {
- 'category1': false,
- 'category2': false
- },
- selectedConfigGroup: {},
- selectedService: {
- serviceName: 'TEST',
- configCategories: [
- App.ServiceConfigCategory.create({ name: 'category1', siteFileName: 'xml', canAddProperty: true}),
- App.ServiceConfigCategory.create({ name: 'category2', siteFileName: 'xml', canAddProperty: false})
- ]
- }
- }
- ];
- describe('#checkCanEdit', function () {
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('selectedService', test.selectedService);
- controller.set('selectedConfigGroup', test.selectedConfigGroup);
- view.checkCanEdit();
- controller.get('selectedService.configCategories').forEach(function (category) {
- expect(category.get('canAddProperty')).to.equal(test.result[category.get('name')]);
- });
- });
- });
- });
- });
- describe('App.ServiceConfigsByCategoryView', function () {
- var view = App.ServiceConfigsByCategoryView.create({
- serviceConfigs: []
- });
- var result = [1, 2, 3, 4];
- var testData = [
- {
- title: 'four configs in correct order',
- configs: [
- Em.Object.create({index: 1, resultId: 1}),
- Em.Object.create({index: 2, resultId: 2}),
- Em.Object.create({index: 3, resultId: 3}),
- Em.Object.create({index: 4, resultId: 4})
- ]
- },
- {
- title: 'four configs in reverse order',
- configs: [
- Em.Object.create({index: 4, resultId: 4}),
- Em.Object.create({index: 3, resultId: 3}),
- Em.Object.create({index: 2, resultId: 2}),
- Em.Object.create({index: 1, resultId: 1})
- ]
- },
- {
- title: 'four configs in random order',
- configs: [
- Em.Object.create({index: 3, resultId: 3}),
- Em.Object.create({index: 4, resultId: 4}),
- Em.Object.create({index: 1, resultId: 1}),
- Em.Object.create({index: 2, resultId: 2})
- ]
- },
- {
- title: 'four configs with no index',
- configs: [
- Em.Object.create({resultId: 1}),
- Em.Object.create({resultId: 2}),
- Em.Object.create({resultId: 3}),
- Em.Object.create({resultId: 4})
- ]
- },
- {
- title: 'four configs but one with index',
- configs: [
- Em.Object.create({resultId: 2}),
- Em.Object.create({resultId: 3}),
- Em.Object.create({resultId: 4}),
- Em.Object.create({index: 1, resultId: 1})
- ]
- },
- {
- title: 'index is null or not number',
- configs: [
- Em.Object.create({index: null, resultId: 3}),
- Em.Object.create({index: 1, resultId: 1}),
- Em.Object.create({index: 2, resultId: 2}),
- Em.Object.create({index: 'a', resultId: 4})
- ]
- },
- {
- title: 'four configs when indexes skipped',
- configs: [
- Em.Object.create({index: 88, resultId: 3}),
- Em.Object.create({index: 67, resultId: 2}),
- Em.Object.create({index: 111, resultId: 4}),
- Em.Object.create({index: 3, resultId: 1})
- ]
- }
- ];
- describe('#sortByIndex', function () {
- testData.forEach(function(_test){
- it(_test.title, function () {
- expect(view.sortByIndex(_test.configs).mapProperty('resultId')).to.deep.equal(result);
- })
- })
- });
- describe('#updateReadOnlyFlags', function () {
- it('if canEdit is true then isEditable flag of configs shouldn\'t be changed', function () {
- view.set('canEdit', true);
- view.set('serviceConfigs', [
- Em.Object.create({
- name: 'config1',
- isEditable: true
- }),
- Em.Object.create({
- name: 'config2',
- isEditable: false
- })
- ]);
- view.updateReadOnlyFlags();
- expect(view.get('serviceConfigs').findProperty('name', 'config1').get('isEditable')).to.equal(true);
- expect(view.get('serviceConfigs').findProperty('name', 'config2').get('isEditable')).to.equal(false);
- });
- it('if canEdit is false then configs shouldn\'t be editable', function () {
- view.set('canEdit', false);
- view.set('serviceConfigs', [
- Em.Object.create({
- name: 'config1',
- isEditable: true
- }),
- Em.Object.create({
- name: 'config2',
- isEditable: false
- })
- ]);
- view.updateReadOnlyFlags();
- expect(view.get('serviceConfigs').findProperty('name', 'config1').get('isEditable')).to.equal(false);
- expect(view.get('serviceConfigs').findProperty('name', 'config2').get('isEditable')).to.equal(false);
- });
- it('if canEdit is false then config overrides shouldn\'t be editable', function () {
- view.set('canEdit', false);
- view.set('serviceConfigs', [
- Em.Object.create({
- name: 'config',
- isEditable: true,
- overrides: [
- Em.Object.create({
- name: 'override1',
- isEditable: true
- }),
- Em.Object.create({
- name: 'override2',
- isEditable: false
- })
- ]
- })
- ]);
- view.updateReadOnlyFlags();
- var overrides = view.get('serviceConfigs').findProperty('name', 'config').get('overrides');
- expect(overrides.findProperty('name', 'override1').get('isEditable')).to.equal(false);
- expect(overrides.findProperty('name', 'override2').get('isEditable')).to.equal(false);
- });
- it('if canEdit is true then isEditable flag of overrides shouldn\'t be changed', function () {
- view.set('canEdit', true);
- view.set('serviceConfigs', [
- Em.Object.create({
- name: 'config',
- isEditable: true,
- overrides: [
- Em.Object.create({
- name: 'override1',
- isEditable: true
- }),
- Em.Object.create({
- name: 'override2',
- isEditable: false
- })
- ]
- })
- ]);
- view.updateReadOnlyFlags();
- var overrides = view.get('serviceConfigs').findProperty('name', 'config').get('overrides');
- expect(overrides.findProperty('name', 'override1').get('isEditable')).to.equal(true);
- expect(overrides.findProperty('name', 'override2').get('isEditable')).to.equal(false);
- })
- })
- });
|