@@ -147,7 +147,7 @@ function getOverlayWrapperLocation(
147147 } else if ( positionSettings . verticalStartPoint === VerticalAlignment . Middle ) {
148148 location . y = Math . max ( 0 , targetRect . top + targetRect . height / 2 - flipOffset ) ;
149149 } else {
150- location . y = Math . max ( 0 , targetRect . top - flipOffset ) ;
150+ location . y = Math . max ( 0 , targetRect . top - flipOffset ) ;
151151 }
152152 }
153153 } else if ( location . y + wrapperRect . height > screenRect . bottom && ! elastic ) {
@@ -163,7 +163,23 @@ function getOverlayWrapperLocation(
163163 return location ;
164164}
165165
166+ /**
167+ * Formats a string according to the given formatters
168+ * @param inputString String to be formatted
169+ * @param formatters Each formatter should include regex expressions and replacements to be applied on the inputString
170+ */
171+ function formatString ( inputString : string , formatters : any [ ] ) {
172+ formatters . forEach ( function ( formatter ) {
173+ inputString = inputString . replace ( formatter . pattern , formatter . replacement ) ;
174+ } ) ;
175+ return inputString ;
176+ }
177+
166178describe ( 'igxOverlay' , ( ) => {
179+ const formatters = [
180+ { pattern : / : \s / g, replacement : ':' } ,
181+ { pattern : / r e d ; / , replacement : 'red' }
182+ ] ;
167183 beforeEach ( async ( ( ) => {
168184 UIInteractions . clearOverlay ( ) ;
169185 } ) ) ;
@@ -856,10 +872,10 @@ describe('igxOverlay', () => {
856872 spyOn ( Util , 'getViewportRect' ) . and . returnValue ( viewPortRect ) ;
857873 spyOn ( Util , 'getTargetRect' ) . and . returnValue ( targetRect ) ;
858874
859- const element = jasmine . createSpyObj ( 'HTMLElement' , [ 'getBoundingClientRect' ] ) ;
875+ const element = jasmine . createSpyObj ( 'HTMLElement' , [ 'getBoundingClientRect' ] ) ;
860876 spyOn ( element , 'getBoundingClientRect' ) . and . returnValue ( elementRect ) ;
861- element . classList = { add : ( ) => { } } ;
862- element . style = { width : '' , height : '' } ;
877+ element . classList = { add : ( ) => { } } ;
878+ element . style = { width : '' , height : '' } ;
863879 elastic . position ( element , null , null , true ) ;
864880
865881 expect ( element . style . width ) . toBe ( '200px' ) ;
@@ -1678,8 +1694,9 @@ describe('igxOverlay', () => {
16781694 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
16791695 const wrapperContent = wrappers [ wrappers . length - 1 ] . lastElementChild ; // wrapped in NG-COMPONENT
16801696 expect ( wrapperContent . children . length ) . toEqual ( 1 ) ;
1681- expect ( wrapperContent . lastElementChild . getAttribute ( 'style' ) )
1682- . toEqual ( 'width:100px; height: 100px; background-color: red' ) ;
1697+ let overlayStyle = wrapperContent . lastElementChild . getAttribute ( 'style' ) ;
1698+ overlayStyle = formatString ( overlayStyle , formatters ) ;
1699+ expect ( overlayStyle ) . toEqual ( 'width:100px; height:100px; background-color:red' ) ;
16831700 } ) ) ;
16841701
16851702 it ( 'Should show the component inside of the viewport if it would normally be outside of bounds, BOTTOM + RIGHT.' , fakeAsync ( ( ) => {
@@ -1702,8 +1719,10 @@ describe('igxOverlay', () => {
17021719 fix . detectChanges ( ) ;
17031720 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
17041721 const wrapperContent = wrappers [ wrappers . length - 1 ] as HTMLElement ; // wrapped in NG-COMPONENT
1705- const expectedStyle = 'width:100px; height: 100px; background-color: red' ;
1706- expect ( wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ) . toEqual ( expectedStyle ) ;
1722+ const expectedStyle = 'width:100px; height:100px; background-color:red' ;
1723+ let overlayStyle = wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ;
1724+ overlayStyle = formatString ( overlayStyle , formatters ) ;
1725+ expect ( overlayStyle ) . toEqual ( expectedStyle ) ;
17071726 const buttonLeft = buttonElement . offsetLeft ;
17081727 const buttonTop = buttonElement . offsetTop ;
17091728 const expectedLeft = buttonLeft - wrapperContent . lastElementChild . lastElementChild . clientWidth ;
@@ -2131,8 +2150,9 @@ describe('igxOverlay', () => {
21312150 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
21322151 const wrapperContent = wrappers [ wrappers . length - 1 ] . lastElementChild ; // wrapped in NG-COMPONENT
21332152 expect ( wrapperContent . children . length ) . toEqual ( 1 ) ;
2134- expect ( wrapperContent . lastElementChild . getAttribute ( 'style' ) )
2135- . toEqual ( 'width:100px; height: 100px; background-color: red' ) ;
2153+ let overlayStyle = wrapperContent . lastElementChild . getAttribute ( 'style' ) ;
2154+ overlayStyle = formatString ( overlayStyle , formatters ) ;
2155+ expect ( overlayStyle ) . toEqual ( 'width:100px; height:100px; background-color:red' ) ;
21362156 } ) ) ;
21372157
21382158 it ( 'Should show the component inside of the viewport if it would normally be outside of bounds, BOTTOM + RIGHT.' , fakeAsync ( ( ) => {
@@ -2910,8 +2930,10 @@ describe('igxOverlay', () => {
29102930 fix . detectChanges ( ) ;
29112931 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
29122932 const wrapperContent = wrappers [ wrappers . length - 1 ] as HTMLElement ;
2913- const expectedStyle = 'width:100px; height: 100px; background-color: red' ;
2914- expect ( wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ) . toEqual ( expectedStyle ) ;
2933+ const expectedStyle = 'width:100px; height:100px; background-color:red' ;
2934+ let overlayStyle = wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ;
2935+ overlayStyle = formatString ( overlayStyle , formatters ) ;
2936+ expect ( overlayStyle ) . toEqual ( expectedStyle ) ;
29152937 const buttonLeft = buttonElement . offsetLeft ;
29162938 const buttonTop = buttonElement . offsetTop ;
29172939 const expectedLeft = buttonLeft + buttonElement . clientWidth ; // To the right of the button
@@ -2960,8 +2982,10 @@ describe('igxOverlay', () => {
29602982 fix . detectChanges ( ) ;
29612983 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
29622984 const wrapperContent = wrappers [ wrappers . length - 1 ] as HTMLElement ;
2963- const expectedStyle = 'width:100px; height: 100px; background-color: red' ;
2964- expect ( wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ) . toEqual ( expectedStyle ) ;
2985+ const expectedStyle = 'width:100px; height:100px; background-color:red' ;
2986+ let overlayStyle = wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ;
2987+ overlayStyle = formatString ( overlayStyle , formatters ) ;
2988+ expect ( overlayStyle ) . toEqual ( expectedStyle ) ;
29652989 const buttonLeft = buttonElement . offsetLeft ;
29662990 const buttonTop = buttonElement . offsetTop ;
29672991 const expectedRight = buttonLeft ; // To the left of the button
@@ -3009,8 +3033,10 @@ describe('igxOverlay', () => {
30093033 fix . detectChanges ( ) ;
30103034 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
30113035 const contentElement = wrappers [ wrappers . length - 1 ] as HTMLElement ; // wrapper in NG-COMPONENT
3012- const expectedStyle = 'width:100px; height: 100px; background-color: red' ;
3013- expect ( contentElement . lastElementChild . lastElementChild . getAttribute ( 'style' ) ) . toEqual ( expectedStyle ) ;
3036+ const expectedStyle = 'width:100px; height:100px; background-color:red' ;
3037+ let overlayStyle = contentElement . lastElementChild . lastElementChild . getAttribute ( 'style' ) ;
3038+ overlayStyle = formatString ( overlayStyle , formatters ) ;
3039+ expect ( overlayStyle ) . toEqual ( expectedStyle ) ;
30143040 const expectedRight = buttonElement . offsetLeft ;
30153041 const expectedTop = buttonElement . offsetTop + buttonElement . clientHeight ;
30163042 const contentElementRect = contentElement . getBoundingClientRect ( ) ;
@@ -3058,8 +3084,10 @@ describe('igxOverlay', () => {
30583084 fix . detectChanges ( ) ;
30593085 const wrappers = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT ) ;
30603086 const wrapperContent = wrappers [ wrappers . length - 1 ] as HTMLElement ;
3061- const expectedStyle = 'width:100px; height: 100px; background-color: red' ;
3062- expect ( wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ) . toEqual ( expectedStyle ) ;
3087+ const expectedStyle = 'width:100px; height:100px; background-color:red' ;
3088+ let overlayStyle = wrapperContent . lastElementChild . lastElementChild . getAttribute ( 'style' ) ;
3089+ overlayStyle = formatString ( overlayStyle , formatters ) ;
3090+ expect ( overlayStyle ) . toEqual ( expectedStyle ) ;
30633091 const buttonLeft = buttonElement . offsetLeft ;
30643092 const buttonTop = buttonElement . offsetTop ;
30653093 const expectedLeft = buttonLeft + buttonElement . clientWidth ; // To the right of the button
0 commit comments