Ejemplo n.º 1
0
 it('should register provider to sam module for angular DI and inject dependencies', function() {
     samModule.createModule();
     var myDependency = {
        name: 'helloDependency',
        configure: function() {
             return 'DependencyConfigure';
         },
         get: function() {
             return 'DependencyGet';
         }
     };
     var myModule = {
         name: 'hello',
         configure: function(helloDependencyProvider) {
             return helloDependencyProvider.configure;
         },
         get: function(helloDependency) {
             return helloDependency;
         },
         getDependencies: function() {
             return [myDependency];
         }
     };
     register(myModule);
     angular.module('samMocks', []).config(function(helloProvider) {
         expect(helloProvider.configure).toEqual(myDependency.configure());
     });
     angular.mock.module('sam', 'samMocks');
     angular.mock.inject(function(hello) {
         expect(hello).toBe(myDependency.get());
     });
 });
Ejemplo n.º 2
0
  it('should only register di modules once', function() {
     samModule.createModule();
     var injectCounter = 0;
     var myModule = {
         name: 'hello',
         inject: function() {
             ++injectCounter;
             return 'ModuleContent';
         }
     };
     var myModule2 = {
         name: 'hello2',
         inject: function() {
             return 'ModuleContent2';
         },
         getDependencies: function() {
             return [myModule];
         }
     };
     register(myModule);
     register(myModule2);
     angular.mock.module('sam');
     angular.mock.inject(function(hello, hello2) {
         expect(hello).toBe('ModuleContent');
         expect(hello2).toBe('ModuleContent2');
     });
      expect(injectCounter).toBe(1);
 });
Ejemplo n.º 3
0
 it('should eat their own dog food', function() {
     samModule.createModule();
     angular.mock.module('sam');
     register(ngUtils);
     angular.mock.inject(['ngUtils', function(ngUtilsModule) {
         expect(ngUtilsModule.register).toBe(register);
     }]);
 });
Ejemplo n.º 4
0
 beforeEach(function() {
     samModule.createModule();
     angular.mock.module('sam');
     angular.mock.inject(function($compile, $rootScope, $ocLazyLoad) {
         ngUtils.register(changePassword, $ocLazyLoad);
         ngUtils.register(userManagerMock);
         element = $compile('<section data-change-password></section>')($rootScope);
         $rootScope.$digest();
         scope = element.isolateScope();
     });
 });
Ejemplo n.º 5
0
 it('di module should become a provider', function() {
     samModule.createModule();
     var myModule = {
         name: 'hello',
         inject: function() {
             return 'ModuleContent';
         }
     };
     register(myModule);
     angular.mock.module('sam');
     angular.mock.inject(function(hello) {
         expect(hello).toBe(myModule.inject());
     });
 });
Ejemplo n.º 6
0
 it('provider should work without configure', function() {
     samModule.createModule();
     var myModule = {
         name: 'hello',
         get: function() {
             return 'ModuleContent';
         }
     };
     register(myModule);
     angular.mock.module('sam');
     angular.mock.inject(function(hello) {
         expect(hello).toBe(myModule.get());
     });
 });
Ejemplo n.º 7
0
 it('should not register a non existing dependent angular module', function(done) {
     samModule.createModule();
     angular.mock.module('sam');
     var myModule = {
         ngModule: 'myNonExistingModule'
     };
     register(myModule, {
         load: function() {
             return rsvp.Promise.reject();
         }
     }).catch(function() {
         done();
     });
 });
Ejemplo n.º 8
0
    beforeEach(function(done) {
        samModule.createModule();
        ngUtils.register(globalMessages);
        angular.mock.module('sam');

        angular.mock.inject(function($compile, $rootScope) {
            element = $compile(
                '<div data-global-messages></div>'
            )($rootScope);
            $scope = element.scope();
            $scope.$digest();
            element = jquery(element);
            done();
        });
    });
Ejemplo n.º 9
0
 it('provider should work without get', function() {
     samModule.createModule();
     var myModule = {
         name: 'hello',
         configure: function() {
             return 'ModuleConfigure';
         }
     };
     register(myModule);
     angular.module('samMocks', []).config(function(helloProvider) {
         expect(helloProvider.configure).toEqual(myModule.configure());
     });
     angular.mock.module('sam', 'samMocks');
     angular.mock.inject();
 });
Ejemplo n.º 10
0
    beforeEach(function(done) {
        samModule.createModule();
        angular.mock.module('sam');
        angular.mock.inject(function($ocLazyLoad) {
            ngUtils.register(header, $ocLazyLoad);
        });

        angular.mock.inject(function($compile, _$rootScope_) {
            $rootScope = _$rootScope_;
            $rootScope.rootNavOpen = false;
            element = $compile('<div data-header data-nav-open="rootNavOpen" ></div>')($rootScope);
            $rootScope.$digest();
            done();
        });
    });
Ejemplo n.º 11
0
    beforeEach(function() {
        samModule.createModule();
        ngUtils.register(compareTo);
        angular.mock.module('sam');

        angular.mock.inject(function($compile, $rootScope) {
            element = $compile(
                '<form name="testForm">' +
                '<input type="text" id="password" ng-model="model.password" name="password" />' +
                '<input type="text" id="confPassword" ng-model="model.confPassword" name="confPassword" compare-to="model.password" />' +
                '</form>'
            )($rootScope);
            $scope = element.scope();
            form = $scope.testForm;
            $scope.$digest();
        });
    });
Ejemplo n.º 12
0
    beforeEach(function() {
        samModule.createModule();
        ngUtils.register(eventsTable);
        ngUtils.register(eventRetrieverMock);
        ngUtils.register(windowMock);
        ngUtils.register(stateMock);
        angular.mock.module('sam');

        angular.mock.inject(function($compile, $rootScope, $state, _$window_) {
            $window = _$window_;
            state = $state;
            element = $compile('<table data-events-table></table>')($rootScope);
            $rootScope.$digest();
            scope = element.isolateScope();
            scope.summary = false;
        });
    });
Ejemplo n.º 13
0
 it('should register a dependent angular module', function(done) {
     samModule.createModule();
     angular.module('myModule', []).constant('myDirectiveInExternalModule', 'HGST');
     var myModule = {
         ngModule: 'myModule'
     };
     angular.mock.module('sam', 'myModule');
     register(myModule, {
         load: function() {
             return rsvp.Promise.resolve();
         }
     }).then(function() {
         angular.mock.inject(function(myDirectiveInExternalModule) {
             expect(myDirectiveInExternalModule).toBe('HGST');
         });
         done();
     });
 });
Ejemplo n.º 14
0
    it('should register controller to sam module', function() {
        samModule.createModule();
        var myCtrl = {
            name: 'HelloCtrl',
            controller: /*@ngInject*/ function($scope) {
                $scope.loaded = true;
            }
        };
        angular.mock.module('sam');
        register(myCtrl);

        var scope;
        angular.mock.inject(function ($controller, $rootScope) {
            scope = $rootScope.$new();
            $controller('HelloCtrl', {
                $scope: scope
            });
        });
        expect(scope.loaded).toBe(true);
    });
Ejemplo n.º 15
0
 it('should register provider to sam module for angular DI', function() {
     samModule.createModule();
     var myModule = {
         name: 'hello',
         configure: function() {
             return 'ModuleConfigure';
         },
         get: function() {
             return 'ModuleContent';
         }
     };
     register(myModule);
     angular.module('samMocks', []).config(function(helloProvider) {
         expect(helloProvider.configure).toEqual(myModule.configure());
     });
     angular.mock.module('sam', 'samMocks');
     angular.mock.inject(function(hello) {
         expect(hello).toBe(myModule.get());
     });
 });
Ejemplo n.º 16
0
    it('should register directive to sam module', function() {
        samModule.createModule();
        var myDirective = {
            name: 'helloDirective',
            directive: function() {
                return {
                    replace: 'true',
                    template: '<div>Hello directive!</div>'
                };
            }
        };
        angular.mock.module('sam');
        register(myDirective);

        var element;
        angular.mock.inject(function($compile, $rootScope) {
            element = $compile('<div data-hello-directive></div>')($rootScope);
            $rootScope.$digest();
        });
        expect(element.html()).toBe('Hello directive!');
    });