123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- /**
- * 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/wizard/step5_view');
- var stringUtils = require('utils/string_utils');
- var view;
- describe('App.WizardStep5View', function() {
- beforeEach(function() {
- view = App.WizardStep5View.create({
- controller: App.WizardStep5Controller.create({})
- });
- });
- describe("#title", function() {
- beforeEach(function () {
- view.set('controller.content', Em.Object.create());
- });
- it("controller name is reassignMasterController", function() {
- view.set('controller.content.controllerName', 'reassignMasterController');
- view.propertyDidChange('title');
- expect(view.get('title')).to.equal(Em.I18n.t('installer.step5.reassign.header'));
- });
- it("controller name is ''", function() {
- view.set('controller.content.controllerName', '');
- view.propertyDidChange('title');
- expect(view.get('title')).to.equal(Em.I18n.t('installer.step5.header'));
- });
- });
- describe("#setCoHostedComponentText()", function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns([
- Em.Object.create({
- componentName: 'C1',
- displayName: 'c1',
- isOtherComponentCoHosted: true,
- stackService: {
- isSelected: true
- },
- coHostedComponents: ['C2']
- }),
- Em.Object.create({
- componentName: 'C2',
- displayName: 'c2',
- isOtherComponentCoHosted: false,
- stackService: {
- isSelected: true
- }
- })
- ]);
- sinon.stub(stringUtils, 'getFormattedStringFromArray', function(str){
- return str;
- });
- });
- afterEach(function () {
- App.StackServiceComponent.find.restore();
- stringUtils.getFormattedStringFromArray.restore();
- });
- it("isReassignWizard - true", function () {
- view.set('controller.isReassignWizard', true);
- view.setCoHostedComponentText();
- expect(view.get('coHostedComponentText')).to.be.empty;
- });
- it("isReassignWizard - false", function () {
- view.set('controller.isReassignWizard', false);
- view.setCoHostedComponentText();
- expect(view.get('coHostedComponentText')).to.equal('<br/>' + Em.I18n.t('installer.step5.body.coHostedComponents').format(['c1', 'c2']));
- });
- });
- describe('#didInsertElement', function() {
- beforeEach(function () {
- sinon.stub(view.get('controller'), 'loadStep', Em.K);
- });
- afterEach(function () {
- view.get('controller').loadStep.restore();
- });
- it('should call controller.loadStep', function() {
- view.didInsertElement();
- expect(view.get('controller').loadStep.calledOnce).to.equal(true);
- });
- });
- describe('#shouldUseInputs', function() {
- Em.A([
- {range: 25, e: false},
- {range: 26, e: true},
- {range: 24, e: false}
- ]).forEach(function (test) {
- it(test.e + ' for ' + test.range + ' hosts', function () {
- view.set('controller.hosts', d3.range(0, test.range).map(function() {return {};}));
- expect(view.get('shouldUseInputs')).to.be.equal(test.e);
- });
- });
- });
- });
- describe('App.SelectHostView', function() {
- var models = require('test/init_model_test');
- beforeEach(function() {
- view = App.SelectHostView.create({
- controller: App.WizardStep5Controller.create({}),
- $: function() {return {typeahead: function(){return {on: Em.K}}}},
- updateErrorStatus: Em.K
- });
- });
- describe('#change', function() {
- beforeEach(function() {
- sinon.stub(view, 'initContent', Em.K);
- sinon.stub(view, 'changeHandler', Em.K);
- models.setupStackServiceComponent();
- });
- afterEach(function() {
- view.initContent.restore();
- view.changeHandler.restore();
- models.cleanStackServiceComponent();
- });
- it('should call initContent', function() {
- view.change();
- expect(view.initContent.calledOnce).to.be.true;
- });
- });
- describe('#didInsertElement', function() {
- it('should set value', function() {
- view.set('value', '');
- view.set('component', {selectedHost: 'h1'});
- view.didInsertElement();
- expect(view.get('value')).to.equal('h1');
- });
- });
- describe('#changeHandler', function() {
- beforeEach(function() {
- view.get('controller').reopen({multipleComponents: ['HBASE_MASTER', 'ZOOKEEPER_SERVER']});
- view.set('component', {component_name: 'ZOOKEEPER_SERVER', serviceComponentId: 1});
- view.set('controller.hosts', [Em.Object.create({host_info: 'h1 info', host_name: 'h1'})]);
- view.set('value', 'h1 info');
- view.set('controller.rebalanceComponentHostsCounter', 0);
- view.set('controller.componentToRebalance', '');
- sinon.stub(view.get('controller'), 'assignHostToMaster', Em.K);
- sinon.stub(view.get('controller'), 'updateIsHostNameValidFlag', Em.K);
- sinon.stub(view, 'shouldChangeHandlerBeCalled', function() {return true;});
- });
- afterEach(function() {
- view.get('controller').assignHostToMaster.restore();
- view.get('controller').updateIsHostNameValidFlag.restore();
- view.shouldChangeHandlerBeCalled.restore();
- });
- it('shouldn\'t do nothing if view is destroyed', function() {
- view.set('state', 'destroyed');
- expect(view.get('controller').assignHostToMaster.called).to.be.false;
- });
- it('should call assignHostToMaster', function() {
- view.changeHandler();
- expect(view.get('controller').assignHostToMaster.args[0]).to.be.eql(['ZOOKEEPER_SERVER', 'h1 info', 1]);
- });
- it('should increment rebalanceComponentHostsCounter if component it is multiple', function() {
- view.set('component', {component_name: 'ZOOKEEPER_SERVER'});
- view.changeHandler();
- expect(view.get('controller.rebalanceComponentHostsCounter')).to.equal(1);
- });
- it('should set componentToRebalance', function() {
- view.changeHandler();
- expect(view.get('controller.componentToRebalance')).to.equal('ZOOKEEPER_SERVER');
- });
- });
- });
- describe('App.InputHostView', function() {
- beforeEach(function() {
- view = App.InputHostView.create({
- controller: App.WizardStep5Controller.create({}),
- $: function() {return {typeahead: function(){return {on: Em.K}}}},
- updateErrorStatus: Em.K
- });
- });
- describe('#didInsertElement', function() {
- beforeEach(function() {
- sinon.stub(view, 'initContent', Em.K);
- view.set('content', [Em.Object.create({host_name: 'h1', host_info: 'h1 info'})]);
- view.set('component', {selectedHost: 'h1'});
- });
- afterEach(function() {
- view.initContent.restore();
- });
- it('should call initContent', function() {
- view.didInsertElement();
- expect(view.initContent.calledOnce).to.equal(true);
- });
- it('should set selectedHost host_name to value', function() {
- view.set('value', '');
- view.didInsertElement();
- expect(view.get('value')).to.equal('h1');
- });
- });
- describe('#changeHandler', function() {
- beforeEach(function() {
- view.get('controller').reopen({multipleComponents: ['HBASE_MASTER', 'ZOOKEEPER_SERVER']});
- view.set('component', {component_name: 'ZOOKEEPER_SERVER', serviceComponentId: 1});
- view.set('controller.hosts', [Em.Object.create({host_info: 'h1 info', host_name: 'h1'})]);
- view.set('value', 'h1');
- view.set('controller.rebalanceComponentHostsCounter', 0);
- view.set('controller.componentToRebalance', '');
- sinon.stub(view.get('controller'), 'assignHostToMaster', Em.K);
- sinon.stub(view.get('controller'), 'updateIsHostNameValidFlag', Em.K);
- sinon.stub(view, 'shouldChangeHandlerBeCalled', function() {return true;});
- });
- afterEach(function() {
- view.get('controller').assignHostToMaster.restore();
- view.get('controller').updateIsHostNameValidFlag.restore();
- view.shouldChangeHandlerBeCalled.restore();
- });
- it('shouldn\'t do nothing if view is destroyed', function() {
- view.set('state', 'destroyed');
- expect(view.get('controller').assignHostToMaster.called).to.be.false;
- });
- it('should call assignHostToMaster', function() {
- view.changeHandler();
- expect(view.get('controller').assignHostToMaster.args[0]).to.be.eql(['ZOOKEEPER_SERVER', 'h1', 1]);
- });
- it('should increment rebalanceComponentHostsCounter if component it is multiple', function() {
- view.set('component', {component_name: 'ZOOKEEPER_SERVER'});
- view.changeHandler();
- expect(view.get('controller.rebalanceComponentHostsCounter')).to.equal(1);
- });
- it('should set componentToRebalance', function() {
- view.changeHandler();
- expect(view.get('controller.componentToRebalance')).to.equal('ZOOKEEPER_SERVER');
- });
- });
- describe('#getAvailableHosts', function() {
- var tests = Em.A([
- {
- hosts: Em.A([]),
- selectedHost: 'h2',
- componentName: 'ZOOKEEPER_SERVER',
- selectedServicesMasters: Em.A([
- Em.Object.create({component_name: 'ZOOKEEPER_SERVER', selectedHost: 'h1'})
- ]),
- m: 'Empty hosts',
- e: []
- },
- {
- hosts: Em.A([
- Em.Object.create({host_name: 'h1'}),
- Em.Object.create({host_name: 'h2'})
- ]),
- selectedHost: 'h2',
- componentName: 'c1',
- selectedServicesMasters: Em.A([
- Em.Object.create({component_name: 'c2', selectedHost: 'h1'})
- ]),
- m: 'Two hosts',
- e: ['h1', 'h2']
- },
- {
- hosts: Em.A([
- Em.Object.create({host_name: 'h1'}),
- Em.Object.create({host_name: 'h2'})
- ]),
- selectedHost: 'h2',
- componentName: 'ZOOKEEPER_SERVER',
- selectedServicesMasters: Em.A([
- Em.Object.create({component_name: 'ZOOKEEPER_SERVER', selectedHost: 'h1'})
- ]),
- m: 'Two hosts, ZOOKEEPER_SERVER',
- e: ['h2']
- },
- {
- hosts: Em.A([
- Em.Object.create({host_name: 'h1'}),
- Em.Object.create({host_name: 'h2'})
- ]),
- selectedHost: 'h2',
- componentName: 'HBASE_MASTER',
- selectedServicesMasters: Em.A([
- Em.Object.create({component_name: 'HBASE_MASTER', selectedHost: 'h1'})
- ]),
- m: 'Two hosts, HBASE_MASTER',
- e: ['h2']
- }
- ]);
- tests.forEach(function(test) {
- it(test.m, function() {
- view.set('controller.hosts', test.hosts);
- view.get('controller').reopen({multipleComponents: ['HBASE_MASTER', 'ZOOKEEPER_SERVER']});
- view.set('component', {component_name: test.componentName});
- view.set('controller.selectedServicesMasters', test.selectedServicesMasters);
- var r = view.getAvailableHosts();
- expect(r.mapProperty('host_name')).to.eql(test.e);
- });
- });
- });
- describe('#rebalanceComponentHostsOnce', function() {
- var tests = Em.A([
- {
- componentName: 'c1',
- componentToRebalance: 'c2',
- content: [{}],
- m: 'componentName not equal to componentToRebalance',
- e: {
- initContent: false
- }
- },
- {
- componentName: 'c2',
- componentToRebalance: 'c2',
- content: [{}],
- m: 'componentName equal to componentToRebalance',
- e: {
- initContent: true
- }
- }
- ]);
- beforeEach(function () {
- sinon.stub(view, 'initContent', Em.K);
- });
- afterEach(function () {
- view.initContent.restore();
- });
- tests.forEach(function(test) {
- it(test.m, function() {
- view.set('content', test.content);
- view.set('component', {component_name: test.componentName});
- view.set('controller.componentToRebalance', test.componentToRebalance);
- view.rebalanceComponentHostsOnce();
- expect(view.initContent.calledOnce).to.equal(test.e.initContent);
- });
- });
- });
- describe('#initContent', function() {
- var tests = Em.A([
- {
- hosts: 25,
- m: 'not lazy loading, 25 hosts, no selected host',
- e: 25
- },
- {
- hosts: 25,
- h: 4,
- m: 'not lazy loading, 25 hosts, one selected host',
- e: 25
- }
- ]);
- tests.forEach(function(test) {
- it(test.m, function() {
- view.reopen({getAvailableHosts: function() {return d3.range(0, test.hosts).map(function(indx){return Em.Object.create({host_name: indx})});}});
- if (test.h) {
- view.set('selectedHost', test.h);
- }
- view.initContent();
- expect(view.get('content.length')).to.equal(test.e);
- });
- });
- });
- describe('#change', function() {
- beforeEach(function() {
- sinon.stub(view, 'changeHandler', Em.K);
- });
- afterEach(function() {
- view.changeHandler.restore();
- });
- it('shouldn\'t do nothing if view is destroyed', function() {
- view.set('controller.hostNameCheckTrigger', false);
- view.set('state', 'destroyed');
- view.change();
- expect(view.get('controller.hostNameCheckTrigger')).to.equal(false);
- });
- it('should toggle hostNameCheckTrigger', function() {
- view.set('controller.hostNameCheckTrigger', false);
- view.change();
- expect(view.get('controller.hostNameCheckTrigger')).to.equal(true);
- });
- });
- });
- describe('App.RemoveControlView', function() {
- beforeEach(function() {
- view = App.RemoveControlView.create({
- controller: App.WizardStep5Controller.create({})
- });
- });
- describe('#click', function() {
- beforeEach(function() {
- sinon.stub(view.get('controller'), 'removeComponent', Em.K);
- });
- afterEach(function() {
- view.get('controller').removeComponent.restore();
- });
- it('should call removeComponent', function() {
- view.set('serviceComponentId', 1);
- view.set('componentName', 'c1');
- view.click();
- expect(view.get('controller').removeComponent.calledWith('c1', 1)).to.equal(true);
- });
- });
- });
- describe('App.AddControlView', function() {
- beforeEach(function() {
- view = App.AddControlView.create({
- controller: App.WizardStep5Controller.create({})
- });
- });
- describe('#click', function() {
- beforeEach(function() {
- sinon.stub(view.get('controller'), 'addComponent', Em.K);
- });
- afterEach(function() {
- view.get('controller').addComponent.restore();
- });
- it('should call addComponent', function() {
- view.set('componentName', 'c1');
- view.click();
- expect(view.get('controller').addComponent.calledWith('c1')).to.equal(true);
- });
- });
- });
|