test: update page-header test

refactor-list
tangjinzhou 2021-06-19 22:47:28 +08:00
parent edcc8b7107
commit e86492d249
5 changed files with 26 additions and 11 deletions

View File

@ -333,6 +333,10 @@ export function isFragment(c) {
return c.length === 1 && c[0].type === Fragment; 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) { export function isEmptyElement(c) {
return ( return (
c.type === Comment || c.type === Comment ||

View File

@ -18,16 +18,21 @@ exports[`PageHeader pageHeader should support class 1`] = `
<!----> <!---->
<div <div
class="ant-page-header-heading" class="ant-page-header-heading"
>
<div
class="ant-page-header-heading-left"
> >
<!----> <!---->
<!----> <!---->
<span <span
class="ant-page-header-heading-title" class="ant-page-header-heading-title"
title="Page Title"
> >
Page Title Page Title
</span> </span>
<!----> <!---->
<!----> <!---->
</div>
<!----> <!---->
</div> </div>
<!----> <!---->

View File

@ -1,6 +1,6 @@
import { defineComponent, ExtractPropTypes, ref, computed } from 'vue'; import { defineComponent, ExtractPropTypes, ref, computed } from 'vue';
import PropTypes from '../_util/vue-types'; 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 ArrowLeftOutlined from '@ant-design/icons-vue/ArrowLeftOutlined';
import ArrowRightOutlined from '@ant-design/icons-vue/ArrowRightOutlined'; import ArrowRightOutlined from '@ant-design/icons-vue/ArrowRightOutlined';
import Breadcrumb from '../breadcrumb'; import Breadcrumb from '../breadcrumb';
@ -39,7 +39,7 @@ const PageHeader = defineComponent({
const onResize = ({ width }: { width: number }) => { const onResize = ({ width }: { width: number }) => {
compact.value = width < 768; compact.value = width < 768;
}; };
const ghost = computed(() => props.ghost ?? pageHeader.value?.ghost ?? false); const ghost = computed(() => props.ghost ?? pageHeader.value?.ghost ?? true);
const getBackIcon = () => { const getBackIcon = () => {
return ( return (
@ -123,7 +123,10 @@ const PageHeader = defineComponent({
}; };
const renderFooter = () => { const renderFooter = () => {
return <div class={`${prefixCls.value}-footer`}>{props.footer ?? slots.footer?.()}</div>; const footer = props.footer ?? filterEmpty(slots.footer?.());
return isEmptyContent(footer) ? null : (
<div class={`${prefixCls.value}-footer`}>{footer}</div>
);
}; };
const renderChildren = (children: any) => { const renderChildren = (children: any) => {

View File

@ -160,6 +160,7 @@
"querystring": "^0.2.0", "querystring": "^0.2.0",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"reqwest": "^2.0.5", "reqwest": "^2.0.5",
"resize-observer-polyfill": "^1.5.1",
"rimraf": "^3.0.0", "rimraf": "^3.0.0",
"rucksack-css": "^1.0.2", "rucksack-css": "^1.0.2",
"selenium-server": "^3.0.1", "selenium-server": "^3.0.1",

View File

@ -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() // The built-in requestAnimationFrame and cancelAnimationFrame not working with jest.runFakeTimes()
// https://github.com/facebook/jest/issues/5147 // https://github.com/facebook/jest/issues/5147
global.requestAnimationFrame = function(cb) { global.requestAnimationFrame = function(cb) {