File tree Expand file tree Collapse file tree 2 files changed +139
-0
lines changed Expand file tree Collapse file tree 2 files changed +139
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ export default function Arrow(props: ArrowProps) {
1313
1414 const arrowRef = React . useRef < HTMLDivElement > ( ) ;
1515
16+ // Skip if no align
17+ if ( ! align || ! align . points ) {
18+ return null ;
19+ }
20+
1621 const alignStyle : React . CSSProperties = {
1722 position : 'absolute' ,
1823 } ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable max-classes-per-file */
2+
3+ import { act , cleanup , render } from '@testing-library/react' ;
4+ import {
5+ spyElementPrototype ,
6+ spyElementPrototypes ,
7+ } from 'rc-util/lib/test/domHook' ;
8+ import Trigger from '../src' ;
9+
10+ describe ( 'Trigger.Arrow' , ( ) => {
11+ beforeEach ( ( ) => {
12+ jest . useFakeTimers ( ) ;
13+ } ) ;
14+
15+ afterEach ( ( ) => {
16+ cleanup ( ) ;
17+ jest . useRealTimers ( ) ;
18+ } ) ;
19+
20+ async function awaitFakeTimer ( ) {
21+ for ( let i = 0 ; i < 10 ; i += 1 ) {
22+ await act ( async ( ) => {
23+ jest . advanceTimersByTime ( 100 ) ;
24+ await Promise . resolve ( ) ;
25+ } ) ;
26+ }
27+ }
28+
29+ it ( 'not show' , ( ) => {
30+ render (
31+ < Trigger popupVisible popup = { < strong > trigger</ strong > } arrow >
32+ < div />
33+ </ Trigger > ,
34+ ) ;
35+ } ) ;
36+
37+ describe ( 'direction' , ( ) => {
38+ let divSpy ;
39+ let windowSpy ;
40+
41+ beforeAll ( ( ) => {
42+ divSpy = spyElementPrototype (
43+ HTMLDivElement ,
44+ 'getBoundingClientRect' ,
45+ ( ) => ( {
46+ x : 200 ,
47+ y : 200 ,
48+ width : 100 ,
49+ height : 50 ,
50+ } ) ,
51+ ) ;
52+
53+ windowSpy = spyElementPrototypes ( Window , {
54+ clientWidth : {
55+ get : ( ) => 1000 ,
56+ } ,
57+ clientHeight : {
58+ get : ( ) => 1000 ,
59+ } ,
60+ } ) ;
61+ } ) ;
62+
63+ afterAll ( ( ) => {
64+ divSpy . mockRestore ( ) ;
65+ windowSpy . mockRestore ( ) ;
66+ } ) ;
67+
68+ function test ( name , align , style ) {
69+ it ( name , async ( ) => {
70+ render (
71+ < Trigger
72+ popupVisible
73+ popupAlign = { align }
74+ popup = { < strong > trigger</ strong > }
75+ arrow
76+ >
77+ < div />
78+ </ Trigger > ,
79+ ) ;
80+
81+ await awaitFakeTimer ( ) ;
82+
83+ console . log ( document . body . innerHTML ) ;
84+ expect ( document . querySelector ( '.rc-trigger-popup-arrow' ) ) . toHaveStyle (
85+ style ,
86+ ) ;
87+ } ) ;
88+ }
89+
90+ // Top
91+ test (
92+ 'top' ,
93+ {
94+ points : [ 'bl' , 'tl' ] ,
95+ } ,
96+ {
97+ bottom : 0 ,
98+ } ,
99+ ) ;
100+
101+ // Bottom
102+ test (
103+ 'bottom' ,
104+ {
105+ points : [ 'tc' , 'bc' ] ,
106+ } ,
107+ {
108+ top : 0 ,
109+ } ,
110+ ) ;
111+
112+ // Left
113+ test (
114+ 'left' ,
115+ {
116+ points : [ 'cr' , 'cl' ] ,
117+ } ,
118+ {
119+ right : 0 ,
120+ } ,
121+ ) ;
122+
123+ // Right
124+ test (
125+ 'right' ,
126+ {
127+ points : [ 'cl' , 'cr' ] ,
128+ } ,
129+ {
130+ left : 0 ,
131+ } ,
132+ ) ;
133+ } ) ;
134+ } ) ;
You can’t perform that action at this time.
0 commit comments