|
@@ -19,7 +19,8 @@
|
|
|
|
|
|
var App = require('app');
|
|
|
|
|
|
-describe('App.InstallerController', function () {
|
|
|
+describe('App.MainController', function () {
|
|
|
+ var mainController = App.MainController.create();
|
|
|
|
|
|
describe('#getServerVersionSuccessCallback', function () {
|
|
|
|
|
@@ -53,7 +54,268 @@ describe('App.InstallerController', function () {
|
|
|
expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected);
|
|
|
});
|
|
|
});
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#isClusterDataLoaded', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns(true);
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should return true', function() {
|
|
|
+ expect(mainController.get('isClusterDataLoaded')).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#clusterDataLoadedPercent', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns(16);
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should return 16', function() {
|
|
|
+ expect(mainController.get('clusterDataLoadedPercent')).to.be.equal(16);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#initialize', function() {
|
|
|
+ var initialize = false;
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns({
|
|
|
+ loadClusterData: function() {
|
|
|
+ initialize = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should return true', function() {
|
|
|
+ mainController.initialize();
|
|
|
+ expect(initialize).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#dataLoading', function() {
|
|
|
+ it ('Should resolve promise', function() {
|
|
|
+ sinon.stub(App.router, 'get').returns(true);
|
|
|
+ var deffer = mainController.dataLoading();
|
|
|
+ App.router.get.restore();
|
|
|
+ deffer.then(function(val){
|
|
|
+ expect(val).to.be.undefined;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ it ('Should resolve promise', function() {
|
|
|
+ sinon.stub(App.router, 'get').returns(false);
|
|
|
+
|
|
|
+ setTimeout(function() {
|
|
|
+ mainController.set('isClusterDataLoaded', true);
|
|
|
+ },150);
|
|
|
+
|
|
|
+ var deffer = mainController.dataLoading();
|
|
|
+ App.router.get.restore();
|
|
|
+ deffer.then(function(val){
|
|
|
+ expect(val).to.be.undefined;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#checkServerClientVersion', function() {
|
|
|
+ var initialize = false;
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(mainController, 'getServerVersion').returns({
|
|
|
+ done: function(func) {
|
|
|
+ if (func) {
|
|
|
+ func();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ mainController.getServerVersion.restore();
|
|
|
+ });
|
|
|
+ it ('Should resolve promise', function() {
|
|
|
+ var deffer = mainController.checkServerClientVersion();
|
|
|
+ deffer.then(function(val){
|
|
|
+ expect(val).to.be.undefined;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#getServerVersion', function() {
|
|
|
+ var res;
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.ajax, 'send', function(data) {
|
|
|
+ res = JSON.parse(JSON.stringify(data));
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.ajax.send.restore();
|
|
|
+ });
|
|
|
+ it ('Should send data', function() {
|
|
|
+ mainController.getServerVersion();
|
|
|
+ expect(res).to.be.eql({
|
|
|
+ "name": "ambari.service",
|
|
|
+ "sender": {},
|
|
|
+ "data": {
|
|
|
+ "fields": "?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true"
|
|
|
+ },
|
|
|
+ "success": "getServerVersionSuccessCallback",
|
|
|
+ "error": "getServerVersionErrorCallback"
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#stopAllService', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns({
|
|
|
+ stopAllService: function(func) {
|
|
|
+ if (func) {
|
|
|
+ func();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should call event', function() {
|
|
|
+ var done = false;
|
|
|
+ var event = function() {
|
|
|
+ done = true;
|
|
|
+ };
|
|
|
+ mainController.stopAllService(event);
|
|
|
+ expect(done).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#startAllService', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns({
|
|
|
+ startAllService: function(func) {
|
|
|
+ if (func) {
|
|
|
+ func();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should call event', function() {
|
|
|
+ var done = false;
|
|
|
+ var event = function() {
|
|
|
+ done = true;
|
|
|
+ };
|
|
|
+ mainController.startAllService(event);
|
|
|
+ expect(done).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#isStopAllDisabled', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(mainController, 'scRequest').returns(true);
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ mainController.scRequest.restore();
|
|
|
+ });
|
|
|
+ it ('Should return true', function() {
|
|
|
+ expect(mainController.get('isStopAllDisabled')).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#gotoAddService', function() {
|
|
|
+ var done = false;
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns({
|
|
|
+ gotoAddService: function() {
|
|
|
+ done = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should call router', function() {
|
|
|
+ mainController.gotoAddService();
|
|
|
+ expect(done).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
+ describe('#isStartAllDisabled', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(mainController, 'scRequest').returns(true);
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ mainController.scRequest.restore();
|
|
|
+ });
|
|
|
+ it ('Should return true', function() {
|
|
|
+ expect(mainController.get('isStartAllDisabled')).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#isAllServicesInstalled', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(mainController, 'scRequest').returns(true);
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ mainController.scRequest.restore();
|
|
|
+ });
|
|
|
+ it ('Should return true', function() {
|
|
|
+ expect(mainController.get('isAllServicesInstalled')).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#scRequest', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get').returns({
|
|
|
+ get: function(request) {
|
|
|
+ if (request) {
|
|
|
+ request();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should return true', function() {
|
|
|
+ var done = false;
|
|
|
+ var event = function() {
|
|
|
+ done = true;
|
|
|
+ };
|
|
|
+ mainController.scRequest(event);
|
|
|
+ expect(done).to.be.true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('#updateTitle', function() {
|
|
|
+ beforeEach(function () {
|
|
|
+ sinon.stub(App.router, 'get', function(message){
|
|
|
+ if (message == 'clusterController.clusterName') {
|
|
|
+ return 'c1';
|
|
|
+ } else if (message == 'clusterInstallCompleted') {
|
|
|
+ return true;
|
|
|
+ } else if (message == 'clusterController') {
|
|
|
+ return {
|
|
|
+ get: function() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ afterEach(function () {
|
|
|
+ App.router.get.restore();
|
|
|
+ });
|
|
|
+ it ('Should update title', function() {
|
|
|
+ $('body').append('<title id="title-id">text</title>');
|
|
|
+ mainController.updateTitle();
|
|
|
+ expect($('title').text()).to.be.equal('Ambari - c1');
|
|
|
+ $('body').remove('#title-id');
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
});
|