de7a63dce0148de51ead292f3fa41de91a547d35
[angular-drzb] / test / unit / controllersSpec.js
1 'use strict';
2
3 /* jasmine specs for controllers go here */
4
5 describe('RegistrationCtrl', function(){
6
7   beforeEach(module('myApp'));
8
9   var scope, ctrl, $httpBackend;
10
11   beforeEach(inject(function($injector) {
12     $httpBackend = $injector.get('$httpBackend');
13
14         $httpBackend
15                 .when('JSONP', '/<%= $couchdb_database %>/_design/registration/_view/organizations?group=true;format=key_array;callback=JSON_CALLBACK')
16                 .respond({ rows: [ 'foo', 'bar', 'baz' ] })
17         ;
18
19         $httpBackend.when('GET', 'partials/registration.html').respond('')
20
21   }));
22
23   afterEach(function() {
24           $httpBackend.verifyNoOutstandingExpectation();
25           $httpBackend.verifyNoOutstandingRequest();
26   });
27
28   beforeEach(inject(function($rootScope, $controller) {
29         scope = $rootScope.$new();
30         ctrl = $controller(RegistrationCtrl, { $scope: scope });
31   }));
32
33   it('organizations', function() {
34         $httpBackend.flush();
35         expect(scope.organizations).toEqual(['foo','bar','baz']);
36         expect(scope.user).toBeDefined();
37         expect(scope.work).toBeDefined();
38   });
39
40 });
41
42
43 describe('ListCtrl', function(){
44   var scope, $httpBackend;
45
46   beforeEach(module('myApp'));
47
48   beforeEach(inject(function($injector) {
49     $httpBackend = $injector.get('$httpBackend');
50         $httpBackend
51                 .when('GET', '/data/%3C%25=%20$couchdb_database%20%25%3E/registration?registraionId=undefined')
52                 .respond([])
53         ;
54   }));
55   afterEach(function() {
56           $httpBackend.verifyNoOutstandingExpectation();
57           $httpBackend.verifyNoOutstandingRequest();
58   });
59
60   beforeEach(inject(function($rootScope, $controller){
61     scope = $rootScope.$new();
62         var ctrl = $controller(ListCtrl, { $scope: scope } );
63   }));
64
65
66   it('ready', function() {
67         $httpBackend.flush();
68         expect( scope.ready ).toBe( true );
69   });
70
71   it('ValidStates', function() {
72         $httpBackend.flush();
73         expect( scope.ValidStates ).toBeTruthy();
74   });
75 });