3 describe('Directive: widget', function () {
5 var element, scope, rootScope, isoScope, compile, provide;
15 destroy: function () {
19 beforeEach(function () {
20 spyOn(Type.prototype, 'setup');
21 spyOn(Type.prototype, 'init');
22 spyOn(Type.prototype, 'destroy');
23 // define mock objects here
26 // load the directive's module
27 beforeEach(module('ui.dashboard', function ($provide, $controllerProvider) {
29 // Inject dependencies like this:
30 $controllerProvider.register('DashboardWidgetCtrl', function ($scope) {
36 beforeEach(inject(function ($compile, $rootScope) {
37 // Cache these for reuse
38 rootScope = $rootScope;
41 // Other setup, e.g. helper functions, etc.
43 // Set up the outer scope
44 scope = $rootScope.$new();
49 compileTemplate = jasmine.createSpy('compileTemplate');
50 scope.compileTemplate = compileTemplate;
53 function compileWidget() {
54 // Define and compile the element
55 element = angular.element('<div widget><div class="widget-content"></div></div>');
56 element = compile(element)(scope);
58 isoScope = element.isolateScope();
61 it('should create a new instance of dataModelType if provided in scope.widget', function () {
63 expect(scope.widget.dataModel instanceof Type).toBe(true);
66 it('should call setup and init on the new dataModel', function () {
68 expect(Type.prototype.setup).toHaveBeenCalled();
69 expect(Type.prototype.init).toHaveBeenCalled();
72 it('should call compile template', function () {
74 expect(scope.compileTemplate).toHaveBeenCalled();
77 it('should create a new instance of dataModelType from string name', function () {
78 // register data model with $injector
79 provide.factory('StringNameDataModel', function () {
84 dataModelType: 'StringNameDataModel'
89 expect(scope.widget.dataModel instanceof Type).toBe(true);
90 expect(Type.prototype.setup).toHaveBeenCalled();
91 expect(Type.prototype.init).toHaveBeenCalled();
94 it('should validate data model type', function () {