Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
5c21b990
Commit
5c21b990
authored
Feb 07, 2018
by
jim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit testing to increase breadcrumbs
parent
f388d925
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
6 deletions
+83
-6
src/components/PageHeader/index.js
src/components/PageHeader/index.js
+12
-6
src/components/PageHeader/index.test.js
src/components/PageHeader/index.test.js
+71
-0
No files found.
src/components/PageHeader/index.js
View file @
5c21b990
...
...
@@ -7,8 +7,7 @@ import styles from './index.less';
const
{
TabPane
}
=
Tabs
;
function
getBreadcrumb
(
breadcrumbNameMap
,
url
)
{
export
function
getBreadcrumb
(
breadcrumbNameMap
,
url
)
{
let
breadcrumb
=
breadcrumbNameMap
[
url
];
if
(
!
breadcrumb
)
{
Object
.
keys
(
breadcrumbNameMap
).
forEach
((
item
)
=>
{
...
...
@@ -20,6 +19,14 @@ function getBreadcrumb(breadcrumbNameMap, url) {
return
breadcrumb
||
{};
}
// /userinfo/2144/id => ['/userinfo','/useinfo/2144,'/userindo/2144/id']
export
function
urlToList
(
url
)
{
const
urllist
=
url
.
split
(
'
/
'
).
filter
(
i
=>
i
);
return
urllist
.
map
((
urlItem
,
index
)
=>
{
return
`/
${
urllist
.
slice
(
0
,
index
+
1
).
join
(
'
/
'
)}
`
;
});
}
export
default
class
PageHeader
extends
PureComponent
{
static
contextTypes
=
{
routes
:
PropTypes
.
array
,
...
...
@@ -62,11 +69,10 @@ export default class PageHeader extends PureComponent {
}
conversionFromLocation
=
(
routerLocation
,
breadcrumbNameMap
)
=>
{
const
{
breadcrumbSeparator
,
linkElement
=
'
a
'
}
=
this
.
props
;
// Convert the
path
to an array
const
pathSnippets
=
routerLocation
.
pathname
.
split
(
'
/
'
).
filter
(
i
=>
i
);
// Convert the
url
to an array
const
pathSnippets
=
urlToList
(
routerLocation
.
pathname
);
// Loop data mosaic routing
const
extraBreadcrumbItems
=
pathSnippets
.
map
((
_
,
index
)
=>
{
const
url
=
`/
${
pathSnippets
.
slice
(
0
,
index
+
1
).
join
(
'
/
'
)}
`
;
const
extraBreadcrumbItems
=
pathSnippets
.
map
((
url
,
index
)
=>
{
const
currentBreadcrumb
=
getBreadcrumb
(
breadcrumbNameMap
,
url
);
const
isLinkable
=
(
index
!==
pathSnippets
.
length
-
1
)
&&
currentBreadcrumb
.
component
;
return
currentBreadcrumb
.
name
&&
!
currentBreadcrumb
.
hideInBreadcrumb
?
(
...
...
src/components/PageHeader/index.test.js
0 → 100644
View file @
5c21b990
import
{
getBreadcrumb
,
urlToList
}
from
'
./index
'
;
describe
(
'
test urlToList
'
,
()
=>
{
it
(
'
A path
'
,
()
=>
{
expect
(
urlToList
(
'
/userinfo
'
)).
toEqual
([
'
/userinfo
'
]);
});
it
(
'
Secondary path
'
,
()
=>
{
expect
(
urlToList
(
'
/userinfo/2144
'
)).
toEqual
([
'
/userinfo
'
,
'
/userinfo/2144
'
,
]);
});
it
(
'
Three paths
'
,
()
=>
{
expect
(
urlToList
(
'
/userinfo/2144/addr
'
)).
toEqual
([
'
/userinfo
'
,
'
/userinfo/2144
'
,
'
/userinfo/2144/addr
'
,
]);
});
});
const
routerData
=
{
'
/dashboard/analysis
'
:
{
name
:
'
分析页
'
,
},
'
/userinfo
'
:
{
name
:
'
用户列表
'
,
},
'
/userinfo/:id
'
:
{
name
:
'
用户信息
'
,
},
'
/userinfo/:id/addr
'
:
{
name
:
'
收货订单
'
,
},
};
describe
(
'
test getBreadcrumb
'
,
()
=>
{
it
(
'
Simple url
'
,
()
=>
{
expect
(
getBreadcrumb
(
routerData
,
'
/dashboard/analysis
'
).
name
).
toEqual
(
'
分析页
'
);
});
it
(
'
Parameters url
'
,
()
=>
{
expect
(
getBreadcrumb
(
routerData
,
'
/userinfo/2144
'
).
name
).
toEqual
(
'
用户信息
'
);
});
it
(
'
The middle parameter url
'
,
()
=>
{
expect
(
getBreadcrumb
(
routerData
,
'
/userinfo/2144/addr
'
).
name
).
toEqual
(
'
收货订单
'
);
});
it
(
'
Loop through the parameters
'
,
()
=>
{
const
urlNameList
=
urlToList
(
'
/userinfo/2144/addr
'
).
map
((
url
)
=>
{
return
getBreadcrumb
(
routerData
,
url
).
name
;
});
expect
(
urlNameList
).
toEqual
([
'
用户列表
'
,
'
用户信息
'
,
'
收货订单
'
]);
});
it
(
'
a path
'
,
()
=>
{
const
urlNameList
=
urlToList
(
'
/userinfo
'
).
map
((
url
)
=>
{
return
getBreadcrumb
(
routerData
,
url
).
name
;
});
expect
(
urlNameList
).
toEqual
([
'
用户列表
'
]);
});
it
(
'
Secondary path
'
,
()
=>
{
const
urlNameList
=
urlToList
(
'
/userinfo/2144
'
).
map
((
url
)
=>
{
return
getBreadcrumb
(
routerData
,
url
).
name
;
});
expect
(
urlNameList
).
toEqual
([
'
用户列表
'
,
'
用户信息
'
]);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment