Skip to content

Commit 113a7f3

Browse files
committed
test: add route stories
1 parent 7b1813e commit 113a7f3

File tree

7 files changed

+138
-107
lines changed

7 files changed

+138
-107
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"to-string-loader": "1.1.5",
4646
"gulp": "3.9.1",
4747
"gulp-typescript": "3",
48-
"react-syntax-highlighter": "^6.1.2",
4948
"@types/node": "9.3.0",
5049
"@types/jest": "22.0.1",
5150
"@types/chai": "4.1.1",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {createElement as h} from 'react';
2+
import {LocationSensor} from '../../LocationSensor';
3+
import {Router, Route} from '..';
4+
5+
const StoryRouteExample = () => (
6+
<Router>
7+
<div>
8+
<ul>
9+
<li onClick={() => history.pushState(null, '', '/home.html')}>Home</li>
10+
<li onClick={() => history.pushState(null, '', '/home/intro.html')}>Home / Intro</li>
11+
<li onClick={() => history.pushState(null, '', '/home/more.html')}>Home / More</li>
12+
<li onClick={() => history.pushState(null, '', '/page.html')}>Page</li>
13+
<li onClick={() => history.pushState(null, '', '/404.html')}>404</li>
14+
</ul>
15+
16+
<Route match='/home'>{() =>
17+
<div>
18+
<div>HOME</div>
19+
<Route match='/intro' children={<div>INTRO</div>} />
20+
<Route children={<div>HOME/404</div>} />
21+
</div>
22+
}</Route>
23+
<Route match={/^\/page\.html/} children={<div>PAGE</div>} />
24+
<Route children={<div>404</div>} />
25+
26+
<br />
27+
<hr />
28+
29+
<LocationSensor>{(state) =>
30+
<pre style={{fontFamily: 'monospace'}}>
31+
{JSON.stringify(state, null, 4)}
32+
</pre>
33+
}</LocationSensor>
34+
35+
<br />
36+
<hr />
37+
38+
<pre style={{fontFamily: 'monospace'}}>{`
39+
<Route match='/home'>{() =>
40+
<div>
41+
<div>HOME</div>
42+
<Route match='/intro' children={<div>INTRO</div>} />
43+
<Route children={<div>HOME/404</div>} />
44+
</div>
45+
}</Route>
46+
<Route match={/^\/page\.html/} children={<div>PAGE</div>} />
47+
<Route children={<div>404</div>} />
48+
`}</pre>
49+
</div>
50+
</Router>
51+
);
52+
53+
export default StoryRouteExample;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {createElement as h} from 'react';
2+
import {LocationSensor} from '../../LocationSensor';
3+
import {Router, Route} from '..';
4+
5+
const StoryRoutePreserveRoute = () =>
6+
<div>
7+
<Router route='/api/users/id/123'>
8+
<Route preserve match='/api'>
9+
<Route preserve match='/api/users'>
10+
<Route preserve match='/api/users/id'>
11+
<Route preserve match={/\/api\/users\/id\/(.*)/}>{(result) =>
12+
<pre style={{fontFamily: 'monospace'}}>{JSON.stringify(result, null, 4)}</pre>
13+
}</Route>
14+
</Route>
15+
</Route>
16+
</Route>
17+
</Router>
18+
19+
<hr />
20+
21+
<pre style={{fontFamily: 'monospace'}}>{`
22+
<Router route='/api/users/id/123'>
23+
<Route preserve match='/api'>
24+
<Route preserve match='/api/users'>
25+
<Route preserve match='/api/users/id'>
26+
<Route preserve match={/\/api\/users\/id\/(.*)/}>{(result) =>
27+
<pre style={{fontFamily: 'monospace'}}>{JSON.stringify(result, null, 4)}</pre>
28+
}</Route>
29+
</Route>
30+
</Route>
31+
</Route>
32+
</Router>
33+
`}</pre>
34+
</div>;
35+
36+
export default StoryRoutePreserveRoute;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {createElement as h} from 'react';
2+
import {LocationSensor} from '../../LocationSensor';
3+
import {Router, Route} from '..';
4+
5+
const StoryRouteTruncateRoute = () =>
6+
<div>
7+
<Router route='/api/users/43f23f-23f34f43r.json'>
8+
<Route match='/api'>
9+
<Route match='/users'>
10+
<Route match={/.*/}>{(result) =>
11+
<pre style={{fontFamily: 'monospace'}}>{JSON.stringify(result, null, 4)}</pre>
12+
}</Route>
13+
</Route>
14+
</Route>
15+
</Router>
16+
17+
<hr />
18+
19+
<pre style={{fontFamily: 'monospace'}}>{`
20+
<Router route='/api/users/43f23f-23f34f43r.json'>
21+
<Route match='/api'>
22+
<Route match='/users'>
23+
<Route match={/.*/}>{(result) =>
24+
<pre style={{fontFamily: 'monospace'}}>{JSON.stringify(result, null, 4)}</pre>
25+
}</Route>
26+
</Route>
27+
</Route>
28+
</Router>
29+
`}</pre>
30+
</div>;
31+
32+
export default StoryRouteTruncateRoute;

src/route/__story__/story.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {createElement as h} from 'react';
2+
import {storiesOf} from '@storybook/react';
3+
import {action} from '@storybook/addon-actions';
4+
import {linkTo} from '@storybook/addon-links';
5+
import {LocationSensor} from '../../LocationSensor';
6+
import {Router, Route} from '..';
7+
import ShowDocs from '../../../.storybook/ShowDocs'
8+
import StoryRouteExample from './StoryRouteExample';
9+
import StoryRouteTruncateRoute from './StoryRouteTruncateRoute';
10+
import StoryRoutePreserveRoute from './StoryRoutePreserveRoute';
11+
12+
storiesOf('Context/route', module)
13+
.add('Documentation', () => h(ShowDocs, {name: 'route'}))
14+
.add('Example', () => h(StoryRouteExample))
15+
.add('Truncates route', () => h(StoryRouteTruncateRoute))
16+
.add('Preserve route', () => h(StoryRoutePreserveRoute));

src/route/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Router extends Component<IRouteProviderProps, any> {
4848

4949
export interface TRouteMatchResult {
5050
length: number; // Length how many characters to truncate from route.
51-
matches?: RegExpMatchArray;
51+
matches?: RegExpMatchArray; // RegExp matches, if any.
5252
}
5353

5454
export type TRouteMatcher = (route: string) => TRouteMatchResult;

src/route/story.tsx

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)