forked from mui/base-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuRadioItemIndicator.test.tsx
94 lines (83 loc) · 2.72 KB
/
MenuRadioItemIndicator.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as React from 'react';
import { Menu } from '@base-ui-components/react/menu';
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';
import { screen, waitFor } from '@mui/internal-test-utils';
import { expect } from 'chai';
describe('<Menu.RadioItemIndicator />', () => {
const { render } = createRenderer();
describeConformance(<Menu.RadioItemIndicator keepMounted />, () => ({
refInstanceof: window.HTMLSpanElement,
render(node) {
return render(
<Menu.Root open>
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>
<Menu.RadioGroup>
<Menu.RadioItem value="">{node}</Menu.RadioItem>
</Menu.RadioGroup>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>,
);
},
}));
it('should remove the indicator when the animation finishes', async ({ skip }) => {
if (isJSDOM) {
skip();
}
globalThis.BASE_UI_ANIMATIONS_DISABLED = false;
let animationFinished = false;
const notifyAnimationFinished = () => {
animationFinished = true;
};
function Test() {
const style = `
@keyframes test-anim {
to {
opacity: 0;
}
}
.animation-test-indicator[data-ending-style] {
animation: test-anim 50ms;
}
`;
const [value, setValue] = React.useState('a');
return (
<div>
{/* eslint-disable-next-line react/no-danger */}
<style dangerouslySetInnerHTML={{ __html: style }} />
<button onClick={() => setValue('b')}>Close</button>
<Menu.Root open modal={false}>
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>
<Menu.RadioGroup value={value}>
<Menu.RadioItem value="a">
<Menu.RadioItemIndicator
className="animation-test-indicator"
data-testid="indicator"
keepMounted
onAnimationEnd={notifyAnimationFinished}
/>
</Menu.RadioItem>
<Menu.RadioItem value="b">
<Menu.RadioItemIndicator keepMounted />
</Menu.RadioItem>
</Menu.RadioGroup>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
</div>
);
}
const { user } = await render(<Test />);
const closeButton = screen.getByText('Close');
await user.click(closeButton);
await waitFor(() => {
expect(animationFinished).to.equal(true);
});
});
});