@common-stack/client-react 0.5.29 → 0.5.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__tests__/fill-register-test.js +6 -31
- package/lib/__tests__/fill-register-test.js.map +1 -1
- package/lib/__tests__/helpers/sample-menu.js +1 -4
- package/lib/__tests__/helpers/sample-menu.js.map +1 -1
- package/lib/__tests__/integrated-routes.test.js +14 -42
- package/lib/__tests__/integrated-routes.test.js.map +1 -1
- package/lib/__tests__/router-render.test.js +13 -57
- package/lib/__tests__/router-render.test.js.map +1 -1
- package/lib/connector/base-connector.js +24 -48
- package/lib/connector/base-connector.js.map +1 -1
- package/lib/connector/connector.d.ts +3 -2
- package/lib/connector/connector.js +9 -13
- package/lib/connector/connector.js.map +1 -1
- package/lib/connector/connector.native.js +10 -17
- package/lib/connector/connector.native.js.map +1 -1
- package/lib/connector/connector.test.js +5 -30
- package/lib/connector/connector.test.js.map +1 -1
- package/lib/connector/index.js +1 -17
- package/lib/connector/index.js.map +1 -1
- package/lib/index.js +10 -28
- package/lib/index.js.map +1 -1
- package/lib/index.native.js +10 -28
- package/lib/index.native.js.map +1 -1
- package/lib/interfaces/extended-feature.js +1 -2
- package/lib/interfaces/feature.js +1 -2
- package/lib/interfaces/index.js +5 -21
- package/lib/interfaces/index.js.map +1 -1
- package/lib/interfaces/menu.js +2 -5
- package/lib/interfaces/menu.js.map +1 -1
- package/lib/interfaces/new-router.d.ts +9 -3
- package/lib/interfaces/new-router.js +1 -2
- package/lib/interfaces/router.js +1 -2
- package/lib/inversify/InversifyContext.js +6 -34
- package/lib/inversify/InversifyContext.js.map +1 -1
- package/lib/inversify/index.js +1 -17
- package/lib/inversify/index.js.map +1 -1
- package/lib/plugin-area/__tests__/higher-order-component-util.test.js +12 -37
- package/lib/plugin-area/__tests__/higher-order-component-util.test.js.map +1 -1
- package/lib/plugin-area/__tests__/plugin-api.test.js +11 -13
- package/lib/plugin-area/__tests__/plugin-api.test.js.map +1 -1
- package/lib/plugin-area/base-plugin-area.js +12 -39
- package/lib/plugin-area/base-plugin-area.js.map +1 -1
- package/lib/plugin-area/higher-order-component-util.js +3 -7
- package/lib/plugin-area/higher-order-component-util.js.map +1 -1
- package/lib/plugin-area/index.js +5 -35
- package/lib/plugin-area/index.js.map +1 -1
- package/lib/plugin-area/index.native.js +7 -37
- package/lib/plugin-area/index.native.js.map +1 -1
- package/lib/plugin-area/plugin-api.js +15 -18
- package/lib/plugin-area/plugin-api.js.map +1 -1
- package/lib/plugin-area/plugin-context.js +5 -32
- package/lib/plugin-area/plugin-context.js.map +1 -1
- package/lib/route/__tests__/admin-new-routes.test.js +11 -45
- package/lib/route/__tests__/admin-new-routes.test.js.map +1 -1
- package/lib/route/__tests__/getFlatMenus.test.js +4 -6
- package/lib/route/__tests__/getFlatMenus.test.js.map +1 -1
- package/lib/route/__tests__/render-routes-config.test.js +6 -18
- package/lib/route/__tests__/render-routes-config.test.js.map +1 -1
- package/lib/route/__tests__/route-type.test.js +1 -2
- package/lib/route/__tests__/route-type.test.js.map +1 -1
- package/lib/route/get-routes.js +24 -31
- package/lib/route/get-routes.js.map +1 -1
- package/lib/route/get-routes.test.js +8 -19
- package/lib/route/get-routes.test.js.map +1 -1
- package/lib/route/index.js +2 -18
- package/lib/route/index.js.map +1 -1
- package/lib/route/index.native.d.ts +1 -1
- package/lib/route/index.native.js +1 -17
- package/lib/route/index.native.js.map +1 -1
- package/lib/route/old/__tests__/config-sidebar-menu.test.js +17 -15
- package/lib/route/old/__tests__/config-sidebar-menu.test.js.map +1 -1
- package/lib/route/old/get-menus.js +14 -21
- package/lib/route/old/get-menus.js.map +1 -1
- package/lib/route/old/get-routes-notused.js +15 -13
- package/lib/route/old/get-routes-notused.js.map +1 -1
- package/lib/route/old/render.d.ts +1 -1
- package/lib/route/old/render.js +7 -31
- package/lib/route/old/render.js.map +1 -1
- package/lib/route/react-navigation/get-navigation-utils.d.ts +8 -0
- package/lib/route/react-navigation/get-navigation-utils.js +35 -40
- package/lib/route/react-navigation/get-navigation-utils.js.map +1 -1
- package/lib/route/react-navigation/get-navigation-utils.test.js +15 -17
- package/lib/route/react-navigation/get-navigation-utils.test.js.map +1 -1
- package/lib/route/react-navigation/index.js +2 -18
- package/lib/route/react-navigation/index.js.map +1 -1
- package/lib/route/react-navigation/react-native.sample.test.js +8 -22
- package/lib/route/react-navigation/react-native.sample.test.js.map +1 -1
- package/lib/route/react-navigation/react-native.sample1.test.js +14 -48
- package/lib/route/react-navigation/react-native.sample1.test.js.map +1 -1
- package/lib/route/react-navigation/react-navigation-render.js +16 -31
- package/lib/route/react-navigation/react-navigation-render.js.map +1 -1
- package/lib/route/react-navigation/react-navigation-render.test.js +23 -37
- package/lib/route/react-navigation/react-navigation-render.test.js.map +1 -1
- package/lib/route/react-navigation/root-navigation.js +5 -9
- package/lib/route/react-navigation/root-navigation.js.map +1 -1
- package/lib/route/react-navigation/routes.js +1 -2
- package/lib/route/react-navigation/types.js +1 -5
- package/lib/route/react-navigation/types.js.map +1 -1
- package/lib/route/render-routes-native.d.ts +3 -0
- package/lib/route/render-routes-native.js +126 -0
- package/lib/route/render-routes-native.js.map +1 -0
- package/lib/route/render-routes.d.ts +1 -2
- package/lib/route/render-routes.js +132 -74
- package/lib/route/render-routes.js.map +1 -1
- package/lib/route/render-routes.test.js +317 -127
- package/lib/route/render-routes.test.js.map +1 -1
- package/lib/route/root-navigation.js +3 -7
- package/lib/route/root-navigation.js.map +1 -1
- package/lib/route/test-routes.d.ts +411 -0
- package/lib/route/test-routes.js +578 -0
- package/lib/route/test-routes.js.map +1 -0
- package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js +12 -37
- package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js.map +1 -1
- package/lib/route-based-plugin-area/__tests__/plugin-api.test.js +11 -13
- package/lib/route-based-plugin-area/__tests__/plugin-api.test.js.map +1 -1
- package/lib/route-based-plugin-area/higher-order-component-util.js +3 -7
- package/lib/route-based-plugin-area/higher-order-component-util.js.map +1 -1
- package/lib/route-based-plugin-area/index.js +2 -18
- package/lib/route-based-plugin-area/index.js.map +1 -1
- package/lib/route-based-plugin-area/plugin-api.js +15 -18
- package/lib/route-based-plugin-area/plugin-api.js.map +1 -1
- package/lib/route-based-plugin-area/plugin-context.js +5 -32
- package/lib/route-based-plugin-area/plugin-context.js.map +1 -1
- package/lib/route-based-plugin-area/route-based-plugin-area.js +12 -39
- package/lib/route-based-plugin-area/route-based-plugin-area.js.map +1 -1
- package/lib/router-factory/index.js +5 -31
- package/lib/router-factory/index.js.map +1 -1
- package/lib/router-factory/index.native.js +5 -31
- package/lib/router-factory/index.native.js.map +1 -1
- package/lib/utils/before-ssr.js +6 -19
- package/lib/utils/before-ssr.js.map +1 -1
- package/lib/utils/combine.js +2 -6
- package/lib/utils/combine.js.map +1 -1
- package/lib/utils/hydrate.js +3 -7
- package/lib/utils/hydrate.js.map +1 -1
- package/lib/utils/index.js +5 -21
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/sort-keys.d.ts +1 -0
- package/lib/utils/sort-keys.js +14 -10
- package/lib/utils/sort-keys.js.map +1 -1
- package/lib/utils/sort-keys.test.js +33 -7
- package/lib/utils/sort-keys.test.js.map +1 -1
- package/lib/utils/utils.js +1 -5
- package/lib/utils/utils.js.map +1 -1
- package/package.json +5 -4
- package/lib/route/render-routes.native.d.ts +0 -4
- package/lib/route/render-routes.native.js +0 -162
- package/lib/route/render-routes.native.js.map +0 -1
|
@@ -1,46 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const react_1 = require("@testing-library/react");
|
|
16
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
17
|
-
const react_2 = __importDefault(require("react"));
|
|
18
|
-
const render_routes_1 = require("./render-routes");
|
|
1
|
+
import { cleanup, getByText, render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import { Link, useParams, createMemoryRouter, RouterProvider, Outlet, useLoaderData } from 'react-router-dom';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { renderRoutes2 as renderRoutes } from './render-routes';
|
|
19
5
|
function TestInitialProps({ foo }) {
|
|
20
|
-
return
|
|
6
|
+
return React.createElement("h1", { "data-testid": "test" }, foo);
|
|
21
7
|
}
|
|
22
8
|
let mountCount = 0;
|
|
23
9
|
let renderCount = 0;
|
|
24
10
|
function TestInitialPropsWithoutUnmount({ foo }) {
|
|
25
|
-
|
|
11
|
+
React.useEffect(() => {
|
|
26
12
|
return () => {
|
|
27
13
|
mountCount++;
|
|
28
14
|
};
|
|
29
15
|
}, []);
|
|
30
|
-
return (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
return (React.createElement("div", null,
|
|
17
|
+
React.createElement("h1", { "data-testid": "test2" }, foo),
|
|
18
|
+
React.createElement("a", { href: "#bar" }, "link-bar"),
|
|
19
|
+
React.createElement(Link, { to: "/get-initial-props" }, "change-route"),
|
|
20
|
+
React.createElement("h2", { id: "bar" }, "h2-bar")));
|
|
35
21
|
}
|
|
36
22
|
function TestInitialPropsWithMount({ foo }) {
|
|
37
|
-
|
|
23
|
+
React.useEffect(() => {
|
|
38
24
|
mountCount++;
|
|
39
25
|
}, []);
|
|
40
26
|
renderCount++;
|
|
41
|
-
return
|
|
27
|
+
return React.createElement("h1", { "data-testid": "test" }, foo);
|
|
42
28
|
}
|
|
43
|
-
const getInitialProps = () =>
|
|
29
|
+
const getInitialProps = async () => {
|
|
44
30
|
return new Promise((resolve) => {
|
|
45
31
|
setTimeout(() => {
|
|
46
32
|
resolve({
|
|
@@ -48,16 +34,16 @@ const getInitialProps = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
48
34
|
});
|
|
49
35
|
}, 100);
|
|
50
36
|
});
|
|
51
|
-
}
|
|
37
|
+
};
|
|
52
38
|
TestInitialProps.getInitialProps = getInitialProps;
|
|
53
39
|
TestInitialPropsWithoutUnmount.getInitialProps = getInitialProps;
|
|
54
40
|
TestInitialPropsWithMount.getInitialProps = getInitialProps;
|
|
55
41
|
function TestInitialPropsParent({ foo, children, }) {
|
|
56
|
-
return (
|
|
57
|
-
|
|
42
|
+
return (React.createElement(React.Fragment, null,
|
|
43
|
+
React.createElement("h1", { "data-testid": "test-parent" }, foo),
|
|
58
44
|
children));
|
|
59
45
|
}
|
|
60
|
-
TestInitialPropsParent.getInitialProps = () =>
|
|
46
|
+
TestInitialPropsParent.getInitialProps = async () => {
|
|
61
47
|
return new Promise((resolve) => {
|
|
62
48
|
setTimeout(() => {
|
|
63
49
|
resolve({
|
|
@@ -65,22 +51,57 @@ TestInitialPropsParent.getInitialProps = () => __awaiter(void 0, void 0, void 0,
|
|
|
65
51
|
});
|
|
66
52
|
}, 100);
|
|
67
53
|
});
|
|
68
|
-
}
|
|
54
|
+
};
|
|
69
55
|
const routerConfig = {
|
|
56
|
+
isServer: false,
|
|
70
57
|
ssrProps: {},
|
|
58
|
+
loaderArgs: { foo: 'bar' },
|
|
71
59
|
routes: [
|
|
60
|
+
{
|
|
61
|
+
path: '/with-loader',
|
|
62
|
+
loader: async ({ foo }) => {
|
|
63
|
+
return { title: 'Loader', foo };
|
|
64
|
+
},
|
|
65
|
+
component: (props) => {
|
|
66
|
+
const loaderData = useLoaderData();
|
|
67
|
+
return (React.createElement(React.Fragment, null,
|
|
68
|
+
React.createElement("h1", { "data-testid": "root" }, loaderData.title),
|
|
69
|
+
React.createElement("h2", { "data-testid": "foo" }, loaderData.foo),
|
|
70
|
+
React.createElement(Outlet, null)));
|
|
71
|
+
},
|
|
72
|
+
routes: [
|
|
73
|
+
{
|
|
74
|
+
path: '/with-loader/child/:id',
|
|
75
|
+
loader: async ({ params }) => {
|
|
76
|
+
const list = ['one', 'two', 'three'];
|
|
77
|
+
return { number: list[params.id] };
|
|
78
|
+
},
|
|
79
|
+
component: (props) => {
|
|
80
|
+
const loaderData = useLoaderData();
|
|
81
|
+
return (React.createElement(React.Fragment, null,
|
|
82
|
+
React.createElement("h1", { "data-testid": "test" }, "Child"),
|
|
83
|
+
React.createElement("h2", { "data-testid": "number" }, loaderData.number)));
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
72
88
|
{
|
|
73
89
|
path: '/layout',
|
|
74
|
-
component: (props) => (
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
component: (props) => (React.createElement(React.Fragment, null,
|
|
91
|
+
React.createElement("h1", { "data-testid": "layout" }, "Layout"),
|
|
92
|
+
React.createElement("h2", { "data-testid": "routes" }, props.routes.map((r) => r.path).join(',')),
|
|
77
93
|
props.children)),
|
|
78
94
|
routes: [
|
|
79
95
|
{
|
|
80
96
|
path: '/layout',
|
|
81
|
-
component: (props) => (
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
component: (props) => (React.createElement(React.Fragment, null,
|
|
98
|
+
React.createElement("h1", { "data-testid": "test" }, "Foo"),
|
|
99
|
+
React.createElement("h2", { "data-testid": "routes-embed" }, props.routes.map((r) => r.path).join(',')))),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
path: '/layout/top',
|
|
103
|
+
component: (props) => (React.createElement(React.Fragment, null,
|
|
104
|
+
React.createElement("h1", { "data-testid": "top" }, "Top"))),
|
|
84
105
|
},
|
|
85
106
|
],
|
|
86
107
|
},
|
|
@@ -89,34 +110,82 @@ const routerConfig = {
|
|
|
89
110
|
routes: [
|
|
90
111
|
{
|
|
91
112
|
path: '/layout-without-component/foo',
|
|
92
|
-
component: () =>
|
|
113
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Foo"),
|
|
93
114
|
},
|
|
94
115
|
],
|
|
95
116
|
},
|
|
96
117
|
{
|
|
97
118
|
path: '/users/:id',
|
|
98
119
|
component: (props) => {
|
|
99
|
-
|
|
120
|
+
let params = useParams();
|
|
121
|
+
return React.createElement(React.Fragment, null,
|
|
122
|
+
React.createElement("h1", { "data-testid": "test" }, params.id),
|
|
123
|
+
React.createElement(Outlet, null));
|
|
100
124
|
},
|
|
125
|
+
routes: [
|
|
126
|
+
{
|
|
127
|
+
path: '/users/:id/dashboard',
|
|
128
|
+
component: (props) => {
|
|
129
|
+
let params = useParams();
|
|
130
|
+
return React.createElement("h2", { "data-testid": "test2" },
|
|
131
|
+
"Dashboard of ",
|
|
132
|
+
params.id);
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
path: '/users/:id/profile',
|
|
137
|
+
component: (props) => {
|
|
138
|
+
let params = useParams();
|
|
139
|
+
return React.createElement("h2", { "data-testid": "test2" },
|
|
140
|
+
"Profile of ",
|
|
141
|
+
params.id);
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
]
|
|
101
145
|
},
|
|
102
|
-
{
|
|
146
|
+
{
|
|
147
|
+
path: '/nested-routes',
|
|
148
|
+
routes: [
|
|
149
|
+
{
|
|
150
|
+
path: '/nested-routes/first',
|
|
151
|
+
component: () => React.createElement("h2", { "data-testid": "child" }, "First"),
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
path: '/nested-routes/second',
|
|
155
|
+
component: () => React.createElement(React.Fragment, null,
|
|
156
|
+
React.createElement("h2", { "data-testid": "child" }, "Second"),
|
|
157
|
+
React.createElement(Outlet, null)),
|
|
158
|
+
routes: [
|
|
159
|
+
{
|
|
160
|
+
path: '/nested-routes/second/one',
|
|
161
|
+
component: () => React.createElement("h3", { "data-testid": "nest-child" }, "One"),
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
path: '/nested-routes/second/two',
|
|
165
|
+
component: () => React.createElement("h3", { "data-testid": "nest-child" }, "Two"),
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
{ path: '/bar', component: () => React.createElement("h1", { "data-testid": "test" }, "Bar") },
|
|
103
172
|
{
|
|
104
173
|
path: '/bar-exact',
|
|
105
174
|
exact: true,
|
|
106
|
-
component: () =>
|
|
175
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Exact"),
|
|
107
176
|
},
|
|
108
177
|
{
|
|
109
178
|
path: '/bar-strict/',
|
|
110
179
|
strict: true,
|
|
111
|
-
component: () =>
|
|
180
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Strict mode will not work"),
|
|
112
181
|
},
|
|
113
182
|
{
|
|
114
183
|
path: '/bar-sensitive',
|
|
115
184
|
sensitive: true,
|
|
116
|
-
component: () =>
|
|
185
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Sensitive"),
|
|
117
186
|
},
|
|
118
187
|
{ path: '/redirect', redirect: '/d' },
|
|
119
|
-
{ path: '/d', component: () =>
|
|
188
|
+
{ path: '/d', component: () => React.createElement("h1", { "data-testid": "test" }, "Redirect") },
|
|
120
189
|
{ path: '/get-initial-props', component: TestInitialProps },
|
|
121
190
|
{
|
|
122
191
|
path: '/get-initial-props-without-unmount',
|
|
@@ -139,124 +208,245 @@ const routerConfig = {
|
|
|
139
208
|
{
|
|
140
209
|
path: '/props-route',
|
|
141
210
|
foo: 'bar',
|
|
142
|
-
component: (props) => (
|
|
211
|
+
component: (props) => (React.createElement("h1", { "data-testid": "test" }, `${props.route.path} ${props.route.foo}`)),
|
|
143
212
|
},
|
|
144
213
|
{
|
|
145
214
|
path: '/pass-props',
|
|
146
215
|
component: (props) => {
|
|
147
|
-
return
|
|
148
|
-
return
|
|
216
|
+
return React.Children.map(props.children, (child) => {
|
|
217
|
+
return React.cloneElement(child, { foo: 'bar' });
|
|
149
218
|
});
|
|
150
219
|
},
|
|
151
220
|
routes: [
|
|
152
221
|
{
|
|
153
222
|
path: '/pass-props',
|
|
154
|
-
component: (props) =>
|
|
223
|
+
component: (props) => React.createElement("h1", { "data-testid": "test" }, props.foo),
|
|
155
224
|
},
|
|
156
225
|
],
|
|
157
226
|
},
|
|
158
227
|
{
|
|
159
228
|
path: '/wrappers',
|
|
160
|
-
component: () =>
|
|
229
|
+
component: () => React.createElement("h1", null, "foo"),
|
|
161
230
|
wrappers: [
|
|
162
|
-
(props) => (
|
|
163
|
-
|
|
231
|
+
(props) => (React.createElement(React.Fragment, null,
|
|
232
|
+
React.createElement("h1", null,
|
|
164
233
|
"wrapper 1 ",
|
|
165
234
|
props.route.path),
|
|
166
235
|
props.children)),
|
|
167
|
-
(props) => (
|
|
168
|
-
|
|
236
|
+
(props) => (React.createElement(React.Fragment, null,
|
|
237
|
+
React.createElement("h1", null, "wrapper 2"),
|
|
169
238
|
props.children)),
|
|
170
239
|
],
|
|
171
240
|
},
|
|
172
|
-
{ component: () =>
|
|
241
|
+
{ component: () => React.createElement("h1", { "data-testid": "test" }, "Fallback") },
|
|
173
242
|
],
|
|
174
243
|
// plugin: new Plugin(),
|
|
175
244
|
};
|
|
176
|
-
|
|
245
|
+
// const setComponent = (configs) => {
|
|
246
|
+
// return configs.map((config) => {
|
|
247
|
+
// config.component = (props) => {
|
|
248
|
+
// const configParam = useParams();
|
|
249
|
+
// if (Array.isArray(config.routes)) {
|
|
250
|
+
// // console.log(props);
|
|
251
|
+
// return <section><h1>{config.path}</h1><span>{JSON.stringify(configParam)}</span><Outlet /></section>
|
|
252
|
+
// } else {
|
|
253
|
+
// return <section><h1>{config.path}</h1><span>{JSON.stringify(configParam)}</span><p>{config.key}</p></section>
|
|
254
|
+
// }
|
|
255
|
+
// }
|
|
256
|
+
// if (Array.isArray(config.routes)) {
|
|
257
|
+
// config.routes = setComponent(config.routes);
|
|
258
|
+
// }
|
|
259
|
+
// return config
|
|
260
|
+
// })
|
|
261
|
+
// }
|
|
262
|
+
// routerConfig.routes = setComponent(testRoutes);
|
|
263
|
+
const routes = renderRoutes(routerConfig);
|
|
177
264
|
beforeEach(() => {
|
|
178
265
|
window.g_useSSR = true;
|
|
179
266
|
window.g_initialProps = null;
|
|
180
267
|
mountCount = 0;
|
|
181
268
|
renderCount = 0;
|
|
182
269
|
});
|
|
183
|
-
afterEach(() =>
|
|
270
|
+
afterEach(async () => {
|
|
184
271
|
delete window.g_useSSR;
|
|
185
272
|
delete window.g_initialProps;
|
|
186
|
-
|
|
187
|
-
})
|
|
188
|
-
test('/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}));
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
(
|
|
202
|
-
expect((
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
expect((
|
|
211
|
-
})
|
|
212
|
-
test('/
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
(
|
|
226
|
-
expect((
|
|
227
|
-
})
|
|
228
|
-
test('/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
273
|
+
await cleanup();
|
|
274
|
+
});
|
|
275
|
+
// test('/o/:orgName/dashboard', async () => {
|
|
276
|
+
// const router = createMemoryRouter(routes, {initialEntries: ['/o/toka/dashboard']});
|
|
277
|
+
// const { container } = render(<RouterProvider router={router} />)
|
|
278
|
+
// expect(container).toMatchSnapshot();
|
|
279
|
+
// });
|
|
280
|
+
test('/layout', async () => {
|
|
281
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/layout'] });
|
|
282
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
283
|
+
// const { container } = render(
|
|
284
|
+
// <MemoryRouter initialEntries={['/layout']}>
|
|
285
|
+
// {routes}
|
|
286
|
+
// </MemoryRouter>
|
|
287
|
+
// );
|
|
288
|
+
// expect(container).toMatchSnapshot();
|
|
289
|
+
expect((await screen.findByTestId('layout')).innerHTML).toEqual('Layout');
|
|
290
|
+
expect((await screen.findByTestId('routes')).innerHTML).toContain('/layout,/layout-without-component,/users/:id');
|
|
291
|
+
expect((await screen.findByTestId('routes-embed')).innerHTML).toContain('/layout,/layout-without-component,/users/:id');
|
|
292
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Foo');
|
|
293
|
+
});
|
|
294
|
+
test('/layout/top', async () => {
|
|
295
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/layout/top'] });
|
|
296
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
297
|
+
expect((await screen.findByTestId('top')).innerHTML).toEqual('Top');
|
|
298
|
+
});
|
|
299
|
+
test('/layout-without-component', async () => {
|
|
300
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/layout-without-component/foo'] });
|
|
301
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
302
|
+
// render(
|
|
303
|
+
// <MemoryRouter initialEntries={['/layout-without-component/foo']}>
|
|
304
|
+
// {routes}
|
|
305
|
+
// </MemoryRouter>,
|
|
306
|
+
// );
|
|
307
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Foo');
|
|
308
|
+
});
|
|
309
|
+
test('/with-loader', async () => {
|
|
310
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/with-loader'] });
|
|
311
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
312
|
+
expect((await screen.findByTestId('root')).innerHTML).toEqual('Loader');
|
|
313
|
+
expect((await screen.findByTestId('foo')).innerHTML).toEqual('bar');
|
|
314
|
+
});
|
|
315
|
+
test('/with-loader/child', async () => {
|
|
316
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/with-loader/child/1'] });
|
|
317
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
318
|
+
expect((await screen.findByTestId('root')).innerHTML).toEqual('Loader');
|
|
319
|
+
expect((await screen.findByTestId('foo')).innerHTML).toEqual('bar');
|
|
320
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Child');
|
|
321
|
+
expect((await screen.findByTestId('number')).innerHTML).toEqual('two');
|
|
322
|
+
});
|
|
323
|
+
test('/nested-routes/first', async () => {
|
|
324
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/nested-routes/first'] });
|
|
325
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
326
|
+
expect((await screen.findByTestId('child')).innerHTML).toEqual('First');
|
|
327
|
+
});
|
|
328
|
+
test('/nested-routes/second/one', async () => {
|
|
329
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/nested-routes/second/one'] });
|
|
330
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
331
|
+
expect((await screen.findByTestId('nest-child')).innerHTML).toEqual('One');
|
|
332
|
+
});
|
|
333
|
+
test('/bar', async () => {
|
|
334
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/bar'] });
|
|
335
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
336
|
+
// render(<MemoryRouter initialEntries={['/bar']}>{routes}</MemoryRouter>);
|
|
337
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Bar');
|
|
338
|
+
});
|
|
339
|
+
test('/BAR', async () => {
|
|
340
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/BAR'] });
|
|
341
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
342
|
+
// render(<MemoryRouter initialEntries={['/BAR']}>{routes}</MemoryRouter>);
|
|
343
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Bar');
|
|
344
|
+
});
|
|
345
|
+
test('/bar-exact/foo', async () => {
|
|
346
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/bar-exact/foo'] });
|
|
347
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
348
|
+
// render(
|
|
349
|
+
// <MemoryRouter initialEntries={['/bar-exact/foo']}>{routes}</MemoryRouter>,
|
|
350
|
+
// );
|
|
351
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Fallback');
|
|
352
|
+
});
|
|
353
|
+
test('/bar-strict', async () => {
|
|
354
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/bar-strict'] });
|
|
355
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
356
|
+
// render(
|
|
357
|
+
// <MemoryRouter initialEntries={['/bar-strict']}>{routes}</MemoryRouter>,
|
|
358
|
+
// );
|
|
359
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Bar Strict mode will not work');
|
|
360
|
+
});
|
|
361
|
+
test('/BAR-sensitive', async () => {
|
|
362
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/BAR-sensitive'] });
|
|
363
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
364
|
+
// render(
|
|
365
|
+
// <MemoryRouter initialEntries={['/BAR-sensitive']}>{routes}</MemoryRouter>,
|
|
366
|
+
// );
|
|
367
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Fallback');
|
|
368
|
+
});
|
|
369
|
+
test('/users/123', async () => {
|
|
370
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/users/123'] });
|
|
371
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
372
|
+
// render(<MemoryRouter initialEntries={['/users/123']}>{routes}</MemoryRouter>);
|
|
373
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('123');
|
|
374
|
+
});
|
|
375
|
+
test('/users/123/dashboard', async () => {
|
|
376
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/users/123/dashboard'] });
|
|
377
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
378
|
+
// render(<MemoryRouter initialEntries={['/users/123']}>{routes}</MemoryRouter>);
|
|
379
|
+
expect((await screen.findByTestId('test2')).innerHTML).toEqual('Dashboard of 123');
|
|
380
|
+
});
|
|
381
|
+
test('/redirect', async () => {
|
|
382
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/redirect'] });
|
|
383
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
384
|
+
// const newRoutes = renderRoutes({...routerConfig, withRoutesElement: true});
|
|
385
|
+
// render(<MemoryRouter initialEntries={['/redirect']}>{newRoutes}</MemoryRouter>);
|
|
386
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Redirect');
|
|
387
|
+
});
|
|
388
|
+
test('/props-route', async () => {
|
|
389
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/props-route'] });
|
|
390
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
391
|
+
// render(
|
|
392
|
+
// <MemoryRouter initialEntries={['/props-route']}>{routes}</MemoryRouter>,
|
|
393
|
+
// );
|
|
394
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('/props-route bar');
|
|
395
|
+
});
|
|
396
|
+
test('/pass-props', async () => {
|
|
397
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/pass-props'] });
|
|
398
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
399
|
+
// const { container } = render(
|
|
400
|
+
// <MemoryRouter initialEntries={['/pass-props']}>{routes}</MemoryRouter>,
|
|
401
|
+
// );
|
|
402
|
+
await waitFor(() => getByText(container, 'bar'));
|
|
403
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('bar');
|
|
404
|
+
});
|
|
405
|
+
test('/get-initial-props-with-mount', async () => {
|
|
406
|
+
const newRoutes = renderRoutes(routerConfig);
|
|
407
|
+
const router = createMemoryRouter(newRoutes, { initialEntries: ['/get-initial-props-with-mount'] });
|
|
239
408
|
expect(mountCount).toEqual(0);
|
|
240
409
|
expect(renderCount).toEqual(0);
|
|
241
|
-
const { container } =
|
|
242
|
-
|
|
410
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
411
|
+
// const { container } = render(
|
|
412
|
+
// <MemoryRouter initialEntries={['/get-initial-props-with-mount']}>
|
|
413
|
+
// {newRoutes}
|
|
414
|
+
// </MemoryRouter>,
|
|
415
|
+
// );
|
|
416
|
+
await waitFor(() => getByText(container, 'bar'));
|
|
243
417
|
expect(mountCount).toEqual(1);
|
|
244
418
|
expect(renderCount).toEqual(2);
|
|
245
|
-
})
|
|
246
|
-
test('/get-initial-props-embed', () =>
|
|
247
|
-
const newRoutes = (
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
419
|
+
});
|
|
420
|
+
test('/get-initial-props-embed', async () => {
|
|
421
|
+
const newRoutes = renderRoutes(routerConfig);
|
|
422
|
+
const router = createMemoryRouter(newRoutes, { initialEntries: ['/get-initial-props-embed'] });
|
|
423
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
424
|
+
// const { container } = render(
|
|
425
|
+
// <MemoryRouter initialEntries={['/get-initial-props-embed']}>
|
|
426
|
+
// {newRoutes}
|
|
427
|
+
// </MemoryRouter>,
|
|
428
|
+
// );
|
|
429
|
+
await waitFor(() => getByText(container, 'bar'));
|
|
430
|
+
await waitFor(() => getByText(container, 'parent'));
|
|
431
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('bar');
|
|
432
|
+
expect((await screen.findByTestId('test-parent')).innerHTML).toEqual('parent');
|
|
433
|
+
});
|
|
254
434
|
test('/wrappers', () => {
|
|
255
|
-
const
|
|
435
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/wrappers'] });
|
|
436
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
437
|
+
// const { container } = render(
|
|
438
|
+
// <MemoryRouter initialEntries={['/wrappers']}>{routes}</MemoryRouter>,
|
|
439
|
+
// );
|
|
256
440
|
expect(container.innerHTML).toEqual('<h1>wrapper 1 /wrappers</h1><h1>wrapper 2</h1><h1>foo</h1>');
|
|
257
441
|
});
|
|
258
|
-
test('/fallback-20140924', () =>
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
442
|
+
test('/fallback-20140924', async () => {
|
|
443
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/fallback-20140924'] });
|
|
444
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
445
|
+
// render(
|
|
446
|
+
// <MemoryRouter initialEntries={['/fallback-20140924']}>
|
|
447
|
+
// {routes}
|
|
448
|
+
// </MemoryRouter>,
|
|
449
|
+
// );
|
|
450
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Fallback');
|
|
451
|
+
});
|
|
262
452
|
//# sourceMappingURL=render-routes.test.js.map
|