diff options
Diffstat (limited to 'example/personalLog')
| -rw-r--r-- | example/personalLog/personalLog.html | 27 | ||||
| -rw-r--r-- | example/personalLog/personalLog.js | 20 | ||||
| -rw-r--r-- | example/personalLog/test/personalLogSpec.js | 39 |
3 files changed, 40 insertions, 46 deletions
diff --git a/example/personalLog/personalLog.html b/example/personalLog/personalLog.html index bc7e2e25..77d2ddc2 100644 --- a/example/personalLog/personalLog.html +++ b/example/personalLog/personalLog.html @@ -1,28 +1,31 @@ <!doctype html> -<html xmlns:ng="http://angularjs.org" ng:app> +<html ng-app> <head> <title>Personal Log</title> - <script type="text/javascript" src="../../src/angular-bootstrap.js"></script> - <script type="text/javascript" src="personalLog.js"></script> + <script src="../../src/loader.js"></script> + <script> + setupModuleLoader(window); + </script> + <script src="personalLog.js"></script> + <script src="../../src/angular-bootstrap.js"></script> + <script src="../../src/ngCookies/cookies.js"></script> </head> - <!-- TODO: we need to expose $root so that we can delete cookies in the scenario runner, there - must be a better way to do this --> - <body ng:controller="example.personalLog.LogCtrl"> + <body ng-controller="LogCtrl"> - <form action="" ng:submit="addLog(newMsg)"> - <input type="text" ng:model="newMsg" /> - <input type="submit" value="add" /> - <input type="button" value="remove all" ng:click="rmLogs()" /> + <form action="" ng-submit="addLog(newMsg)"> + <input type="text" ng-model="newMsg"> + <input type="submit" value="add"> + <input type="button" value="remove all" ng-click="rmLogs()"> </form> <hr/> <h2>Logs:</h2> <ul> - <li ng:repeat="log in logs | orderBy:'-at'"> + <li ng-repeat="log in logs | orderBy:'-at'"> {{log.at | date:'yy-MM-dd HH:mm'}} {{log.msg}} - [<a href="" ng:click="rmLog(log)">x</a>] + [<a href="" ng-click="rmLog(log)">x</a>] </li> </ul> diff --git a/example/personalLog/personalLog.js b/example/personalLog/personalLog.js index 4d182227..c22b8702 100644 --- a/example/personalLog/personalLog.js +++ b/example/personalLog/personalLog.js @@ -5,28 +5,23 @@ * - testability of controllers * - dependency injection for controllers via $inject and constructor function * - $cookieStore for persistent cookie-backed storage - * - simple templating constructs such as ng:repeat and {{}} + * - simple templating constructs such as ng-repeat and {{}} * - date filter * - and binding onSubmit and onClick events to angular expressions * @author Igor Minar */ - -/** @namespace the 'example' namespace */ -var example = example || {}; -/** @namespace namespace of the personal log app */ -example.personalLog = {}; - - //name space isolating closure (function() { +var app = angular.module('personalLog', ['ngCookies']); + var LOGS = 'logs'; /** * The controller for the personal log app. */ -function LogCtrl($cookieStore, $scope) { +app.controller('LogCtrl', ['$cookieStore', '$scope', function LogCtrl($cookieStore, $scope) { var logs = $scope.logs = $cookieStore.get(LOGS) || []; //main model @@ -72,11 +67,6 @@ function LogCtrl($cookieStore, $scope) { logs.splice(0, logs.length); $cookieStore.remove(LOGS); }; -} - -//inject -LogCtrl.$inject = ['$cookieStore', '$scope']; +}]); -//export -example.personalLog.LogCtrl = LogCtrl; })(); diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js index ee4fb687..c68fbfc2 100644 --- a/example/personalLog/test/personalLogSpec.js +++ b/example/personalLog/test/personalLogSpec.js @@ -1,12 +1,13 @@ describe('example.personalLog.LogCtrl', function() { var logScope; - beforeEach(function() { - var injector = angular.injector(['ng', 'ngMock', 'ngCookies']); - logScope = injector.get('$rootScope'); - logScope.$cookies = injector.get('$cookies'); - injector.instantiate(example.personalLog.LogCtrl, {$scope: logScope}); - }); + + beforeEach(module('personalLog')); + + beforeEach(inject(function($rootScope, $controller) { + logScope = $rootScope.$new(); + $controller('LogCtrl', {$scope: logScope}); + })); it('should initialize notes with an empty array', function() { @@ -43,11 +44,11 @@ describe('example.personalLog.LogCtrl', function() { }); - it('should store logs in the logs cookie', function() { - expect(logScope.$cookies.logs).not.toBeDefined(); + it('should store logs in the logs cookie', inject(function($cookies) { + expect($cookies.logs).not.toBeDefined(); logScope.addLog('first log message'); - expect(logScope.$cookies.logs).toBeTruthy(); - }); + expect($cookies.logs).toBeTruthy(); + })); it('should do nothing if newMsg is empty', function() { @@ -79,17 +80,17 @@ describe('example.personalLog.LogCtrl', function() { }); - it('should update cookies when a log is deleted', function() { - expect(logScope.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/); + it('should update cookies when a log is deleted', inject(function($cookies) { + expect($cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/); logScope.rmLog(logScope.logs[1]); - expect(logScope.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/); + expect($cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/); logScope.rmLog(logScope.logs[0]); logScope.rmLog(logScope.logs[0]); logScope.rmLog(logScope.logs[0]); - expect(logScope.$cookies.logs).toMatch(/\[\]/); - }); + expect($cookies.logs).toMatch(/\[\]/); + })); }); @@ -110,10 +111,10 @@ describe('example.personalLog.LogCtrl', function() { }); - it('should remove logs cookie', function() { - expect(logScope.$cookies.logs).toBeTruthy(); + it('should remove logs cookie', inject(function($cookies) { + expect($cookies.logs).toBeTruthy(); logScope.rmLogs(); - expect(logScope.$cookies.logs).not.toBeDefined(); - }); + expect($cookies.logs).not.toBeDefined(); + })); }); }); |
