|
1 |
| -import React from 'react'; |
2 |
| -import { render } from '@testing-library/react'; |
3 | 1 | import Popup from '../src/Popup';
|
4 | 2 |
|
5 | 3 | describe('Popup', () => {
|
6 | 4 | // Used in antd for C2D2C
|
7 | 5 | it('should export', () => {
|
8 | 6 | expect(Popup).toBeTruthy();
|
9 | 7 | });
|
10 |
| - |
11 |
| - it('should correctly extract text from string, number, function, and element', () => { |
12 |
| - const { getByRole } = render( |
13 |
| - <Popup prefixCls="test" id="popup-id"> |
14 |
| - {() => ( |
15 |
| - <> |
16 |
| - {'Hello'} |
17 |
| - {123} |
18 |
| - <span>World</span> |
19 |
| - </> |
20 |
| - )} |
21 |
| - </Popup>, |
22 |
| - ); |
23 |
| - |
24 |
| - const tooltip = getByRole('tooltip'); |
25 |
| - const hiddenTextContainer = tooltip.querySelector('div > div'); |
26 |
| - |
27 |
| - expect(hiddenTextContainer.textContent).toBe('Hello 123 World'); |
28 |
| - }); |
29 |
| - |
30 |
| - it('should apply updated hidden text styles correctly', () => { |
31 |
| - const { getByRole } = render( |
32 |
| - <Popup prefixCls="test" id="popup-id"> |
33 |
| - test hidden text |
34 |
| - </Popup>, |
35 |
| - ); |
36 |
| - |
37 |
| - const tooltip = getByRole('tooltip'); |
38 |
| - const hiddenTextContainer = tooltip.querySelector('div > div'); |
39 |
| - |
40 |
| - expect(hiddenTextContainer).toHaveStyle({ |
41 |
| - width: '0', |
42 |
| - height: '0', |
43 |
| - position: 'absolute', |
44 |
| - overflow: 'hidden', |
45 |
| - opacity: '0', |
46 |
| - }); |
47 |
| - }); |
48 |
| - |
49 |
| - it('should return empty string if children is null or undefined', () => { |
50 |
| - const { getByRole } = render( |
51 |
| - <Popup prefixCls="test" id="popup-empty"> |
52 |
| - {null} |
53 |
| - </Popup>, |
54 |
| - ); |
55 |
| - const tooltip = getByRole('tooltip'); |
56 |
| - |
57 |
| - expect(tooltip.querySelector('div > div')).toBeNull(); |
58 |
| - }); |
59 |
| - |
60 |
| - it('should handle nested arrays correctly', () => { |
61 |
| - const { getByRole } = render( |
62 |
| - <Popup prefixCls="test" id="popup-nested"> |
63 |
| - {[ |
64 |
| - 'First', |
65 |
| - ['Second', 'Third'], |
66 |
| - <span key="fourth">Fourth</span>, |
67 |
| - ]} |
68 |
| - </Popup>, |
69 |
| - ); |
70 |
| - const tooltip = getByRole('tooltip'); |
71 |
| - const hiddenTextContainer = tooltip.querySelector('div > div'); |
72 |
| - |
73 |
| - // "First Second Third Fourth" |
74 |
| - expect(hiddenTextContainer.textContent).toBe('First Second Third Fourth'); |
75 |
| - }); |
76 |
| - |
77 |
| - it('should handle function returning an array', () => { |
78 |
| - const { getByRole } = render( |
79 |
| - <Popup prefixCls="test" id="popup-func-array"> |
80 |
| - {() => ['Alpha', <span key="beta">Beta</span>]} |
81 |
| - </Popup>, |
82 |
| - ); |
83 |
| - const tooltip = getByRole('tooltip'); |
84 |
| - const hiddenTextContainer = tooltip.querySelector('div > div'); |
85 |
| - |
86 |
| - // "Alpha Beta" |
87 |
| - expect(hiddenTextContainer.textContent).toBe('Alpha Beta'); |
88 |
| - }); |
89 |
| - |
90 |
| - it('should handle function returning undefined', () => { |
91 |
| - const { getByRole } = render( |
92 |
| - <Popup prefixCls="test" id="popup-func-undefined"> |
93 |
| - {() => undefined} |
94 |
| - </Popup>, |
95 |
| - ); |
96 |
| - const tooltip = getByRole('tooltip'); |
97 |
| - |
98 |
| - expect(tooltip.querySelector('div > div')).toBeNull(); |
99 |
| - }); |
100 | 8 | });
|
0 commit comments