|
@@ -18,8 +18,9 @@
|
|
|
|
|
|
var Ember = require('ember');
|
|
|
var App = require('app');
|
|
|
-require('controllers/wizard/step4_controller');
|
|
|
+var modelSetup = require('test/init_model_test');
|
|
|
|
|
|
+require('controllers/wizard/step4_controller');
|
|
|
describe('App.WizardStep4Controller', function () {
|
|
|
|
|
|
var services = [
|
|
@@ -28,6 +29,34 @@ describe('App.WizardStep4Controller', function () {
|
|
|
];
|
|
|
|
|
|
var controller = App.WizardStep4Controller.create();
|
|
|
+
|
|
|
+ var generateSelectedServicesContent = function(selectedServiceNames) {
|
|
|
+ var allServices = services.slice(0);
|
|
|
+ if (selectedServiceNames.contains('GLUSTERFS')) allServices.push('GLUSTERFS');
|
|
|
+ allServices = allServices.map(function(serviceName) {
|
|
|
+ return [Ember.Object.create({
|
|
|
+ 'serviceName': serviceName,
|
|
|
+ 'isSelected': false,
|
|
|
+ 'canBeSelected': true,
|
|
|
+ 'isInstalled': false,
|
|
|
+ isPrimaryDFS: serviceName == 'HDFS',
|
|
|
+ isDFS: ['HDFS','GLUSTERFS'].contains(serviceName),
|
|
|
+ isMonitoringService: ['NAGIOS','GANGLIA'].contains(serviceName),
|
|
|
+ dependentServices: App.StackService.dependency['HDP-2'][serviceName],
|
|
|
+ displayNameOnSelectServicePage: App.format.role(serviceName),
|
|
|
+ coSelectedServices: function() {
|
|
|
+ return App.StackService.coSelected[this.get('serviceName')] || [];
|
|
|
+ }.property('serviceName')
|
|
|
+ })];
|
|
|
+ }).reduce(function(current, prev) { return current.concat(prev); });
|
|
|
+
|
|
|
+ selectedServiceNames.forEach(function(serviceName) {
|
|
|
+ allServices.findProperty('serviceName', serviceName).set('isSelected', true);
|
|
|
+ });
|
|
|
+
|
|
|
+ return allServices;
|
|
|
+ };
|
|
|
+
|
|
|
services.forEach(function(serviceName, index){
|
|
|
controller.pushObject(Ember.Object.create({
|
|
|
'serviceName':serviceName, 'isSelected': true, 'isHiddenOnSelectServicePage': false, 'isInstalled': false, 'isDisabled': 'HDFS' === serviceName, isDFS: 'HDFS' === serviceName
|
|
@@ -211,19 +240,181 @@ describe('App.WizardStep4Controller', function () {
|
|
|
}, this);
|
|
|
});
|
|
|
|
|
|
- describe('#monitoringCheckPopup', function() {
|
|
|
- it('should show App.ModalPopup', function() {
|
|
|
- sinon.spy(App.ModalPopup, 'show');
|
|
|
- controller.monitoringCheckPopup();
|
|
|
- expect(App.ModalPopup.show.calledOnce).to.equal(true);
|
|
|
- App.ModalPopup.show.restore();
|
|
|
+ describe('#addValidationError()', function() {
|
|
|
+ var tests = [
|
|
|
+ {
|
|
|
+ errorObjects: [
|
|
|
+ {
|
|
|
+ id: 'serviceCheck_ZOOKEEPER',
|
|
|
+ shouldBeAdded: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'serviceCheck_YARN',
|
|
|
+ shouldBeAdded: true
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ expectedIds: ['serviceCheck_ZOOKEEPER', 'serviceCheck_YARN']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ errorObjects: [
|
|
|
+ {
|
|
|
+ id: 'fsCheck',
|
|
|
+ shouldBeAdded: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'fsCheck',
|
|
|
+ shouldBeAdded: false
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ expectedIds: ['fsCheck']
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ beforeEach(function() {
|
|
|
+ controller.clear();
|
|
|
+ controller.set('errorStack', []);
|
|
|
});
|
|
|
- it('onPrimary should proceed to next step', function() {
|
|
|
+
|
|
|
+ tests.forEach(function(test) {
|
|
|
+ var message = 'Erorrs {0} thrown. errorStack property should contains ids: {1}'
|
|
|
+ .format(test.errorObjects.mapProperty('id').join(', '), test.expectedIds.join(', '));
|
|
|
+ it(message, function() {
|
|
|
+ test.errorObjects.forEach(function(errorObject) {
|
|
|
+ expect(controller.addValidationError(errorObject)).to.equal(errorObject.shouldBeAdded);
|
|
|
+ });
|
|
|
+ expect(controller.get('errorStack').mapProperty('id')).to.eql(test.expectedIds);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#validate()', function() {
|
|
|
+ var tests = [
|
|
|
+ {
|
|
|
+ services: ['HDFS','ZOOKEEPER'],
|
|
|
+ errorsExpected: ['monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['ZOOKEEPER'],
|
|
|
+ errorsExpected: ['fsCheck', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS'],
|
|
|
+ errorsExpected: ['serviceCheck_ZOOKEEPER', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS', 'TEZ', 'ZOOKEEPER'],
|
|
|
+ errorsExpected: ['serviceCheck_YARN', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS', 'ZOOKEEPER', 'FALCON', 'NAGIOS'],
|
|
|
+ errorsExpected: ['serviceCheck_OOZIE', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'NAGIOS', 'HIVE'],
|
|
|
+ errorsExpected: ['serviceCheck_YARN']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
|
|
|
+ errorsExpected: ['serviceCheck_YARN', 'multipleDFS', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
|
|
|
+ errorsExpected: []
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ tests.forEach(function(test) {
|
|
|
+ var message = '{0} selected validation should be {1}, errors with ids: {2} present'
|
|
|
+ .format(test.services.join(','), !!test.validationPassed ? 'passed' : 'failed', test.errorsExpected.join(','));
|
|
|
+ it(message, function() {
|
|
|
+ controller.clear();
|
|
|
+ controller.set('content', generateSelectedServicesContent(test.services));
|
|
|
+ controller.validate();
|
|
|
+ expect(controller.get('errorStack').mapProperty('id')).to.be.eql(test.errorsExpected);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#onPrimaryPopupCallback()', function() {
|
|
|
+ var c;
|
|
|
+ var tests = [
|
|
|
+ {
|
|
|
+ services: ['HDFS','ZOOKEEPER'],
|
|
|
+ confirmPopupCount: 1,
|
|
|
+ errorsExpected: ['monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['ZOOKEEPER'],
|
|
|
+ confirmPopupCount: 2,
|
|
|
+ errorsExpected: ['fsCheck', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
|
|
|
+ confirmPopupCount: 3,
|
|
|
+ errorsExpected: ['serviceCheck_YARN', 'serviceCheck_TEZ', 'multipleDFS', 'monitoringCheck']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ services: ['HDFS','ZOOKEEPER', 'NAGIOS', 'GANGLIA'],
|
|
|
+ confirmPopupCount: 0,
|
|
|
+ errorsExpected: []
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
+ beforeEach(function() {
|
|
|
+ c = App.WizardStep4Controller.create({});
|
|
|
sinon.stub(App.router, 'send', Em.K);
|
|
|
- controller.monitoringCheckPopup().onPrimary();
|
|
|
- expect(App.router.send.calledWith('next')).to.equal(true);
|
|
|
+ sinon.stub(c, 'submit', Em.K);
|
|
|
+ sinon.spy(c, 'onPrimaryPopupCallback');
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
App.router.send.restore();
|
|
|
+ c.submit.restore();
|
|
|
+ c.onPrimaryPopupCallback.restore();
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+ tests.forEach(function(test) {
|
|
|
+ var message = 'Selected services: {0}. {1} errors should be confirmed'
|
|
|
+ .format(test.services.join(', '), test.confirmPopupCount);
|
|
|
+
|
|
|
+ it(message, function() {
|
|
|
+ var runValidations = function() {
|
|
|
+ c.serviceDependencyValidation();
|
|
|
+ c.fileSystemServiceValidation();
|
|
|
+ c.serviceMonitoringValidation();
|
|
|
+ }
|
|
|
+
|
|
|
+ c.set('content', generateSelectedServicesContent(test.services));
|
|
|
+ runValidations();
|
|
|
+ // errors count validation
|
|
|
+ expect(c.get('errorStack.length')).to.equal(test.confirmPopupCount);
|
|
|
+ // if errors detected than it should be shown
|
|
|
+ if (test.errorsExpected) {
|
|
|
+ test.errorsExpected.forEach(function(error, index, errors) {
|
|
|
+ // validate current error
|
|
|
+ var currentErrorObject = c.get('errorStack').findProperty('isShown', false);
|
|
|
+ if (currentErrorObject) {
|
|
|
+ expect(error).to.be.equal(currentErrorObject.id);
|
|
|
+ // show current error
|
|
|
+ var popup = c.showError(currentErrorObject);
|
|
|
+ // submit popup
|
|
|
+ popup.onPrimary();
|
|
|
+ // onPrimaryPopupCallback should be called
|
|
|
+ expect(c.onPrimaryPopupCallback.called).to.equal(true);
|
|
|
+ // submit called
|
|
|
+ expect(c.submit.called).to.equal(true);
|
|
|
+ if (c.get('errorStack').length) {
|
|
|
+ // current error isShown flag changed to true
|
|
|
+ expect(currentErrorObject.isShown).to.equal(true);
|
|
|
+ }
|
|
|
+ runValidations();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
});
|
|
|
|
|
|
describe('#needToAddServicePopup', function() {
|
|
@@ -253,65 +444,55 @@ describe('App.WizardStep4Controller', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('#submit', function() {
|
|
|
+ describe('#submit', function() {
|
|
|
+ var c;
|
|
|
+ var tests = [
|
|
|
+ {
|
|
|
+ isSubmitDisabled: true,
|
|
|
+ validate: false,
|
|
|
+ userCanProceed: false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ isSubmitDisabled: false,
|
|
|
+ validate: false,
|
|
|
+ userCanProceed: false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ isSubmitDisabled: false,
|
|
|
+ validate: true,
|
|
|
+ userCanProceed: true
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
beforeEach(function() {
|
|
|
- sinon.stub(controller, 'validateMonitoring', Em.K);
|
|
|
- sinon.stub(controller, 'setGroupedServices', Em.K);
|
|
|
+ c = App.WizardStep4Controller.create();
|
|
|
+ sinon.stub(App.router, 'send', Em.K);
|
|
|
});
|
|
|
+
|
|
|
afterEach(function() {
|
|
|
- controller.validateMonitoring.restore();
|
|
|
- controller.setGroupedServices.restore();
|
|
|
- });
|
|
|
- it('if not isSubmitDisabled shound\'t do nothing', function() {
|
|
|
- controller.reopen({isSubmitDisabled: true});
|
|
|
- controller.submit();
|
|
|
- expect(controller.validateMonitoring.called).to.equal(false);
|
|
|
- });
|
|
|
- it('if isSubmitDisabled and not submitChecks should call validateMonitoring', function() {
|
|
|
- sinon.stub(controller, 'isSubmitChecksFailed', function() { return false; });
|
|
|
- controller.reopen({
|
|
|
- isSubmitDisabled: false,
|
|
|
- submitChecks: []
|
|
|
- });
|
|
|
- controller.submit();
|
|
|
- expect(controller.validateMonitoring.calledOnce).to.equal(true);
|
|
|
- controller.isSubmitChecksFailed.restore();
|
|
|
- });
|
|
|
- it('if isSubmitDisabled and some submitChecks true shouldn\'t call validateMonitoring', function() {
|
|
|
- controller.reopen({
|
|
|
- isSubmitDisabled: false,
|
|
|
- submitChecks: [
|
|
|
- {
|
|
|
- popupParams: [
|
|
|
- {serviceName: 'MAPREDUCE', selected: true},
|
|
|
- 'mapreduceCheck'
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
- });
|
|
|
- sinon.stub(controller, 'isSubmitChecksFailed', function() { return true; });
|
|
|
- controller.submit();
|
|
|
- controller.isSubmitChecksFailed.restore();
|
|
|
- expect(controller.validateMonitoring.called).to.equal(false);
|
|
|
+ App.router.send.restore();
|
|
|
});
|
|
|
- it('if isSubmitDisabled and some submitChecks false should call validateMonitoring', function() {
|
|
|
- controller.reopen({
|
|
|
- isSubmitDisabled: false,
|
|
|
- submitChecks: [
|
|
|
- {
|
|
|
- checkCallback: 'needToAddMapReduce',
|
|
|
- popupParams: [
|
|
|
- {serviceName: 'MAPREDUCE', selected: true},
|
|
|
- 'mapreduceCheck'
|
|
|
- ]
|
|
|
- }
|
|
|
- ]
|
|
|
+
|
|
|
+ tests.forEach(function(test) {
|
|
|
+ var messageFormat = [
|
|
|
+ test.isSubmitDisabled ? 'disabled' : 'enabled',
|
|
|
+ test.validate ? 'success' : 'failed',
|
|
|
+ test.userCanProceed ? '' : 'not'
|
|
|
+ ];
|
|
|
+ var message = String.prototype.format.apply('Submit btn: {0}. Validation: {1}. Can{2} move to the next step.', messageFormat);
|
|
|
+
|
|
|
+ it(message, function() {
|
|
|
+ c.reopen({
|
|
|
+ isSubmitDisabled: test.isSubmitDisabled,
|
|
|
+ validate: function() { return test.validate; }
|
|
|
+ });
|
|
|
+ c.clear();
|
|
|
+ c.submit();
|
|
|
+
|
|
|
+ expect(App.router.send.calledOnce).to.equal(test.userCanProceed);
|
|
|
});
|
|
|
- sinon.stub(controller, 'isSubmitChecksFailed', function() { return false; });
|
|
|
- controller.submit();
|
|
|
- controller.isSubmitChecksFailed.restore();
|
|
|
- expect(controller.validateMonitoring.calledOnce).to.equal(true);
|
|
|
- });
|
|
|
+
|
|
|
+ })
|
|
|
});
|
|
|
|
|
|
-});
|
|
|
+});
|