@@ -1062,7 +1062,48 @@ describe('MDCTooltipFoundation', () => {
10621062 expect ( mockAdapter . setStyleProperty ) . toHaveBeenCalledWith ( 'left' , `80px` ) ;
10631063 } ) ;
10641064
1065- it ( 'allows users to specify the tooltip position (START alignment instead of CENTER)' ,
1065+ it ( 'properly calculates rich tooltip position (START alignment)' , ( ) => {
1066+ const anchorBoundingRect =
1067+ { top : 0 , bottom : 35 , left : 100 , right : 150 , width : 50 , height : 35 } ;
1068+ const expectedTooltipHeight =
1069+ anchorBoundingRect . height + numbers . BOUNDED_ANCHOR_GAP ;
1070+ const tooltipSize = { width : 40 , height : 30 } ;
1071+ const { foundation, mockAdapter} =
1072+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
1073+ mockAdapter . getViewportWidth . and . returnValue ( 150 ) ;
1074+ mockAdapter . getAnchorBoundingRect . and . returnValue ( anchorBoundingRect ) ;
1075+ mockAdapter . getTooltipSize . and . returnValue ( tooltipSize ) ;
1076+
1077+ foundation . show ( ) ;
1078+
1079+ expect ( mockAdapter . setStyleProperty )
1080+ . toHaveBeenCalledWith ( 'top' , `${ expectedTooltipHeight } px` ) ;
1081+ expect ( mockAdapter . setStyleProperty )
1082+ . toHaveBeenCalledWith (
1083+ 'left' , `${ anchorBoundingRect . left - tooltipSize . width } px` ) ;
1084+ } ) ;
1085+
1086+ it ( 'properly calculates rich tooltip position (END alignment)' , ( ) => {
1087+ const anchorBoundingRect =
1088+ { top : 0 , bottom : 35 , left : 0 , right : 50 , width : 50 , height : 35 } ;
1089+ const expectedTooltipTop =
1090+ anchorBoundingRect . height + numbers . BOUNDED_ANCHOR_GAP ;
1091+ const tooltipSize = { width : 40 , height : 30 } ;
1092+ const { foundation, mockAdapter} =
1093+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
1094+ mockAdapter . getViewportWidth . and . returnValue ( 150 ) ;
1095+ mockAdapter . getAnchorBoundingRect . and . returnValue ( anchorBoundingRect ) ;
1096+ mockAdapter . getTooltipSize . and . returnValue ( tooltipSize ) ;
1097+
1098+ foundation . show ( ) ;
1099+
1100+ expect ( mockAdapter . setStyleProperty )
1101+ . toHaveBeenCalledWith ( 'top' , `${ expectedTooltipTop } px` ) ;
1102+ expect ( mockAdapter . setStyleProperty )
1103+ . toHaveBeenCalledWith ( 'left' , `${ anchorBoundingRect . right } px` ) ;
1104+ } ) ;
1105+
1106+ it ( 'allows users to specify the tooltip position for plain tooltips (START alignment instead of CENTER)' ,
10661107 ( ) => {
10671108 const anchorBoundingRect =
10681109 { top : 0 , bottom : 35 , left : 32 , right : 232 , width : 200 , height : 35 } ;
@@ -1084,7 +1125,7 @@ describe('MDCTooltipFoundation', () => {
10841125 . toHaveBeenCalledWith ( 'left' , `32px` ) ;
10851126 } ) ;
10861127
1087- it ( 'ignores user specification if positioning violates threshold (CENTER alignment instead of START)' ,
1128+ it ( 'ignores user specification if positioning violates threshold for plain tooltips (CENTER alignment instead of START)' ,
10881129 ( ) => {
10891130 const anchorBoundingRect =
10901131 { top : 0 , bottom : 35 , left : 0 , right : 200 , width : 200 , height : 35 } ;
@@ -1106,7 +1147,7 @@ describe('MDCTooltipFoundation', () => {
11061147 . toHaveBeenCalledWith ( 'left' , `80px` ) ;
11071148 } ) ;
11081149
1109- it ( 'allows users to specify the tooltip position (END alignment instead of START)' ,
1150+ it ( 'allows users to specify the tooltip position for plain tooltips (END alignment instead of START)' ,
11101151 ( ) => {
11111152 const anchorHeight = 35 ;
11121153 const expectedTooltipHeight = anchorHeight + numbers . BOUNDED_ANCHOR_GAP ;
@@ -1132,6 +1173,73 @@ describe('MDCTooltipFoundation', () => {
11321173 . toHaveBeenCalledWith ( 'left' , `50px` ) ;
11331174 } ) ;
11341175
1176+ it ( 'allows users to specify the tooltip position for rich tooltips (END alignment instead of START)' ,
1177+ ( ) => {
1178+ const anchorBoundingRect =
1179+ { top : 0 , bottom : 35 , left : 132 , right : 232 , width : 100 , height : 35 } ;
1180+ const expectedTooltipTop =
1181+ anchorBoundingRect . height + numbers . BOUNDED_ANCHOR_GAP ;
1182+ const tooltipSize = { width : 40 , height : 30 } ;
1183+ const { foundation, mockAdapter} =
1184+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
1185+ mockAdapter . getViewportWidth . and . returnValue ( 500 ) ;
1186+ mockAdapter . getAnchorBoundingRect . and . returnValue ( anchorBoundingRect ) ;
1187+ mockAdapter . getTooltipSize . and . returnValue ( tooltipSize ) ;
1188+
1189+ foundation . setTooltipPosition ( { xPos : XPosition . START } ) ;
1190+ foundation . show ( ) ;
1191+
1192+ expect ( mockAdapter . setStyleProperty )
1193+ . toHaveBeenCalledWith ( 'top' , `${ expectedTooltipTop } px` ) ;
1194+ expect ( mockAdapter . setStyleProperty )
1195+ . toHaveBeenCalledWith (
1196+ 'left' , `${ anchorBoundingRect . left - tooltipSize . width } px` ) ;
1197+ } ) ;
1198+
1199+ it ( 'ignores user specification if positioning violates threshold for rich tooltips (END alignment instead of START)' ,
1200+ ( ) => {
1201+ const anchorBoundingRect =
1202+ { top : 0 , bottom : 35 , left : 0 , right : 200 , width : 200 , height : 35 } ;
1203+ const expectedTooltipTop =
1204+ anchorBoundingRect . height + numbers . BOUNDED_ANCHOR_GAP ;
1205+ const tooltipSize = { width : 40 , height : 30 } ;
1206+ const { foundation, mockAdapter} =
1207+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
1208+ mockAdapter . getViewportWidth . and . returnValue ( 500 ) ;
1209+ mockAdapter . getAnchorBoundingRect . and . returnValue ( anchorBoundingRect ) ;
1210+ mockAdapter . getTooltipSize . and . returnValue ( tooltipSize ) ;
1211+
1212+ foundation . setTooltipPosition ( { xPos : XPosition . START } ) ;
1213+ foundation . show ( ) ;
1214+
1215+ expect ( mockAdapter . setStyleProperty )
1216+ . toHaveBeenCalledWith ( 'top' , `${ expectedTooltipTop } px` ) ;
1217+ expect ( mockAdapter . setStyleProperty )
1218+ . toHaveBeenCalledWith ( 'left' , `${ anchorBoundingRect . right } px` ) ;
1219+ } ) ;
1220+
1221+ it ( 'ignores user specification if positioning is not supported for rich tooltips (END alignment instead of CENTER)' ,
1222+ ( ) => {
1223+ const anchorBoundingRect =
1224+ { top : 0 , bottom : 35 , left : 0 , right : 100 , width : 100 , height : 35 } ;
1225+ const expectedTooltipHeight =
1226+ anchorBoundingRect . height + numbers . BOUNDED_ANCHOR_GAP ;
1227+ const { foundation, mockAdapter} =
1228+ setUpFoundationTestForRichTooltip ( MDCTooltipFoundation ) ;
1229+ mockAdapter . getViewportWidth . and . returnValue ( 500 ) ;
1230+ mockAdapter . getAnchorBoundingRect . and . returnValue ( anchorBoundingRect ) ;
1231+ mockAdapter . getTooltipSize . and . returnValue ( { width : 50 , height : 30 } ) ;
1232+
1233+ foundation . setTooltipPosition ( { xPos : XPosition . CENTER } ) ;
1234+ foundation . show ( ) ;
1235+
1236+ expect ( mockAdapter . setStyleProperty )
1237+ . toHaveBeenCalledWith ( 'top' , `${ expectedTooltipHeight } px` ) ;
1238+ expect ( mockAdapter . setStyleProperty )
1239+ . toHaveBeenCalledWith ( 'left' , `${ anchorBoundingRect . right } px` ) ;
1240+ } ) ;
1241+
1242+
11351243 it ( 'properly calculates START tooltip position in RTL' , ( ) => {
11361244 const anchorBoundingRect =
11371245 { top : 0 , bottom : 35 , left : 0 , right : 100 , width : 100 , height : 35 } ;
0 commit comments