3 describe('Controller: DashboardWidgetCtrl', function() {
5 var $scope, $element, $timeout, injections;
7 beforeEach(module('ui.dashboard'));
9 beforeEach(inject(function($rootScope, $controller){
10 $scope = $rootScope.$new();
11 $element = angular.element('<div><div class="widget"></div></div>');
12 $timeout = function timeout(fn) {
20 spyOn(injections, '$timeout');
21 $controller('DashboardWidgetCtrl', injections);
24 describe('the makeTemplateString method', function() {
26 it('should return a string', function() {
28 templateUrl: 'some/template.html'
30 expect(typeof $scope.makeTemplateString()).toEqual('string');
33 it('should use ng-include if templateUrl is specified on widget, despite any other options', function() {
35 templateUrl: 'some/template.html',
36 template: 'not this one',
43 expect($scope.makeTemplateString()).toMatch(/ng-include="'some\/template\.html'"/);
46 it('should return widget.template if specified, regardless of presence of directive or attrs', function() {
48 template: '<div class="testing"></div>',
51 expect($scope.makeTemplateString()).toEqual($scope.widget.template);
54 it('should use widget.directive as attribute directive', function() {
56 directive: 'ng-awesome'
58 expect($scope.makeTemplateString()).toEqual('<div ng-awesome></div>');
61 it('should attach attributes if provided', function() {
63 directive: 'ng-awesome',
65 'ng-awesome': 'test1',
70 expect($scope.makeTemplateString()).toEqual('<div ng-awesome="test1" other="attr" more="stuff"></div>');
73 it('should place widgetData into dataAttrName attribute if specified', function() {
75 directive: 'ng-awesome',
77 'ng-awesome': 'test1',
83 expect($scope.makeTemplateString()).toEqual('<div ng-awesome="test1" other="attr" more="stuff" data="widgetData"></div>');
86 it('should add attrs to the widget object if it does not exist and dataAttrName is specified', function() {
88 directive: 'ng-awesome',
91 expect($scope.makeTemplateString()).toEqual('<div ng-awesome data="widgetData"></div>');
96 describe('the grabResizer method', function() {
98 var evt, widget, WidgetModel;
100 beforeEach(inject(function (_WidgetModel_) {
101 WidgetModel = _WidgetModel_;
104 beforeEach(function() {
106 stopPropagation: jasmine.createSpy('stopPropagation'),
108 preventDefault: jasmine.createSpy('preventDefault')
113 $scope.widget = widget = new WidgetModel({
120 it('should do nothing if event.which is not 1 (left click)', function() {
122 $scope.grabResizer(evt);
123 expect(evt.stopPropagation).not.toHaveBeenCalled();
126 it('should call stopPropagation and preventDefault', function() {
127 $scope.grabResizer(evt);
128 expect(evt.stopPropagation).toHaveBeenCalled();
129 expect(evt.originalEvent.preventDefault).toHaveBeenCalled();
132 it('should add a .widget-resizer-marquee element to the .widget element', function() {
133 $scope.grabResizer(evt);
134 expect($element.find('.widget-resizer-marquee').length).toBeGreaterThan(0);
139 describe('the editTitle method', function() {
141 it('should set editingTitle=true on the widget object', function() {
143 $scope.editTitle(widget);
144 expect(widget.editingTitle).toEqual(true);
147 it('should call $timeout', function() {
149 $scope.editTitle(widget);
150 expect(injections.$timeout).toHaveBeenCalled();
155 describe('the saveTitleEdit method', function() {
157 it('should set editingTitle=false', function() {
158 var widget = { editingTitle: true };
159 $scope.saveTitleEdit(widget);
160 expect(widget.editingTitle).toEqual(false);