Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
πŸ› bug: fix menuData no work error (#543)
Browse files Browse the repository at this point in the history
* πŸ› bug: fix menuData no work error

* add test

* fix tsc

* fix ts error

* fix ts
  • Loading branch information
chenshuai2144 authored Jul 8, 2020
1 parent aa723d5 commit 6c17d87
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"site_build": "dumi build",
"doc": "cd ./example && umi dev",
"test": "umi-test",
"tsc": "tsc"
"tsc": "tsc -p tsconfig-check.json"
},
"husky": {
"hooks": {
Expand Down
1 change: 1 addition & 0 deletions src/SiderMenu/BaseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ const BaseMenu: React.FC<BaseMenuProps> = (props) => {
);

useEffect(() => {
setPostMenuData(menuData);
if (menu.defaultOpenAll || propsOpenKeys === false || flatMenuKeys.length) {
return;
}
Expand Down
228 changes: 227 additions & 1 deletion tests/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,232 @@ exports[`BasicLayout πŸ₯© contentStyle should change dom 1`] = `
</div>
`;

exports[`BasicLayout πŸ₯© menuDataRender change date 1`] = `
<div
class="ant-design-pro ant-pro-basicLayout screen-md"
>
<section
class="ant-layout ant-layout-has-sider"
style="min-height: 100%;"
>
<aside
class="ant-pro-sider ant-pro-sider-layout-side ant-layout-sider ant-layout-sider-dark"
style="overflow: hidden; flex: 0 0 208px; max-width: 208px; min-width: 208px; width: 208px;"
>
<div
class="ant-layout-sider-children"
>
<div
class="ant-pro-sider-logo"
id="logo"
>
<a>
<img
alt="logo"
src="https://gw.alipayobjects.com/zos/antfincdn/PmY%24TNNDBI/logo.svg"
/>
<h1>
Ant Design Pro
</h1>
</a>
</div>
<div
style="flex: 1; overflow-y: auto; overflow-x: hidden;"
>
<ul
class="ant-menu ant-pro-sider-menu ant-menu-dark ant-menu-root ant-menu-inline"
role="menu"
style="width: 100%;"
/>
</div>
<div
class="ant-pro-sider-links"
>
<ul
class="ant-menu ant-pro-sider-link-menu ant-menu-dark ant-menu-root ant-menu-inline"
role="menu"
>
<li
class="ant-menu-item ant-pro-sider-collapsed-button ant-menu-item-only-child"
role="menuitem"
style="padding-left: 16px;"
>
<span
aria-label="menu-fold"
class="anticon anticon-menu-fold"
role="img"
>
<svg
aria-hidden="true"
class=""
data-icon="menu-fold"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 000 13.8z"
/>
</svg>
</span>
</li>
</ul>
</div>
</div>
</aside>
<section
class="ant-layout"
style="position: relative;"
>
<header
class="ant-layout-header"
style="padding: 0px; height: 48px; line-height: 48px; width: 100%; z-index: 9;"
>
<div
class="ant-pro-global-header ant-pro-global-header-layout-side"
>
<div
style="flex: 1;"
/>
</div>
</header>
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
</section>
</section>
</div>
`;

exports[`BasicLayout πŸ₯© menuDataRender change date 2`] = `
<div
class="ant-design-pro ant-pro-basicLayout screen-md"
>
<section
class="ant-layout ant-layout-has-sider"
style="min-height: 100%;"
>
<aside
class="ant-pro-sider ant-pro-sider-layout-side ant-layout-sider ant-layout-sider-dark"
style="overflow: hidden; flex: 0 0 208px; max-width: 208px; min-width: 208px; width: 208px;"
>
<div
class="ant-layout-sider-children"
>
<div
class="ant-pro-sider-logo"
id="logo"
>
<a>
<img
alt="logo"
src="https://gw.alipayobjects.com/zos/antfincdn/PmY%24TNNDBI/logo.svg"
/>
<h1>
Ant Design Pro
</h1>
</a>
</div>
<div
style="flex: 1; overflow-y: auto; overflow-x: hidden;"
>
<ul
class="ant-menu ant-pro-sider-menu ant-menu-dark ant-menu-root ant-menu-inline"
role="menu"
style="width: 100%;"
>
<li
class="ant-menu-submenu ant-menu-submenu-inline"
role="menuitem"
>
<div
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
role="button"
style="padding-left: 16px;"
title="ι¦–ι‘΅"
>
ι¦–ι‘΅
<i
class="ant-menu-submenu-arrow"
/>
</div>
<div />
</li>
</ul>
</div>
<div
class="ant-pro-sider-links"
>
<ul
class="ant-menu ant-pro-sider-link-menu ant-menu-dark ant-menu-root ant-menu-inline"
role="menu"
>
<li
class="ant-menu-item ant-pro-sider-collapsed-button ant-menu-item-only-child"
role="menuitem"
style="padding-left: 16px;"
>
<span
aria-label="menu-fold"
class="anticon anticon-menu-fold"
role="img"
>
<svg
aria-hidden="true"
class=""
data-icon="menu-fold"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 000 13.8z"
/>
</svg>
</span>
</li>
</ul>
</div>
</div>
</aside>
<section
class="ant-layout"
style="position: relative;"
>
<header
class="ant-layout-header"
style="padding: 0px; height: 48px; line-height: 48px; width: 100%; z-index: 9;"
>
<div
class="ant-pro-global-header ant-pro-global-header-layout-side"
>
<div
style="flex: 1;"
/>
</div>
</header>
<main
class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header"
>
<div
class="ant-pro-basicLayout-children-content-wrap"
/>
</main>
</section>
</section>
</div>
`;

exports[`BasicLayout πŸ₯© support loading 1`] = `
<div
class="ant-design-pro ant-pro-basicLayout screen-md"
Expand Down Expand Up @@ -335,7 +561,7 @@ exports[`BasicLayout πŸ₯© support loading 1`] = `
</div>
`;

exports[`BasicLayout πŸ₯© support menuDateRender 1`] = `
exports[`BasicLayout πŸ₯© support menuDataRender 1`] = `
<div
class="ant-design-pro ant-pro-basicLayout screen-md"
>
Expand Down
32 changes: 31 additions & 1 deletion tests/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('BasicLayout', () => {
wrapper.unmount();
});

it('πŸ₯© support menuDateRender', async () => {
it('πŸ₯© support menuDataRender', async () => {
const wrapper = mount(
<BasicLayout
menuDataRender={() =>
Expand Down Expand Up @@ -222,6 +222,36 @@ describe('BasicLayout', () => {
wrapper.unmount();
});

it('πŸ₯© menuDataRender change date', async () => {
const wrapper = mount(<BasicLayout menuDataRender={() => []} />);
await waitForComponentToPaint(wrapper);

expect(wrapper.render()).toMatchSnapshot();

wrapper.setProps({
menuDataRender: () => [
{
path: '/home',
name: 'ι¦–ι‘΅',
children: [
{
path: '/home/overview',
name: '概述',
exact: true,
},
{
path: '/home/search',
name: '搜紒',
exact: true,
},
],
},
],
});
await waitForComponentToPaint(wrapper);
expect(wrapper.render()).toMatchSnapshot();
});

it('πŸ₯© use onLogoClick', async () => {
const onLogoClick = jest.fn();
const wrapper = mount(
Expand Down
25 changes: 25 additions & 0 deletions tsconfig-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"outDir": "build/dist",
"module": "esnext",
"target": "ES2015",
"lib": ["esnext", "dom"],
"sourceMap": true,
"baseUrl": ".",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"strict": true,
"declaration": true,
"skipLibCheck": true,
"paths": {
"@ant-design/pro-layout": ["./src"]
}
},
"include": ["src/"]
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@ant-design/pro-layout": ["./src"]
}
},
"include": ["**/src/", "**/docs/"],
"include": ["**/src/", "**/docs/", "**/tests/"],
"exclude": [
"node_modules",
"build",
Expand All @@ -32,7 +32,6 @@
"tslint:latest",
"tslint-config-prettier",
"example",
"**/tests/",
"**/docs/"
]
}

0 comments on commit 6c17d87

Please sign in to comment.