Browse Source

Merge branch 'master' into next-merge-master

pull/38016/head
MadCcc 2 years ago
parent
commit
1c16888d43
  1. 23
      components/_util/__tests__/reactNode.test.tsx
  2. 30
      components/affix/__tests__/Affix.test.tsx
  3. 6
      components/affix/utils.ts
  4. 2
      components/breadcrumb/Breadcrumb.tsx
  5. 4
      components/breadcrumb/BreadcrumbItem.tsx
  6. 11
      components/breadcrumb/__tests__/Breadcrumb.test.tsx
  7. 33
      components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap

23
components/_util/__tests__/reactNode.test.tsx

@ -0,0 +1,23 @@
import React from 'react';
import { isValidElement, cloneElement, isFragment, replaceElement } from '../reactNode';
describe('reactNode test', () => {
it('isValidElement', () => {
expect(isValidElement(null)).toBe(false);
expect(isValidElement(<p>test</p>)).toBe(true);
});
it('isFragment', () => {
expect(isFragment(<p>test</p>)).toBe(false);
expect(isFragment(<>test</>)).toBe(true);
});
it('replaceElement', () => {
const node = <p>test</p>;
expect(replaceElement(null, node)).toBe(node);
expect(replaceElement(node, node)).toStrictEqual(node);
});
it('cloneElement', () => {
const node = <p>test</p>;
expect(cloneElement(null)).toBe(null);
expect(cloneElement(node)).toStrictEqual(node);
});
});

30
components/affix/__tests__/Affix.test.tsx

@ -1,11 +1,11 @@
import React from 'react';
import type { AffixProps, InternalAffixClass } from '..';
import type { InternalAffixClass } from '..';
import Affix from '..';
import accessibilityTest from '../../../tests/shared/accessibilityTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render, triggerResize, waitFakeTimer } from '../../../tests/utils';
import Button from '../../button';
import { getObserverEntities } from '../utils';
import { addObserveTarget, getObserverEntities } from '../utils';
const events: Partial<Record<keyof HTMLElementEventMap, (ev: Partial<Event>) => void>> = {};
@ -120,9 +120,8 @@ describe('Affix Render', () => {
});
it('Anchor correct render when target is null', async () => {
expect(() => {
render(<Affix target={null as unknown as AffixProps['target']}>test</Affix>);
}).not.toThrow();
render(<Affix target={() => null}>test</Affix>);
await waitFakeTimer();
});
it('support offsetBottom', async () => {
@ -202,6 +201,21 @@ describe('Affix Render', () => {
expect(getObserverEntities()).toHaveLength(1);
expect(getObserverEntities()[0].target).toBe(window);
});
it('check position change before measure', async () => {
const { container } = render(
<>
<Affix offsetTop={10}>
<Button>top</Button>
</Affix>
<Affix offsetBottom={10}>
<Button>bottom</Button>
</Affix>
</>,
);
await waitFakeTimer();
await movePlaceholder(1000);
expect(container.querySelector('.ant-affix')).toBeTruthy();
});
});
describe('updatePosition when size changed', () => {
@ -248,5 +262,11 @@ describe('Affix Render', () => {
expect(updateCalled).toHaveBeenCalled();
});
});
it('addObserveTarget should not Throw Error when target is null', () => {
expect(() => {
addObserveTarget(null);
}).not.toThrow();
});
});
});

6
components/affix/utils.ts

@ -51,8 +51,10 @@ export function getObserverEntities() {
return observerEntities;
}
export function addObserveTarget<T>(target: HTMLElement | Window | null, affix: T): void {
if (!target) return;
export function addObserveTarget<T>(target: HTMLElement | Window | null, affix?: T): void {
if (!target) {
return;
}
let entity: ObserverEntity | undefined = observerEntities.find(item => item.target === target);

2
components/breadcrumb/Breadcrumb.tsx

@ -85,7 +85,7 @@ const Breadcrumb: BreadcrumbInterface = ({
}) => {
const { getPrefixCls, direction } = React.useContext(ConfigContext);
let crumbs;
let crumbs: React.ReactNode;
const prefixCls = getPrefixCls('breadcrumb', customizePrefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls);

4
components/breadcrumb/BreadcrumbItem.tsx

@ -43,7 +43,7 @@ const BreadcrumbItem: BreadcrumbItemInterface = ({
return breadcrumbItem;
};
let link;
let link: React.ReactNode;
if ('href' in restProps) {
link = (
<a className={`${prefixCls}-link`} {...restProps}>
@ -60,7 +60,7 @@ const BreadcrumbItem: BreadcrumbItemInterface = ({
// wrap to dropDown
link = renderBreadcrumbNode(link);
if (children) {
if (children !== undefined && children !== null) {
return (
<li>
{link}

11
components/breadcrumb/__tests__/Breadcrumb.test.tsx

@ -157,4 +157,15 @@ describe('Breadcrumb', () => {
);
expect(asFragment().firstChild).toMatchSnapshot();
});
it('should support string `0` and number `0`', () => {
const { container } = render(
<Breadcrumb>
<Breadcrumb.Item>{0}</Breadcrumb.Item>
<Breadcrumb.Item>0</Breadcrumb.Item>
</Breadcrumb>,
);
expect(container.querySelectorAll('.ant-breadcrumb-link')[0].textContent).toBe('0');
expect(container.querySelectorAll('.ant-breadcrumb-link')[1].textContent).toBe('0');
expect(container.firstChild).toMatchSnapshot();
});
});

33
components/breadcrumb/__tests__/__snapshots__/Breadcrumb.test.tsx.snap

@ -323,3 +323,36 @@ exports[`Breadcrumb should support custom attribute 1`] = `
</ol>
</nav>
`;
exports[`Breadcrumb should support string \`0\` and number \`0\` 1`] = `
<nav
class="ant-breadcrumb"
>
<ol>
<li>
<span
class="ant-breadcrumb-link"
>
0
</span>
<span
class="ant-breadcrumb-separator"
>
/
</span>
</li>
<li>
<span
class="ant-breadcrumb-link"
>
0
</span>
<span
class="ant-breadcrumb-separator"
>
/
</span>
</li>
</ol>
</nav>
`;

Loading…
Cancel
Save