Skip to content

Commit

Permalink
AMBARI-25042 Cover host component view with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atkach committed Dec 13, 2018
1 parent e2f9318 commit bab7cf5
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 13 deletions.
20 changes: 8 additions & 12 deletions ambari-web/app/views/main/host/details/host_component_view.js
Expand Up @@ -57,11 +57,11 @@ App.HostComponentView = Em.View.extend({
*/
typeDisplay: function() {
if (this.get('content.isMaster')) {
return Em.I18n.t('common.master')
return Em.I18n.t('common.master');
} else if (this.get('content.isSlave')) {
return Em.I18n.t('common.slave')
return Em.I18n.t('common.slave');
} else if (this.get('content.isClient')) {
return Em.I18n.t('common.client')
return Em.I18n.t('common.client');
}
}.property('content'),

Expand Down Expand Up @@ -214,17 +214,13 @@ App.HostComponentView = Em.View.extend({
isDeleteComponentDisabled: function () {
var stackComponentCount = App.StackServiceComponent.find(this.get('content.componentName')).get('minToInstall');
var installedCount = App.HostComponent.getCount(this.get('content.componentName'), 'totalCount');
if(this.get('content.componentName') === 'MYSQL_SERVER' && this.get('content.serviceDisplayName') === 'Hive') {
var db_type=App.db.getConfigs().findProperty('type','hive-env').properties['hive_database'];
var status=[App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
if(db_type.indexOf('Existing') > -1 && status)
return false;
else
return true;
if (this.get('content.componentName') === 'MYSQL_SERVER' && this.get('content.serviceDisplayName') === 'Hive') {
var db_type = App.db.getConfigs().findProperty('type', 'hive-env').properties['hive_database'];
var status = [App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
return !(db_type.indexOf('Existing') > -1 && status);
}
if (this.get('content.componentName') === 'JOURNALNODE') {
var count_JN = App.HostComponent.find().filterProperty('componentName', 'JOURNALNODE').get('length');
return count_JN <= 3; // TODO get 3 from stack
return installedCount <= 3; // TODO get 3 from stack
}
return (installedCount <= stackComponentCount)
|| ![App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
Expand Down
107 changes: 106 additions & 1 deletion ambari-web/test/views/main/host/details/host_component_view_test.js
Expand Up @@ -434,13 +434,18 @@ describe('App.HostComponentView', function() {
});

it('should return list of commands', function() {
hostComponentView.set('content');
hostComponentView.propertyDidChange('clientCustomCommands');
expect(hostComponentView.get('clientCustomCommands')).to.be.eql([{
command: 'COMMAND1',
label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('COMMAND1')
}]);
});

it('should return empty list of commands', function() {
hostComponentView.set('content.componentName', 'KERBEROS_CLIENT');
hostComponentView.propertyDidChange('clientCustomCommands');
expect(hostComponentView.get('clientCustomCommands')).to.be.empty;
});
});

describe('#installClient', function() {
Expand All @@ -450,5 +455,105 @@ describe('App.HostComponentView', function() {
expect(hostComponentView.get('controller').installClients.calledOnce).to.be.true;
});
});

describe('#typeDisplay', function() {

it('should return label for master component', function() {
hostComponentView.set('content.isMaster', true);
hostComponentView.propertyDidChange('typeDisplay');
expect(hostComponentView.get('typeDisplay')).to.be.equal(Em.I18n.t('common.master'));
});

it('should return label for slave component', function() {
hostComponentView.set('content.isSlave', true);
hostComponentView.propertyDidChange('typeDisplay');
expect(hostComponentView.get('typeDisplay')).to.be.equal(Em.I18n.t('common.slave'));
});

it('should return label for client component', function() {
hostComponentView.set('content.isClient', true);
hostComponentView.propertyDidChange('typeDisplay');
expect(hostComponentView.get('typeDisplay')).to.be.equal(Em.I18n.t('common.client'));
});
});

describe('#maintenanceTooltip', function() {
beforeEach(function() {
hostComponentView.get('content').setProperties({
service: {
serviceName: 'S1'
},
displayName: 's1',
host: {
hostName: 'host1'
}
});
});

it('should return label for IMPLIED_FROM_SERVICE', function() {
hostComponentView.set('content.passiveState', 'IMPLIED_FROM_SERVICE');
hostComponentView.propertyDidChange('maintenanceTooltip');
expect(hostComponentView.get('maintenanceTooltip')).to.be.equal(
Em.I18n.t('passiveState.disabled.impliedFromHighLevel').format('s1', 'S1')
);
});

it('should return label for IMPLIED_FROM_HOST', function() {
hostComponentView.set('content.passiveState', 'IMPLIED_FROM_HOST');
hostComponentView.propertyDidChange('maintenanceTooltip');
expect(hostComponentView.get('maintenanceTooltip')).to.be.equal(
Em.I18n.t('passiveState.disabled.impliedFromHighLevel').format('s1', 'host1')
);
});

it('should return label for IMPLIED_FROM_SERVICE_AND_HOST', function() {
hostComponentView.set('content.passiveState', 'IMPLIED_FROM_SERVICE_AND_HOST');
hostComponentView.propertyDidChange('maintenanceTooltip');
expect(hostComponentView.get('maintenanceTooltip')).to.be.equal(
Em.I18n.t('passiveState.disabled.impliedFromServiceAndHost').format('s1', 'S1', 'host1')
);
});

it('should return label for unknown', function() {
hostComponentView.set('content.passiveState', '');
hostComponentView.propertyDidChange('maintenanceTooltip');
expect(hostComponentView.get('maintenanceTooltip')).to.be.empty;
});
});

describe('#meetsCustomCommandReq', function() {
var component = Em.Object.create({cardinality: "1"});
beforeEach(function() {
sinon.stub(hostComponentView, 'runningComponentCounter').returns(true);
this.mock = sinon.stub(App.HostComponent, 'getCount');
hostComponentView.set('excludedMasterCommands', ['command1']);
});
afterEach(function() {
hostComponentView.runningComponentCounter.restore();
this.mock.restore();
});

it('should return false when command excluded', function() {
expect(hostComponentView.meetsCustomCommandReq(component, 'command1')).to.be.false;
});

it('should return true when cardinality !== 1', function() {
expect(hostComponentView.meetsCustomCommandReq(component, 'command2')).to.be.true;
});

it('should return false when total count > 2 and running', function() {
component.set('cardinality', '0+');
hostComponentView.set('workStatus', App.HostComponentStatus.stopped);
this.mock.returns(2);
expect(hostComponentView.meetsCustomCommandReq(component, 'command2')).to.be.false;
});

it('should return false when total count = 1', function() {
component.set('cardinality', '0+');
hostComponentView.set('workStatus', App.HostComponentStatus.stopped);
this.mock.returns(1);
expect(hostComponentView.meetsCustomCommandReq(component, 'command2')).to.be.false;
});
});

});

0 comments on commit bab7cf5

Please sign in to comment.