From c5a275d6570e796858b8403cfab8ed0924b86917 Mon Sep 17 00:00:00 2001 From: * <8> Date: Tue, 13 Sep 2022 16:29:26 +0800 Subject: [PATCH] Match-id-cf2539a89122b0c25a798cf4990d143902cb20dd --- .../ComponentTest/PortalComponent.test.js | 42 +++++++++++++++++++ .../__tests__/utils/dispatchChangeEvent.js | 9 ++++ 2 files changed, 51 insertions(+) create mode 100644 scripts/__tests__/utils/dispatchChangeEvent.js diff --git a/scripts/__tests__/ComponentTest/PortalComponent.test.js b/scripts/__tests__/ComponentTest/PortalComponent.test.js index 05908f18..5743093d 100755 --- a/scripts/__tests__/ComponentTest/PortalComponent.test.js +++ b/scripts/__tests__/ComponentTest/PortalComponent.test.js @@ -1,5 +1,6 @@ import * as Horizon from '@cloudsop/horizon/index.ts'; import { getLogUtils } from '../jest/testUtils'; +import dispatchChangeEvent from '../utils/dispatchChangeEvent'; describe('PortalComponent Test', () => { const LogUtils = getLogUtils(); @@ -235,4 +236,45 @@ describe('PortalComponent Test', () => { btnRef.current.click(); expect(onClick).toHaveBeenCalledTimes(1); }); + + it('Portal onChange should activate', () => { + class Dialog extends Horizon.Component { + node; + + constructor(props) { + super(props); + this.node = window.document.createElement('div'); + window.document.body.appendChild(this.node); + } +`` render() { + return Horizon.createPortal(this.props.children, this.node); + } + } + + let showPortalInput; + const fn = jest.fn(); + const inputRef = Horizon.createRef(); + function Input() { + const [show, setShow] = Horizon.useState(false); + showPortalInput = setShow; + + Horizon.useEffect(() => { + setTimeout(() => { + setShow(true); + }, 0); + }, []); + + if (!show) { + return null; + } + + return ; + } + + Horizon.render(