test controllers
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Jan 2013 20:16:08 +0000 (21:16 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Jan 2013 20:16:08 +0000 (21:16 +0100)
test/unit/controllersSpec.js

index bc9be5e..7548b7a 100644 (file)
@@ -2,30 +2,69 @@
 
 /* jasmine specs for controllers go here */
 
-describe('MyCtrl1', function(){
-  var myCtrl1;
+describe('RegistrationCtrl', function(){
 
-  beforeEach(function(){
-    myCtrl1 = new MyCtrl1();
+  beforeEach(module('myApp'));
+
+  var scope, ctrl, $httpBackend;
+
+  beforeEach(inject(function($injector) {
+    $httpBackend = $injector.get('$httpBackend');
+
+       $httpBackend
+               .when('JSONP', '/<%= $couchdb_database %>/_design/registration/_view/organizations?group=true;format=key_array;callback=JSON_CALLBACK')
+               .respond({ rows: [ 'foo', 'bar', 'baz' ] })
+       ;
+
+       $httpBackend.when('GET', 'partials/registration.html').respond('')
+
+  }));
+
+  afterEach(function() {
+         $httpBackend.verifyNoOutstandingExpectation();
+         $httpBackend.verifyNoOutstandingRequest();
   });
 
+  beforeEach(inject(function($rootScope, $controller) {
+       scope = $rootScope.$new();
+       ctrl = $controller(RegistrationCtrl, { $scope: scope });
+  }));
 
-  it('should ....', function() {
-    //spec body
+  it('organizations', function() {
+       $httpBackend.flush();
+       expect(scope.organizations).toEqual(['foo','bar','baz']);
+       expect(scope.user).toBeDefined();
+       expect(scope.work).toBeDefined();
   });
+
 });
 
 
-describe('MyCtrl2', function(){
-  var myCtrl2;
+describe('ListCtrl', function(){
+  var scope, $httpBackend;
 
+  beforeEach(module('myApp'));
 
-  beforeEach(function(){
-    myCtrl2 = new MyCtrl2();
+  beforeEach(inject(function($injector) {
+    $httpBackend = $injector.get('$httpBackend');
+       $httpBackend
+               .when('GET', '/data/%3C%25=%20$couchdb_database%20%25%3E/registration?registraionId=undefined')
+               .respond([])
+       ;
+  }));
+  afterEach(function() {
+         $httpBackend.verifyNoOutstandingExpectation();
+         $httpBackend.verifyNoOutstandingRequest();
   });
 
+  beforeEach(inject(function($rootScope, $controller){
+    scope = $rootScope.$new();
+       var ctrl = $controller(ListCtrl, { $scope: scope } );
+  }));
+
 
-  it('should ....', function() {
-    //spec body
+  it('ready', function() {
+       $httpBackend.flush();
+       expect( scope.ready ).toBe( true );
   });
 });