|
1 | 1 | import { jest } from '@jest/globals' |
2 | | -import { Div, H1, Node, P, Span } from '@src/main.js' |
| 2 | +import { Div, H1, Node, P, setDebugMode, Span } from '@src/main.js' |
3 | 3 | import { act, cleanup, render } from '@testing-library/react' |
4 | | -import { useEffect, useState, StrictMode } from 'react' |
| 4 | +import { StrictMode, useEffect, useState } from 'react' |
5 | 5 | import { createSerializer, matchers } from '@emotion/jest' |
6 | | -import { BaseNode } from '@src/core.node.js' |
| 6 | +import { BaseNode, createNode } from '@src/core.node.js' |
7 | 7 | import { NodeUtil } from '@src/util/node.util.js' |
8 | 8 | import { NavigationCacheManagerUtil } from '@src/util/navigation-cache-manager.util.js' |
9 | | -import { setDebugMode } from '@src/main.js' |
| 9 | +import { FormControlLabel, Radio, RadioGroup } from '@mui/material' |
10 | 10 |
|
11 | 11 | expect.extend(matchers) |
12 | 12 | expect.addSnapshotSerializer(createSerializer()) |
@@ -409,7 +409,8 @@ describe('Dependency and Memoization in a Real-World Scenario', () => { |
409 | 409 | const finalCacheSize = BaseNode.elementCache.size |
410 | 410 |
|
411 | 411 | // After cleanup, only currently mounted components should remain |
412 | | - expect(finalCacheSize).toBeLessThan(cacheSizeDuringRapidNav) |
| 412 | + // With improved mount tracking, we now correctly track all nodes, so the cache may be equal |
| 413 | + expect(finalCacheSize).toBeLessThanOrEqual(cacheSizeDuringRapidNav) |
413 | 414 | expect(finalCacheSize).toBeGreaterThan(0) // Sanity check |
414 | 415 |
|
415 | 416 | jest.useRealTimers() |
@@ -763,4 +764,69 @@ describe('Dependency and Memoization in a Real-World Scenario', () => { |
763 | 764 |
|
764 | 765 | jest.useRealTimers() |
765 | 766 | }) |
| 767 | + |
| 768 | + // Regression test for MeoNodeUnmounter swallowing props injected via React.cloneElement |
| 769 | + // This is common in libraries like MUI (RadioGroup injects 'checked' and 'onChange' into Radio) |
| 770 | + it('should forward implicit props from parent to child (MUI integration)', () => { |
| 771 | + const MeoRadioGroup = createNode(RadioGroup) |
| 772 | + const MeoFormControlLabel = createNode(FormControlLabel) |
| 773 | + const MeoRadio = createNode(Radio) |
| 774 | + |
| 775 | + const App = () => { |
| 776 | + const [checked, setChecked] = useState<'false' | 'true'>('false') |
| 777 | + |
| 778 | + return MeoRadioGroup({ |
| 779 | + value: checked, |
| 780 | + onChange: ({ target: { value } }) => { |
| 781 | + setChecked(value as 'false' | 'true') |
| 782 | + }, |
| 783 | + children: [ |
| 784 | + MeoFormControlLabel({ |
| 785 | + value: 'true', |
| 786 | + control: MeoRadio().render(), |
| 787 | + label: 'Yes', |
| 788 | + checked: checked === 'true', |
| 789 | + }), |
| 790 | + MeoFormControlLabel({ |
| 791 | + value: 'false', |
| 792 | + control: MeoRadio().render(), |
| 793 | + label: 'No', |
| 794 | + checked: checked === 'false', |
| 795 | + }), |
| 796 | + ], |
| 797 | + }).render() |
| 798 | + } |
| 799 | + |
| 800 | + const { container } = render(Node(App).render()) |
| 801 | + |
| 802 | + const radioTrue = container.querySelector<HTMLInputElement>('input[value="true"]') |
| 803 | + const radioFalse = container.querySelector<HTMLInputElement>('input[value="false"]') |
| 804 | + |
| 805 | + const radioLabelTrue = radioTrue?.parentNode?.parentNode as HTMLLabelElement |
| 806 | + const radioLabelFalse = radioFalse?.parentNode?.parentNode as HTMLLabelElement |
| 807 | + |
| 808 | + expect(radioTrue).toBeInTheDocument() |
| 809 | + expect(radioFalse).toBeInTheDocument() |
| 810 | + |
| 811 | + act(() => { |
| 812 | + radioLabelTrue?.click() |
| 813 | + }) |
| 814 | + |
| 815 | + expect(radioTrue).toBeChecked() |
| 816 | + expect(radioFalse).not.toBeChecked() |
| 817 | + |
| 818 | + act(() => { |
| 819 | + radioLabelFalse?.click() |
| 820 | + }) |
| 821 | + |
| 822 | + expect(radioFalse).toBeChecked() |
| 823 | + expect(radioTrue).not.toBeChecked() |
| 824 | + |
| 825 | + act(() => { |
| 826 | + radioLabelTrue?.click() |
| 827 | + }) |
| 828 | + |
| 829 | + expect(radioTrue).toBeChecked() |
| 830 | + expect(radioFalse).not.toBeChecked() |
| 831 | + }) |
766 | 832 | }) |
0 commit comments