Loading public/app.js +6 −7 Original line number Diff line number Diff line Loading @@ -792,11 +792,11 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', ' }]); angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', function ($scope, $http, $sce, DataService, AlertService, ModalService, AceEditorService) { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); $scope.editor = undefined; $scope.response = undefined; $scope.mappings = undefined; Loading @@ -820,6 +820,8 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce }; $scope.initializeController = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); DataService.getClusterMapping( function(response) { $scope.mappings = response; Loading @@ -833,12 +835,9 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce $scope.updateOptions = function(text) { if ($scope.mappings) { var autocomplete = new URLAutocomplete($scope.mappings); $scope.options = autocomplete.getAlternatives(text); console.log($scope.options); $scope.options = new URLAutocomplete($scope.mappings).getAlternatives(text); } }; }]); angular.module('cerebro').directive('ngPagination', ['$document', function($document) { Loading src/controllers/rest.js +6 −7 Original line number Diff line number Diff line angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', function ($scope, $http, $sce, DataService, AlertService, ModalService, AceEditorService) { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); $scope.editor = undefined; $scope.response = undefined; $scope.mappings = undefined; Loading @@ -26,6 +26,8 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce }; $scope.initializeController = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); DataService.getClusterMapping( function(response) { $scope.mappings = response; Loading @@ -39,10 +41,7 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce $scope.updateOptions = function(text) { if ($scope.mappings) { var autocomplete = new URLAutocomplete($scope.mappings); $scope.options = autocomplete.getAlternatives(text); console.log($scope.options); $scope.options = new URLAutocomplete($scope.mappings).getAlternatives(text); } }; }]); tests/controllers/rest.tests.js 0 → 100644 +105 −0 Original line number Diff line number Diff line describe('RestController', function() { beforeEach(angular.mock.module('cerebro')); beforeEach(angular.mock.inject(function($rootScope, $controller, $injector) { this.scope = $rootScope.$new(); this.$http = $injector.get('$http'); this.$sce = $injector.get('$sce'); this.DataService = $injector.get('DataService'); this.AlertService = $injector.get('AlertService'); this.ModalService = $injector.get('ModalService'); this.AceEditorService = $injector.get('AceEditorService'); this.createController = function() { return $controller('RestController', {$scope: this.scope}, this.$http, this.$window, this.DataService, this.AlertService, this.ModalService, this.AceEditorService); }; this._controller = this.createController(); })); it('should have intial state correctly set', function () { expect(this.scope.response).toEqual(undefined); expect(this.scope.mappings).toEqual(undefined); expect(this.scope.method).toEqual("POST"); expect(this.scope.path).toEqual(""); expect(this.scope.options).toEqual([]); }); describe('initializeController', function() { it('initializes Ace editor', function () { var fakeEditor = {setValue: function() {}}; spyOn(this.AceEditorService, "init").andReturn(fakeEditor); this.scope.initializeController(); expect(this.AceEditorService.init).toHaveBeenCalledWith('rest-client-editor'); expect(this.scope.editor).toEqual(fakeEditor); }); it('loads mappings', function () { var fakeEditor = {setValue: function() {}}; spyOn(this.AceEditorService, "init").andReturn(fakeEditor); this.DataService.getClusterMapping = function(success, error) { success({"mappings":"mappingsValue"}); }; spyOn(this.DataService, "getClusterMapping").andCallThrough(); spyOn(this.scope, "updateOptions").andReturn(); this.scope.initializeController(); expect(this.DataService.getClusterMapping).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function)); expect(this.scope.mappings).toEqual({"mappings":"mappingsValue"}); expect(this.scope.updateOptions).toHaveBeenCalled(); }); it('alerts when loading mappings fail', function () { var fakeEditor = {setValue: function() {}}; spyOn(this.AceEditorService, "init").andReturn(fakeEditor); this.DataService.getClusterMapping = function(success, error) { error("some reason"); }; spyOn(this.DataService, "getClusterMapping").andCallThrough(); spyOn(this.AlertService, "error").andReturn(); spyOn(this.scope, "updateOptions").andReturn(); this.scope.initializeController(); expect(this.scope.updateOptions).not.toHaveBeenCalled(); expect(this.AlertService.error).toHaveBeenCalledWith('Error while loading cluster mappings', 'some reason'); }); }); describe('execute', function() { it('cleans response when executing a request', function () { this.scope.response = "{}"; expect(this.scope.response).toEqual("{}"); this.scope.editor = { getValue: function () { return ""; } }; spyOn(this.DataService, "getClusterMapping").andReturn(); this.scope.execute(); expect(this.scope.response).toEqual(undefined); }); it('uses path, method and body from ace editor', function () { this.scope.editor = { getValue: function () { return "some value"; } }; spyOn(this.DataService, "execute").andReturn(); this.scope.execute(); expect(this.DataService.execute).toHaveBeenCalledWith("POST", "", "some value", jasmine.any(Function), jasmine.any(Function)); }); }); describe('updateOptions', function() { it('loads all possible autocompletion options', function () { this.scope.mappings = {}; this.scope.updateOptions(""); expect(this.scope.options).toEqual(['_msearch', '_search', '_suggest']); }); it('skip autocompletion if mappings is absent', function () { this.scope.mappings = undefined; this.scope.updateOptions(""); expect(this.scope.options).toEqual([]); }); }); }); Loading
public/app.js +6 −7 Original line number Diff line number Diff line Loading @@ -792,11 +792,11 @@ angular.module('cerebro').controller('OverviewController', ['$scope', '$http', ' }]); angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', function ($scope, $http, $sce, DataService, AlertService, ModalService, AceEditorService) { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); $scope.editor = undefined; $scope.response = undefined; $scope.mappings = undefined; Loading @@ -820,6 +820,8 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce }; $scope.initializeController = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); DataService.getClusterMapping( function(response) { $scope.mappings = response; Loading @@ -833,12 +835,9 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce $scope.updateOptions = function(text) { if ($scope.mappings) { var autocomplete = new URLAutocomplete($scope.mappings); $scope.options = autocomplete.getAlternatives(text); console.log($scope.options); $scope.options = new URLAutocomplete($scope.mappings).getAlternatives(text); } }; }]); angular.module('cerebro').directive('ngPagination', ['$document', function($document) { Loading
src/controllers/rest.js +6 −7 Original line number Diff line number Diff line angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce', 'DataService', 'AlertService', 'ModalService', 'AceEditorService', function ($scope, $http, $sce, DataService, AlertService, ModalService, AceEditorService) { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); $scope.editor = undefined; $scope.response = undefined; $scope.mappings = undefined; Loading @@ -26,6 +26,8 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce }; $scope.initializeController = function() { $scope.editor = AceEditorService.init('rest-client-editor'); $scope.editor.setValue("{}"); DataService.getClusterMapping( function(response) { $scope.mappings = response; Loading @@ -39,10 +41,7 @@ angular.module('cerebro').controller('RestController', ['$scope', '$http', '$sce $scope.updateOptions = function(text) { if ($scope.mappings) { var autocomplete = new URLAutocomplete($scope.mappings); $scope.options = autocomplete.getAlternatives(text); console.log($scope.options); $scope.options = new URLAutocomplete($scope.mappings).getAlternatives(text); } }; }]);
tests/controllers/rest.tests.js 0 → 100644 +105 −0 Original line number Diff line number Diff line describe('RestController', function() { beforeEach(angular.mock.module('cerebro')); beforeEach(angular.mock.inject(function($rootScope, $controller, $injector) { this.scope = $rootScope.$new(); this.$http = $injector.get('$http'); this.$sce = $injector.get('$sce'); this.DataService = $injector.get('DataService'); this.AlertService = $injector.get('AlertService'); this.ModalService = $injector.get('ModalService'); this.AceEditorService = $injector.get('AceEditorService'); this.createController = function() { return $controller('RestController', {$scope: this.scope}, this.$http, this.$window, this.DataService, this.AlertService, this.ModalService, this.AceEditorService); }; this._controller = this.createController(); })); it('should have intial state correctly set', function () { expect(this.scope.response).toEqual(undefined); expect(this.scope.mappings).toEqual(undefined); expect(this.scope.method).toEqual("POST"); expect(this.scope.path).toEqual(""); expect(this.scope.options).toEqual([]); }); describe('initializeController', function() { it('initializes Ace editor', function () { var fakeEditor = {setValue: function() {}}; spyOn(this.AceEditorService, "init").andReturn(fakeEditor); this.scope.initializeController(); expect(this.AceEditorService.init).toHaveBeenCalledWith('rest-client-editor'); expect(this.scope.editor).toEqual(fakeEditor); }); it('loads mappings', function () { var fakeEditor = {setValue: function() {}}; spyOn(this.AceEditorService, "init").andReturn(fakeEditor); this.DataService.getClusterMapping = function(success, error) { success({"mappings":"mappingsValue"}); }; spyOn(this.DataService, "getClusterMapping").andCallThrough(); spyOn(this.scope, "updateOptions").andReturn(); this.scope.initializeController(); expect(this.DataService.getClusterMapping).toHaveBeenCalledWith(jasmine.any(Function), jasmine.any(Function)); expect(this.scope.mappings).toEqual({"mappings":"mappingsValue"}); expect(this.scope.updateOptions).toHaveBeenCalled(); }); it('alerts when loading mappings fail', function () { var fakeEditor = {setValue: function() {}}; spyOn(this.AceEditorService, "init").andReturn(fakeEditor); this.DataService.getClusterMapping = function(success, error) { error("some reason"); }; spyOn(this.DataService, "getClusterMapping").andCallThrough(); spyOn(this.AlertService, "error").andReturn(); spyOn(this.scope, "updateOptions").andReturn(); this.scope.initializeController(); expect(this.scope.updateOptions).not.toHaveBeenCalled(); expect(this.AlertService.error).toHaveBeenCalledWith('Error while loading cluster mappings', 'some reason'); }); }); describe('execute', function() { it('cleans response when executing a request', function () { this.scope.response = "{}"; expect(this.scope.response).toEqual("{}"); this.scope.editor = { getValue: function () { return ""; } }; spyOn(this.DataService, "getClusterMapping").andReturn(); this.scope.execute(); expect(this.scope.response).toEqual(undefined); }); it('uses path, method and body from ace editor', function () { this.scope.editor = { getValue: function () { return "some value"; } }; spyOn(this.DataService, "execute").andReturn(); this.scope.execute(); expect(this.DataService.execute).toHaveBeenCalledWith("POST", "", "some value", jasmine.any(Function), jasmine.any(Function)); }); }); describe('updateOptions', function() { it('loads all possible autocompletion options', function () { this.scope.mappings = {}; this.scope.updateOptions(""); expect(this.scope.options).toEqual(['_msearch', '_search', '_suggest']); }); it('skip autocompletion if mappings is absent', function () { this.scope.mappings = undefined; this.scope.updateOptions(""); expect(this.scope.options).toEqual([]); }); }); });