1
+ describe ( 'position elements' , function ( ) {
2
+
3
+ var TargetElMock = function ( width , height ) {
4
+ this . width = width ;
5
+ this . height = height ;
6
+
7
+ this . prop = function ( propName ) {
8
+ return propName === 'offsetWidth' ? width : height ;
9
+ } ;
10
+ } ;
11
+
12
+ var $position ;
13
+
14
+ beforeEach ( module ( 'ui.bootstrap.position' ) ) ;
15
+ beforeEach ( inject ( function ( _$position_ ) {
16
+ $position = _$position_ ;
17
+ } ) ) ;
18
+ beforeEach ( function ( ) {
19
+ this . addMatchers ( {
20
+ toBePositionedAt : function ( top , left ) {
21
+ this . message = function ( ) {
22
+ return 'Expected "(' + this . actual . top + ', ' + this . actual . left + ')" to be positioned at (' + top + ', ' + left + ')' ;
23
+ } ;
24
+
25
+ return this . actual . top == top && this . actual . left == left ;
26
+ }
27
+ } ) ;
28
+ } ) ;
29
+
30
+
31
+ describe ( 'append-to-body: false' , function ( ) {
32
+
33
+ beforeEach ( function ( ) {
34
+ //mock position info normally queried from the DOM
35
+ $position . position = function ( ) {
36
+ return {
37
+ width : 20 ,
38
+ height : 20 ,
39
+ top : 100 ,
40
+ left : 100
41
+ } ;
42
+ } ;
43
+ } ) ;
44
+
45
+ it ( 'should position element on top-center by default' , function ( ) {
46
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'other' ) ) . toBePositionedAt ( 90 , 105 ) ;
47
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'top' ) ) . toBePositionedAt ( 90 , 105 ) ;
48
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'top-center' ) ) . toBePositionedAt ( 90 , 105 ) ;
49
+ } ) ;
50
+
51
+ it ( 'should position on top-left' , function ( ) {
52
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'top-left' ) ) . toBePositionedAt ( 90 , 100 ) ;
53
+ } ) ;
54
+
55
+ it ( 'should position on top-right' , function ( ) {
56
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'top-right' ) ) . toBePositionedAt ( 90 , 120 ) ;
57
+ } ) ;
58
+
59
+ it ( 'should position elements on bottom-center when "bottom" specified' , function ( ) {
60
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'bottom' ) ) . toBePositionedAt ( 120 , 105 ) ;
61
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'bottom-center' ) ) . toBePositionedAt ( 120 , 105 ) ;
62
+ } ) ;
63
+
64
+ it ( 'should position elements on bottom-left' , function ( ) {
65
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'bottom-left' ) ) . toBePositionedAt ( 120 , 100 ) ;
66
+ } ) ;
67
+
68
+ it ( 'should position elements on bottom-right' , function ( ) {
69
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'bottom-right' ) ) . toBePositionedAt ( 120 , 120 ) ;
70
+ } ) ;
71
+
72
+ it ( 'should position elements on left-center when "left" specified' , function ( ) {
73
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'left' ) ) . toBePositionedAt ( 105 , 90 ) ;
74
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'left-center' ) ) . toBePositionedAt ( 105 , 90 ) ;
75
+ } ) ;
76
+
77
+ it ( 'should position elements on left-top when "left-top" specified' , function ( ) {
78
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'left-top' ) ) . toBePositionedAt ( 100 , 90 ) ;
79
+ } ) ;
80
+
81
+ it ( 'should position elements on left-bottom when "left-bottom" specified' , function ( ) {
82
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'left-bottom' ) ) . toBePositionedAt ( 120 , 90 ) ;
83
+ } ) ;
84
+
85
+ it ( 'should position elements on right-center when "right" specified' , function ( ) {
86
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'right' ) ) . toBePositionedAt ( 105 , 120 ) ;
87
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'right-center' ) ) . toBePositionedAt ( 105 , 120 ) ;
88
+ } ) ;
89
+
90
+ it ( 'should position elements on right-top when "right-top" specified' , function ( ) {
91
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'right-top' ) ) . toBePositionedAt ( 100 , 120 ) ;
92
+ } ) ;
93
+
94
+ it ( 'should position elements on right-top when "right-top" specified' , function ( ) {
95
+ expect ( $position . positionElements ( { } , new TargetElMock ( 10 , 10 ) , 'right-bottom' ) ) . toBePositionedAt ( 120 , 120 ) ;
96
+ } ) ;
97
+ } ) ;
98
+
99
+ } ) ;
0 commit comments