From 620e90d078c44456e3cdfe550dc1d9c20c49e187 Mon Sep 17 00:00:00 2001 From: dengfuping Date: Wed, 27 Mar 2024 15:58:51 +0800 Subject: [PATCH] fix(design): Modal should hide footer dom when footer is false, to #522 --- packages/design/src/modal/Modal.tsx | 5 +- .../__snapshots__/modal.test.tsx.snap | 179 ++++++++++++++++++ .../design/src/modal/__tests__/modal.test.tsx | 38 ++++ 3 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 packages/design/src/modal/__tests__/__snapshots__/modal.test.tsx.snap create mode 100644 packages/design/src/modal/__tests__/modal.test.tsx diff --git a/packages/design/src/modal/Modal.tsx b/packages/design/src/modal/Modal.tsx index 5accf24a0..df651a5bf 100644 --- a/packages/design/src/modal/Modal.tsx +++ b/packages/design/src/modal/Modal.tsx @@ -6,7 +6,7 @@ import ConfigProvider from '../config-provider'; import { modal } from '../static-function'; import useStyle from './style'; -const Modal = ({ prefixCls: customizePrefixCls, className, ...restProps }: ModalProps) => { +const Modal = ({ footer, prefixCls: customizePrefixCls, className, ...restProps }: ModalProps) => { const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); const prefixCls = getPrefixCls('modal', customizePrefixCls); const { wrapSSR } = useStyle(prefixCls); @@ -15,6 +15,9 @@ const Modal = ({ prefixCls: customizePrefixCls, className, ...restProps }: Modal return wrapSSR( should hide footer dom when footer is false 1`] = ` +
+
+
+
+
+ +
+`; + +exports[`Modal > should hide footer dom when footer is null 1`] = ` +
+
+
+
+
+ +
+`; diff --git a/packages/design/src/modal/__tests__/modal.test.tsx b/packages/design/src/modal/__tests__/modal.test.tsx new file mode 100644 index 000000000..8e730d49f --- /dev/null +++ b/packages/design/src/modal/__tests__/modal.test.tsx @@ -0,0 +1,38 @@ +import React, { useEffect } from 'react'; +import { render } from '@testing-library/react'; +import { Modal } from '@oceanbase/design'; +import type { ModalProgressProps } from '@oceanbase/design/es/modal'; + +const ModalTest: React.FC = props => { + const [open, setOpen] = React.useState(false); + const container = React.useRef(null); + useEffect(() => { + setOpen(true); + }, []); + return ( +
+
+ +
+ ); +}; + +describe('Modal', () => { + it('should hide footer dom when footer is null', () => { + const { container, asFragment } = render(); + expect(container.querySelector('.ant-modal-footer')).toBeFalsy(); + expect(asFragment().firstChild).toMatchSnapshot(); + }); + + it('should hide footer dom when footer is false', () => { + const { container, asFragment } = render(); + expect(container.querySelector('.ant-modal-footer')).toBeFalsy(); + expect(asFragment().firstChild).toMatchSnapshot(); + }); +});