From: Gustavo Martin Morcuende
Date: Sun, 13 Sep 2015 23:44:53 +0000 (+0200)
Subject: showcase: renaming controllers to NameController and using always $scope and $rootSco...
X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=cebe73e5f6aa8bcac043b0b2d2331e11be99bf44;p=JavaScriptForFun
showcase: renaming controllers to NameController and using always $scope and $rootScope variables in specs.
---
diff --git a/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js
index 2f6456a..d40d7e8 100644
--- a/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js
+++ b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js
@@ -3,11 +3,11 @@
angular
.module('app.cars')
- .controller('CarsErrorModal', CarsErrorModal);
+ .controller('CarsErrorModalController', CarsErrorModalController);
/**
* @ngdoc controller
- * @name app.cars.controller:CarsErrorModal
+ * @name app.cars.controller:CarsErrorModalController
*
* @requires $modalInstance
* @requires app.cars.cars
@@ -21,7 +21,7 @@
* Controller for error modal in cars application.
*/
/* @ngInject */
- function CarsErrorModal($modalInstance, cars) {
+ function CarsErrorModalController($modalInstance, cars) {
var vm = this;
vm.cars = cars;
diff --git a/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.spec.js b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.spec.js
index f85e9f4..bf72b5d 100644
--- a/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.spec.js
+++ b/angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.spec.js
@@ -6,13 +6,13 @@ describe('app.cars', function() {
close: jasmine.createSpy('modalInstance.close'),
dismiss: jasmine.createSpy('modalInstance.dismiss')
};
- var CarsErrorModal;
+ var CarsErrorModalController;
beforeEach(function() {
module('app.cars');
inject(function($controller) {
- CarsErrorModal = $controller('CarsErrorModal', {
+ CarsErrorModalController = $controller('CarsErrorModalController', {
$modalInstance: $modalInstance,
cars: cars
});
@@ -20,16 +20,16 @@ describe('app.cars', function() {
});
- describe('CarsErrorModal controller', function () {
+ describe('CarsErrorModalController controller', function () {
it('should invoke $modalInstance.close', function () {
- CarsErrorModal.ok();
+ CarsErrorModalController.ok();
expect($modalInstance.close).toHaveBeenCalledWith('car1');
});
it('should invoke $modalInstance.dismiss', function () {
- CarsErrorModal.cancel();
+ CarsErrorModalController.cancel();
expect($modalInstance.dismiss).toHaveBeenCalledWith('cancel');
});
diff --git a/angularjs/showcase/src/showcase/app/cars/cars.controller.js b/angularjs/showcase/src/showcase/app/cars/cars.controller.js
index 7734c20..dec4420 100644
--- a/angularjs/showcase/src/showcase/app/cars/cars.controller.js
+++ b/angularjs/showcase/src/showcase/app/cars/cars.controller.js
@@ -3,11 +3,11 @@
angular
.module('app.cars')
- .controller('Cars', Cars);
+ .controller('CarsController', CarsController);
/**
* @ngdoc controller
- * @name app.cars.controller:Cars
+ * @name app.cars.controller:CarsController
*
* @requires $modal
* @requires $timeout
@@ -20,10 +20,10 @@
*
*
* @description
- * Cars controller.
+ * CarsController controller.
*/
/* @ngInject */
- function Cars($modal, $timeout, cars) {
+ function CarsController($modal, $timeout, cars) {
var vm = this;
vm.example = {
@@ -40,7 +40,7 @@
},
// Error
function(reason) {
- console.log('Cars controller error: ' + reason);
+ console.log('CarsController controller error: ' + reason);
vm.doModal('lg');
}
);
@@ -51,19 +51,19 @@
cars.getById(1).then(
function (value) {
- console.log('getCar getById: Cars controller value: ' + JSON.stringify(value));
+ console.log('getCar getById: CarsController controller value: ' + JSON.stringify(value));
},
function(reason) {
- console.log('getCar getById: Cars controller reason: ' + JSON.stringify(reason));
+ console.log('getCar getById: CarsController controller reason: ' + JSON.stringify(reason));
}
);
cars.getExpectedValue().then(
function (value) {
- console.log('getCar getExpectedValue: Cars controller value: ' + JSON.stringify(value));
+ console.log('getCar getExpectedValue: CarsController controller value: ' + JSON.stringify(value));
},
function(reason) {
- console.log('getCar getExpectedValue: Cars controller reason: ' + JSON.stringify(reason));
+ console.log('getCar getExpectedValue: CarsController controller reason: ' + JSON.stringify(reason));
}
);
@@ -74,10 +74,12 @@
cars.getExpectedValue().then(
function (value) {
- console.log('getResolvedPromise getExpectedValue: Cars controller value: ' + JSON.stringify(value));
+ console.log('getResolvedPromise getExpectedValue: CarsController controller value: ' +
+ JSON.stringify(value));
},
function(reason) {
- console.log('getResolvedPromise getExpectedValue: Cars controller reason: ' + JSON.stringify(reason));
+ console.log('getResolvedPromise getExpectedValue: CarsController controller reason: ' +
+ JSON.stringify(reason));
}
);
@@ -95,7 +97,7 @@
var modalInstance = $modal.open({
animation: true,
templateUrl: 'app/cars/cars-error-modal.html',
- controller: 'CarsErrorModal as vm',
+ controller: 'CarsErrorModalController as vm',
size: size,
backdrop: 'static',
keyboard: false,
diff --git a/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js b/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js
index b4f2030..81f1924 100644
--- a/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js
+++ b/angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js
@@ -10,14 +10,14 @@ describe('app.cars', function() {
return {};
}
};
- var Cars;
+ var CarsController;
var $q;
beforeEach(function() {
module('app.cars');
inject(function($controller, $modal, $timeout, _$q_) {
- Cars = $controller('Cars', {
+ CarsController = $controller('CarsController', {
$modal: $modal,
$timeout: $timeout,
cars: cars
@@ -43,10 +43,10 @@ describe('app.cars', function() {
};
});
- Cars.getCars();
+ CarsController.getCars();
expect(cars.getAll).toHaveBeenCalled();
- expect(Cars.cars).toEqual(onFulfilledValue);
+ expect(CarsController.cars).toEqual(onFulfilledValue);
});
});
@@ -114,14 +114,14 @@ describe('app.cars', function() {
})
};
var $timeout;
- var Cars;
+ var CarsController;
var $q;
beforeEach(function() {
module('app.cars');
inject(function($controller, _$timeout_, _$q_) {
- Cars = $controller('Cars', {
+ CarsController = $controller('CarsController', {
$modal: $modal,
$timeout: _$timeout_,
cars: cars
@@ -135,46 +135,46 @@ describe('app.cars', function() {
it('should invoke GET all cars in service with success: alternative way', function () {
- Cars.getCars();
+ CarsController.getCars();
expect(cars.getAll).toHaveBeenCalled();
- expect(Cars.cars).toEqual(onFulfilledValue);
+ expect(CarsController.cars).toEqual(onFulfilledValue);
});
it('should invoke GET all cars in service with error: alternative way', function () {
isSuccessCallBack = false;
- spyOn(Cars, 'doModal')
+ spyOn(CarsController, 'doModal')
.and.callFake(function() {
return {};
});
- Cars.getCars();
+ CarsController.getCars();
expect(cars.getAll).toHaveBeenCalled();
- expect(Cars.doModal).toHaveBeenCalled();
+ expect(CarsController.doModal).toHaveBeenCalled();
isSuccessCallBack = true;
});
it('should invoke $modal.open', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modal.open).toHaveBeenCalled();
});
it('should invoke $modalInstance.result with success', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.result.then).toHaveBeenCalled();
- expect(Cars.selected).toEqual(onFulfilledValue);
+ expect(CarsController.selected).toEqual(onFulfilledValue);
});
it('should invoke $modalInstance.result with error', function () {
isSuccessCallBack = false;
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.result.then).toHaveBeenCalled();
@@ -183,7 +183,7 @@ describe('app.cars', function() {
it('should invoke $modalInstance.opened with success', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.opened.then).toHaveBeenCalled();
@@ -192,7 +192,7 @@ describe('app.cars', function() {
it('should invoke $modalInstance.opened with error', function () {
isSuccessCallBack = false;
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.opened.then).toHaveBeenCalled();
@@ -201,7 +201,7 @@ describe('app.cars', function() {
it('should invoke $modalInstance.rendered with success', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.rendered.then).toHaveBeenCalled();
@@ -210,7 +210,7 @@ describe('app.cars', function() {
it('should invoke $modalInstance.rendered with error', function () {
isSuccessCallBack = false;
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.rendered.then).toHaveBeenCalled();
@@ -219,7 +219,7 @@ describe('app.cars', function() {
it('should invoke $modalInstance.close because of timeout', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
$timeout.flush();
expect($modalInstance.close).toHaveBeenCalledWith('closed by timeout');
@@ -228,7 +228,7 @@ describe('app.cars', function() {
it('should invoke $modalInstance.dismiss because of timeout', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
$timeout.flush();
expect($modalInstance.dismiss).toHaveBeenCalledWith('dismissed by timeout');
diff --git a/angularjs/showcase/src/showcase/app/cars/cars.html b/angularjs/showcase/src/showcase/app/cars/cars.html
index fda95e9..28d2756 100644
--- a/angularjs/showcase/src/showcase/app/cars/cars.html
+++ b/angularjs/showcase/src/showcase/app/cars/cars.html
@@ -1,7 +1,7 @@