Repository: ambari Updated Branches: refs/heads/branch-1.5.0 c5419fa84 -> 0d61aba20
http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/app/views/wizard/step8_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/wizard/step8_view.js b/ambari-web/app/views/wizard/step8_view.js index 1c1141b..d2ea4c5 100644 --- a/ambari-web/app/views/wizard/step8_view.js +++ b/ambari-web/app/views/wizard/step8_view.js @@ -24,8 +24,7 @@ App.WizardStep8View = Em.View.extend({ templateName: require('templates/wizard/step8'), didInsertElement: function () { - var controller = this.get('controller'); - controller.loadStep(); + this.get('controller').loadStep(); }, spinner : null, @@ -35,14 +34,6 @@ App.WizardStep8View = Em.View.extend({ o.jqprint(); }, - ajaxQueueLength: function() { - return this.get('controller.ajaxQueueLength'); - }.property('controller.ajaxQueueLength'), - - ajaxQueueLeft: function() { - return this.get('controller.ajaxQueueLeft'); - }.property('controller.ajaxQueueLeft'), - // reference to modalPopup to make sure only one instance is created modalPopup: null, @@ -59,32 +50,34 @@ App.WizardStep8View = Em.View.extend({ return; } this.set('modalPopup', App.ModalPopup.show({ - header: '', + header: '', showFooter: false, - showCloseButton: false, bodyClass: Ember.View.extend({ templateName: require('templates/wizard/step8_log_popup'), - message: function() { - return Em.I18n.t('installer.step8.deployPopup.message').format(this.get('ajaxQueueComplete'), this.get('ajaxQueueLength')); - }.property('ajaxQueueComplete', 'ajaxQueueLength'), - controllerBinding: 'App.router.wizardStep8Controller', - ajaxQueueLength: function() { - return this.get('controller.ajaxQueueLength'); - }.property(), - - ajaxQueueComplete: function() { - return this.get('ajaxQueueLength') - this.get('controller.ajaxQueueLeft'); - }.property('controller.ajaxQueueLeft', 'ajaxQueueLength'), - - barWidth: function () { - return 'width: ' + (this.get('ajaxQueueComplete') / this.get('ajaxQueueLength') * 100) + '%;'; - }.property('ajaxQueueComplete', 'ajaxQueueLength'), + /** + * Css-property for progress-bar + * @type {string} + */ + barWidth: '', + + /** + * Popup-message + * @type {string} + */ + message: '', + + ajaxQueueChangeObs: function() { + var length = this.get('controller.ajaxQueueLength'); + var left = this.get('controller.ajaxRequestsQueue.queue.length'); + this.set('barWidth', 'width: ' + ((length - left) / length * 100) + '%;'); + this.set('message', Em.I18n.t('installer.step8.deployPopup.message').format((length - left), length)); + }.observes('controller.ajaxQueueLength', 'controller.ajaxRequestsQueue.queue.length'), autoHide: function() { if (this.get('controller.servicesInstalled')) { @@ -92,6 +85,7 @@ App.WizardStep8View = Em.View.extend({ } }.observes('controller.servicesInstalled') }) + })); }.observes('controller.isSubmitDisabled') }); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/test/controllers/global/background_operations_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/global/background_operations_test.js b/ambari-web/test/controllers/global/background_operations_test.js index 710147a..02df0cf 100644 --- a/ambari-web/test/controllers/global/background_operations_test.js +++ b/ambari-web/test/controllers/global/background_operations_test.js @@ -21,7 +21,7 @@ var App = require('app'); require('config'); require('utils/updater'); -require('utils/ajax'); +require('utils/ajax/ajax'); require('models/host_component'); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/test/installer/step8_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/installer/step8_test.js b/ambari-web/test/installer/step8_test.js index 7a79930..9d7978d 100644 --- a/ambari-web/test/installer/step8_test.js +++ b/ambari-web/test/installer/step8_test.js @@ -17,6 +17,7 @@ */ var App = require('app'); +require('utils/ajax/ajax_queue'); require('controllers/wizard/step8_controller'); var installerStep8Controller; http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/test/installer/step9_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/installer/step9_test.js b/ambari-web/test/installer/step9_test.js index 4ecd864..45fb4b9 100644 --- a/ambari-web/test/installer/step9_test.js +++ b/ambari-web/test/installer/step9_test.js @@ -717,18 +717,6 @@ describe('App.InstallerStep9Controller', function () { }); }); - describe('#getUrl', function () { - var clusterName = 'tdk'; - var cluster = App.WizardStep9Controller.create({content: {cluster: {name: clusterName, requestId: null}}}); - it('check requestId priority', function () { - cluster.set('content.cluster.requestId', 123); - var url = cluster.getUrl(321); - expect(url).to.equal(App.apiPrefix + '/clusters/' + clusterName + '/requests/' + '321' + '?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true'); - url = cluster.getUrl(); - expect(url).to.equal(App.apiPrefix + '/clusters/' + clusterName + '/requests/' + '123' + '?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true'); - }); - }); - describe('#finishState', function () { var statuses = Em.A(['INSTALL FAILED', 'START FAILED', 'STARTED']); it('Installer is finished', function () { @@ -1173,7 +1161,7 @@ describe('App.InstallerStep9Controller', function () { var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING',name: 'c1'}},togglePreviousSteps: function(){}}); //Action - controller.launchStartServicesErrorCallback({status:500, statusTesxt: 'Server Error'}); + controller.launchStartServicesErrorCallback({status:500, statusTesxt: 'Server Error'}, {}, '', {}); it('Cluster Status should be INSTALL FAILED', function () { expect(controller.get('content.cluster.status')).to.equal('INSTALL FAILED'); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/test/utils/ajax/ajax_queue_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/ajax/ajax_queue_test.js b/ambari-web/test/utils/ajax/ajax_queue_test.js new file mode 100644 index 0000000..3c7ac85 --- /dev/null +++ b/ambari-web/test/utils/ajax/ajax_queue_test.js @@ -0,0 +1,111 @@ +/** + * 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'); + +var ajaxQueue; + +describe('App.ajaxQueue', function () { + + beforeEach(function() { + ajaxQueue = App.ajaxQueue.create(); + sinon.spy(ajaxQueue, 'runNextRequest'); + sinon.spy(ajaxQueue, 'finishedCallback'); + sinon.spy(App.ajax, 'send'); + }); + + afterEach(function() { + ajaxQueue.clear(); + ajaxQueue.runNextRequest.restore(); + ajaxQueue.finishedCallback.restore(); + App.ajax.send.restore(); + }); + + describe('#clear', function() { + it('should clear queue', function() { + ajaxQueue.addRequest({name:'some', sender: Em.Object.create()}); + ajaxQueue.clear(); + expect(ajaxQueue.get('queue.length')).to.equal(0); + }); + }); + + describe('#addRequest', function() { + it('should add request', function() { + ajaxQueue.addRequest({name:'some', sender: Em.Object.create()}); + expect(ajaxQueue.get('queue.length')).to.equal(1); + }); + it('should throw `name` error', function() { + expect(function() {ajaxQueue.addRequest({name:'', sender: Em.Object.create()})}).to.throw(Error); + }); + it('should throw `sender` error', function() { + expect(function() {ajaxQueue.addRequest({name:'some', sender: {}})}).to.throw(Error); + }); + }); + + describe('#addRequests', function() { + it('should add requests', function() { + ajaxQueue.addRequests(Em.A([ + {name:'some', sender: Em.Object.create()}, + {name:'some2', sender: Em.Object.create()} + ])); + expect(ajaxQueue.get('queue.length')).to.equal(2); + }); + + it('should throw `name` error', function() { + expect(function() {ajaxQueue.addRequests(Em.A([ + {name:'some', sender: Em.Object.create()}, + {name:'', sender: Em.Object.create()} + ]));}).to.throw(Error); + }); + + it('should throw `sender` error', function() { + expect(function() {ajaxQueue.addRequests(Em.A([ + {name:'some', sender: Em.Object.create()}, + {name:'some2', sender: {}} + ]));}).to.throw(Error); + }); + + }); + + describe('#start', function() { + it('should call runNextRequest', function() { + ajaxQueue.start(); + expect(ajaxQueue.runNextRequest.called).to.equal(true); + }); + }); + + describe('#runNextRequest', function() { + it('for empty queue App.ajax.send shouldn\'t be called', function() { + ajaxQueue.clear(); + ajaxQueue.runNextRequest(); + expect(App.ajax.send.called).to.equal(false); + }); + it('when queue is empty finishedCallback should be called', function() { + ajaxQueue.clear(); + ajaxQueue.runNextRequest(); + expect(ajaxQueue.finishedCallback.called).to.equal(true); + }); + it('if abortOnError is false queue shouldn\'t be interrupted', function() { + ajaxQueue.clear(); + ajaxQueue.set('abortOnError', false); + ajaxQueue.addRequest({name:'some_fake', sender: Em.Object.create()}).addRequest({name: 'some_fake2', sender: Em.Object.create()}).start(); + expect(ajaxQueue.runNextRequest.callCount).to.equal(3); // One for empty-queue + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/test/utils/ajax/ajax_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/ajax/ajax_test.js b/ambari-web/test/utils/ajax/ajax_test.js new file mode 100644 index 0000000..d029df8 --- /dev/null +++ b/ambari-web/test/utils/ajax/ajax_test.js @@ -0,0 +1,148 @@ +/** + * 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('utils/ajax/ajax'); + +describe('App.ajax', function() { + + beforeEach(function() { + App.set('apiPrefix', '/api/v1'); + App.set('clusterName', 'tdk'); + sinon.spy($, 'ajax'); + }); + + afterEach(function() { + $.ajax.restore(); + }); + + describe('#send', function() { + + it('Without sender', function() { + expect(App.ajax.send({})).to.equal(null); + expect($.ajax.called).to.be.false; + }); + + it('Invalid config.name', function() { + expect(App.ajax.send({name:'fake_name', sender: this})).to.equal(null); + expect($.ajax.called).to.be.false; + }); + + it('With proper data', function() { + App.ajax.send({name: 'router.logoff', sender: this}); + expect($.ajax.calledOnce).to.be.true; + }); + + }); + + describe('#formatUrl', function() { + + var tests = [ + { + url: null, + data: {}, + e: null, + m: 'url is null' + }, + { + url: 'site/{param}', + data: null, + e: 'site/', + m: 'url with one param, but data is null' + }, + { + url: 'clean_url', + data: {}, + e: 'clean_url', + m: 'url without placeholders' + }, + { + url: 'site/{param}', + data: {}, + e: 'site/', + m: 'url with param, but there is no such param in the data' + }, + { + url: 'site/{param}/{param}', + data: {param: 123}, + e: 'site/123/123', + m: 'url with param which appears two times' + } + ]; + + tests.forEach(function(test) { + it(test.m, function() { + var r = App.ajax.fakeFormatUrl(test.url, test.data); + expect(r).to.equal(test.e); + }); + }); + }); + + describe('Check "real" and "mock" properties for each url object', function() { + var names = App.ajax.fakeGetUrlNames(); + names.forEach(function(name) { + it(name, function() { + var url = App.ajax.fakeGetUrl(name); + expect(url.real).to.be.a('string'); + expect(url.real.length > 0).to.equal(true); + expect(url.mock).to.be.a('string'); + }); + }); + }); + + describe('#formatRequest', function() { + + beforeEach(function() { + App.testMode = false; + }); + afterEach(function() { + App.testMode = true; + }); + + it('App.testMode = true', function() { + App.testMode = true; + var r = App.ajax.fakeFormatRequest({real:'/', mock: '/some_url'}, {}); + expect(r.type).to.equal('GET'); + expect(r.url).to.equal('/some_url'); + expect(r.dataType).to.equal('json'); + }); + var tests = [ + { + urlObj: { + real: '/real_url', + format: function() { + return { + type: 'PUT' + } + } + }, + data: {}, + m: '', + e: {type: 'PUT', url: '/api/v1/real_url'} + } + ]; + tests.forEach(function(test) { + it(test.m, function() { + var r = App.ajax.fakeFormatRequest(test.urlObj, test.data); + expect(r.type).to.equal(test.e.type); + expect(r.url).to.equal(test.e.url); + }); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/0d61aba2/ambari-web/test/utils/ajax_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/ajax_test.js b/ambari-web/test/utils/ajax_test.js deleted file mode 100644 index 6bd8e02..0000000 --- a/ambari-web/test/utils/ajax_test.js +++ /dev/null @@ -1,148 +0,0 @@ -/** - * 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('utils/ajax'); - -describe('App.ajax', function() { - - beforeEach(function() { - App.set('apiPrefix', '/api/v1'); - App.set('clusterName', 'tdk'); - sinon.spy($, 'ajax'); - }); - - afterEach(function() { - $.ajax.restore(); - }); - - describe('#send', function() { - - it('Without sender', function() { - expect(App.ajax.send({})).to.equal(null); - expect($.ajax.called).to.be.false; - }); - - it('Invalid config.name', function() { - expect(App.ajax.send({name:'fake_name', sender: this})).to.equal(null); - expect($.ajax.called).to.be.false; - }); - - it('With proper data', function() { - App.ajax.send({name: 'router.logoff', sender: this}); - expect($.ajax.calledOnce).to.be.true; - }); - - }); - - describe('#formatUrl', function() { - - var tests = [ - { - url: null, - data: {}, - e: null, - m: 'url is null' - }, - { - url: 'site/{param}', - data: null, - e: 'site/', - m: 'url with one param, but data is null' - }, - { - url: 'clean_url', - data: {}, - e: 'clean_url', - m: 'url without placeholders' - }, - { - url: 'site/{param}', - data: {}, - e: 'site/', - m: 'url with param, but there is no such param in the data' - }, - { - url: 'site/{param}/{param}', - data: {param: 123}, - e: 'site/123/123', - m: 'url with param which appears two times' - } - ]; - - tests.forEach(function(test) { - it(test.m, function() { - var r = App.ajax.fakeFormatUrl(test.url, test.data); - expect(r).to.equal(test.e); - }); - }); - }); - - describe('Check "real" and "mock" properties for each url object', function() { - var names = App.ajax.fakeGetUrlNames(); - names.forEach(function(name) { - it(name, function() { - var url = App.ajax.fakeGetUrl(name); - expect(url.real).to.be.a('string'); - expect(url.real.length > 0).to.equal(true); - expect(url.mock).to.be.a('string'); - }); - }); - }); - - describe('#formatRequest', function() { - - beforeEach(function() { - App.testMode = false; - }); - afterEach(function() { - App.testMode = true; - }); - - it('App.testMode = true', function() { - App.testMode = true; - var r = App.ajax.fakeFormatRequest({real:'/', mock: '/some_url'}, {}); - expect(r.type).to.equal('GET'); - expect(r.url).to.equal('/some_url'); - expect(r.dataType).to.equal('json'); - }); - var tests = [ - { - urlObj: { - real: '/real_url', - format: function() { - return { - type: 'PUT' - } - } - }, - data: {}, - m: '', - e: {type: 'PUT', url: '/api/v1/real_url'} - } - ]; - tests.forEach(function(test) { - it(test.m, function() { - var r = App.ajax.fakeFormatRequest(test.urlObj, test.data); - expect(r.type).to.equal(test.e.type); - expect(r.url).to.equal(test.e.url); - }); - }); - }); - -});
