From e86492d249f64146ab35baa48b276347a268479d Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 19 Jun 2021 22:47:28 +0800 Subject: [PATCH] test: update page-header test --- components/_util/props-util/index.js | 4 ++++ .../__snapshots__/index.test.js.snap | 21 ++++++++++++------- components/page-header/index.tsx | 9 +++++--- package.json | 1 + tests/setup.js | 2 ++ 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/components/_util/props-util/index.js b/components/_util/props-util/index.js index 018122270..2ecdecf1f 100644 --- a/components/_util/props-util/index.js +++ b/components/_util/props-util/index.js @@ -333,6 +333,10 @@ export function isFragment(c) { return c.length === 1 && c[0].type === Fragment; } +export function isEmptyContent(c) { + return c === undefined || c === null || c === '' || (Array.isArray(c) && c.length === 0); +} + export function isEmptyElement(c) { return ( c.type === Comment || diff --git a/components/page-header/__tests__/__snapshots__/index.test.js.snap b/components/page-header/__tests__/__snapshots__/index.test.js.snap index 91b27ef83..2f0447bd8 100644 --- a/components/page-header/__tests__/__snapshots__/index.test.js.snap +++ b/components/page-header/__tests__/__snapshots__/index.test.js.snap @@ -19,15 +19,20 @@ exports[`PageHeader pageHeader should support class 1`] = `
- - - - Page Title - - - + + + + Page Title + + + +
diff --git a/components/page-header/index.tsx b/components/page-header/index.tsx index 9411b566e..98ab2f2cc 100644 --- a/components/page-header/index.tsx +++ b/components/page-header/index.tsx @@ -1,6 +1,6 @@ import { defineComponent, ExtractPropTypes, ref, computed } from 'vue'; import PropTypes from '../_util/vue-types'; -import { flattenChildren } from '../_util/props-util'; +import { filterEmpty, flattenChildren, isEmptyContent } from '../_util/props-util'; import ArrowLeftOutlined from '@ant-design/icons-vue/ArrowLeftOutlined'; import ArrowRightOutlined from '@ant-design/icons-vue/ArrowRightOutlined'; import Breadcrumb from '../breadcrumb'; @@ -39,7 +39,7 @@ const PageHeader = defineComponent({ const onResize = ({ width }: { width: number }) => { compact.value = width < 768; }; - const ghost = computed(() => props.ghost ?? pageHeader.value?.ghost ?? false); + const ghost = computed(() => props.ghost ?? pageHeader.value?.ghost ?? true); const getBackIcon = () => { return ( @@ -123,7 +123,10 @@ const PageHeader = defineComponent({ }; const renderFooter = () => { - return
{props.footer ?? slots.footer?.()}
; + const footer = props.footer ?? filterEmpty(slots.footer?.()); + return isEmptyContent(footer) ? null : ( +
{footer}
+ ); }; const renderChildren = (children: any) => { diff --git a/package.json b/package.json index adaf2a6ba..07bd5fb9a 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,7 @@ "querystring": "^0.2.0", "raw-loader": "^4.0.2", "reqwest": "^2.0.5", + "resize-observer-polyfill": "^1.5.1", "rimraf": "^3.0.0", "rucksack-css": "^1.0.2", "selenium-server": "^3.0.1", diff --git a/tests/setup.js b/tests/setup.js index c2ba6f9d3..3c28118dd 100644 --- a/tests/setup.js +++ b/tests/setup.js @@ -23,6 +23,8 @@ if (typeof window !== 'undefined') { } } +global.ResizeObserver = require('resize-observer-polyfill'); + // The built-in requestAnimationFrame and cancelAnimationFrame not working with jest.runFakeTimes() // https://github.com/facebook/jest/issues/5147 global.requestAnimationFrame = function(cb) {