@@ -2,6 +2,7 @@ import { cleanup, fireEvent, render } from '@testing-library/react';
2
2
import React from 'react' ;
3
3
import Trigger , { UniqueProvider } from '../src' ;
4
4
import { awaitFakeTimer } from './util' ;
5
+ import type { TriggerProps } from '../src' ;
5
6
6
7
// Mock FloatBg to check if open props changed
7
8
global . openChangeLog = [ ] ;
@@ -27,6 +28,34 @@ jest.mock('../src/UniqueProvider/FloatBg', () => {
27
28
} ;
28
29
} ) ;
29
30
31
+ async function setupAndOpenPopup ( triggerProps : Partial < TriggerProps > = { } ) {
32
+ const { container } = render (
33
+ < UniqueProvider >
34
+ < Trigger
35
+ action = { [ 'click' ] }
36
+ popup = { < strong className = "x-content" > tooltip</ strong > }
37
+ unique
38
+ { ...triggerProps }
39
+ >
40
+ < div className = "target" > click me</ div >
41
+ </ Trigger >
42
+ </ UniqueProvider > ,
43
+ ) ;
44
+
45
+ // Initially no popup should be visible
46
+ expect ( document . querySelector ( '.rc-trigger-popup' ) ) . toBeFalsy ( ) ;
47
+
48
+ // Click trigger to show popup
49
+ fireEvent . click ( container . querySelector ( '.target' ) ) ;
50
+ await awaitFakeTimer ( ) ;
51
+
52
+ // Check that popup exists
53
+ const popup = document . querySelector ( '.rc-trigger-popup' ) ;
54
+ expect ( popup ) . toBeTruthy ( ) ;
55
+
56
+ return { container, popup } ;
57
+ }
58
+
30
59
describe ( 'Trigger.Unique' , ( ) => {
31
60
beforeEach ( ( ) => {
32
61
jest . useFakeTimers ( ) ;
@@ -152,4 +181,34 @@ describe('Trigger.Unique', () => {
152
181
expect ( popup . className ) . toContain ( 'custom-align' ) ;
153
182
expect ( popup . className ) . toContain ( 'rc-trigger-popup-unique-controlled' ) ;
154
183
} ) ;
184
+
185
+ it ( 'should apply uniqueBgClassName to FloatBg component' , async ( ) => {
186
+ await setupAndOpenPopup ( { uniqueBgClassName : 'custom-bg-class' } ) ;
187
+
188
+ // Check that FloatBg has the custom background className
189
+ const floatBg = document . querySelector ( '.rc-trigger-popup-float-bg' ) ;
190
+ expect ( floatBg ) . toBeTruthy ( ) ;
191
+ expect ( floatBg . className ) . toContain ( 'custom-bg-class' ) ;
192
+ } ) ;
193
+
194
+ it ( 'should apply uniqueBgStyle to FloatBg component' , async ( ) => {
195
+ await setupAndOpenPopup ( { uniqueBgStyle : { backgroundColor : 'red' , border : '1px solid blue' } } ) ;
196
+
197
+ // Check that FloatBg has the custom background style
198
+ const floatBg = document . querySelector ( '.rc-trigger-popup-float-bg' ) ;
199
+ expect ( floatBg ) . toBeTruthy ( ) ;
200
+ expect ( floatBg ) . toHaveStyle ( {
201
+ backgroundColor : 'red' ,
202
+ border : '1px solid blue' ,
203
+ } ) ;
204
+ } ) ;
205
+
206
+ it ( 'should not apply any additional className to FloatBg when uniqueBgClassName is not provided' , async ( ) => {
207
+ await setupAndOpenPopup ( ) ;
208
+
209
+ // Check that FloatBg exists but does not have custom background className
210
+ const floatBg = document . querySelector ( '.rc-trigger-popup-float-bg' ) ;
211
+ expect ( floatBg ) . toBeTruthy ( ) ;
212
+ expect ( floatBg . className ) . not . toContain ( 'undefined' ) ;
213
+ } ) ;
155
214
} ) ;
0 commit comments