This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
/
widget_area_spec.js
115 lines (90 loc) · 4.17 KB
/
widget_area_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Copyright 2016 aixigo AG
* Released under the MIT license.
* http://laxarjs.org/license
*/
define( [
'../widget_area',
'angular',
'angular-mocks'
], function( widgetAreaModule, ng ) {
'use strict';
var angularMocks = ng.mock;
///////////////////////////////////////////////////////////////////////////////////////////////////////////
describe( 'A widget area module', function() {
var register;
var deregister;
var controllerForScope;
beforeEach( function() {
deregister = jasmine.createSpy( 'deregister' );
register = jasmine.createSpy( 'pageController.areas.register' ).andCallFake( function() {
return deregister;
} );
controllerForScope = jasmine.createSpy( 'controllerForScope' ).andCallFake( function() {
return {
areas: {
register: register
}
};
} );
angularMocks.module( widgetAreaModule.name, function( $provide ) {
$provide.service( 'axPageService', function() {
return {
controllerForScope: controllerForScope
};
} );
} );
} );
////////////////////////////////////////////////////////////////////////////////////////////////////////
describe( 'provides an axWidgetArea directive that', function() {
var $compile;
var $rootScope;
var scope;
beforeEach( function() {
widgetAreaModule.controller( 'TestWidgetController', function( $scope ) { } );
} );
beforeEach( angularMocks.inject( function( _$compile_, _$rootScope_ ) {
$compile = _$compile_;
$rootScope = _$rootScope_;
scope = $rootScope.$new();
scope.boundArea = 'two';
} ) );
/////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'registers any named widget area with the page controller when linked', function() {
var link = $compile( '<div data-ax-widget-area="one"></div>' );
expect( register ).not.toHaveBeenCalled();
var element = link( scope );
expect( controllerForScope ).toHaveBeenCalledWith( scope );
expect( register ).toHaveBeenCalledWith( 'one', element[ 0 ] );
} );
/////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'registers any bound widget area with the page controller when linked', function() {
var link = $compile( '<div data-ax-widget-area data-ax-widget-area-binding="boundArea"></div>' );
expect( register ).not.toHaveBeenCalled();
var element = link( scope );
expect( controllerForScope ).toHaveBeenCalledWith( scope );
expect( register ).toHaveBeenCalledWith( 'two', element[ 0 ] );
} );
/////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'triggers an error when there is neither name nor binding', function() {
expect( function() {
$compile( '<div data-ax-widget-area></div>' )( scope );
} ).toThrow();
} );
/////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'deregisters any named area with the page controller when destroyed', function() {
$compile( '<div data-ax-widget-area="one"></div>' )( scope );
expect( deregister ).not.toHaveBeenCalled();
scope.$destroy();
expect( deregister ).toHaveBeenCalled();
} );
/////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'deregisters any bound area with the page controller when destroyed', function() {
$compile( '<div data-ax-widget-area data-ax-widget-area-binding="boundArea"></div>' )( scope );
expect( deregister ).not.toHaveBeenCalled();
scope.$destroy();
expect( deregister ).toHaveBeenCalled();
} );
} );
} );
} );