@common-stack/client-react 3.0.2-alpha.1 → 3.0.2-alpha.4
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 +12 -37
- package/lib/__tests__/integrated-routes.test.js.map +1 -1
- package/lib/__tests__/router-render.test.js +13 -53
- 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.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.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 +22 -29
- package/lib/route/get-routes.js.map +1 -1
- package/lib/route/get-routes.test.js +6 -17
- 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.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 +14 -12
- package/lib/route/old/get-routes-notused.js.map +1 -1
- package/lib/route/old/render.js +6 -33
- package/lib/route/old/render.js.map +1 -1
- 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 +14 -16
- 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.js +32 -65
- package/lib/route/render-routes-native.js.map +1 -1
- package/lib/route/render-routes.js +54 -85
- package/lib/route/render-routes.js.map +1 -1
- package/lib/route/render-routes.test.js +189 -203
- 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.js +1 -3
- package/lib/route/test-routes.js.map +1 -1
- 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.js +5 -13
- package/lib/utils/sort-keys.js.map +1 -1
- package/lib/utils/sort-keys.test.js +3 -5
- 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
|
@@ -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,7 +51,7 @@ TestInitialPropsParent.getInitialProps = () => __awaiter(void 0, void 0, void 0,
|
|
|
65
51
|
});
|
|
66
52
|
}, 100);
|
|
67
53
|
});
|
|
68
|
-
}
|
|
54
|
+
};
|
|
69
55
|
const routerConfig = {
|
|
70
56
|
isServer: false,
|
|
71
57
|
ssrProps: {},
|
|
@@ -73,49 +59,49 @@ const routerConfig = {
|
|
|
73
59
|
routes: [
|
|
74
60
|
{
|
|
75
61
|
path: '/with-loader',
|
|
76
|
-
loader: ({ foo }) =>
|
|
62
|
+
loader: async ({ foo }) => {
|
|
77
63
|
return { title: 'Loader', foo };
|
|
78
|
-
}
|
|
64
|
+
},
|
|
79
65
|
component: (props) => {
|
|
80
|
-
const loaderData =
|
|
81
|
-
return (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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)));
|
|
85
71
|
},
|
|
86
72
|
routes: [
|
|
87
73
|
{
|
|
88
74
|
path: '/with-loader/child/:id',
|
|
89
|
-
loader: ({ params }) =>
|
|
75
|
+
loader: async ({ params }) => {
|
|
90
76
|
const list = ['one', 'two', 'three'];
|
|
91
77
|
return { number: list[params.id] };
|
|
92
|
-
}
|
|
78
|
+
},
|
|
93
79
|
component: (props) => {
|
|
94
|
-
const loaderData =
|
|
95
|
-
return (
|
|
96
|
-
|
|
97
|
-
|
|
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)));
|
|
98
84
|
}
|
|
99
85
|
},
|
|
100
86
|
],
|
|
101
87
|
},
|
|
102
88
|
{
|
|
103
89
|
path: '/layout',
|
|
104
|
-
component: (props) => (
|
|
105
|
-
|
|
106
|
-
|
|
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(',')),
|
|
107
93
|
props.children)),
|
|
108
94
|
routes: [
|
|
109
95
|
{
|
|
110
96
|
path: '/layout',
|
|
111
|
-
component: (props) => (
|
|
112
|
-
|
|
113
|
-
|
|
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(',')))),
|
|
114
100
|
},
|
|
115
101
|
{
|
|
116
102
|
path: '/layout/top',
|
|
117
|
-
component: (props) => (
|
|
118
|
-
|
|
103
|
+
component: (props) => (React.createElement(React.Fragment, null,
|
|
104
|
+
React.createElement("h1", { "data-testid": "top" }, "Top"))),
|
|
119
105
|
},
|
|
120
106
|
],
|
|
121
107
|
},
|
|
@@ -124,24 +110,24 @@ const routerConfig = {
|
|
|
124
110
|
routes: [
|
|
125
111
|
{
|
|
126
112
|
path: '/layout-without-component/foo',
|
|
127
|
-
component: () =>
|
|
113
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Foo"),
|
|
128
114
|
},
|
|
129
115
|
],
|
|
130
116
|
},
|
|
131
117
|
{
|
|
132
118
|
path: '/users/:id',
|
|
133
119
|
component: (props) => {
|
|
134
|
-
let params =
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
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));
|
|
138
124
|
},
|
|
139
125
|
routes: [
|
|
140
126
|
{
|
|
141
127
|
path: '/users/:id/dashboard',
|
|
142
128
|
component: (props) => {
|
|
143
|
-
let params =
|
|
144
|
-
return
|
|
129
|
+
let params = useParams();
|
|
130
|
+
return React.createElement("h2", { "data-testid": "test2" },
|
|
145
131
|
"Dashboard of ",
|
|
146
132
|
params.id);
|
|
147
133
|
},
|
|
@@ -149,8 +135,8 @@ const routerConfig = {
|
|
|
149
135
|
{
|
|
150
136
|
path: '/users/:id/profile',
|
|
151
137
|
component: (props) => {
|
|
152
|
-
let params =
|
|
153
|
-
return
|
|
138
|
+
let params = useParams();
|
|
139
|
+
return React.createElement("h2", { "data-testid": "test2" },
|
|
154
140
|
"Profile of ",
|
|
155
141
|
params.id);
|
|
156
142
|
},
|
|
@@ -162,44 +148,44 @@ const routerConfig = {
|
|
|
162
148
|
routes: [
|
|
163
149
|
{
|
|
164
150
|
path: '/nested-routes/first',
|
|
165
|
-
component: () =>
|
|
151
|
+
component: () => React.createElement("h2", { "data-testid": "child" }, "First"),
|
|
166
152
|
},
|
|
167
153
|
{
|
|
168
154
|
path: '/nested-routes/second',
|
|
169
|
-
component: () =>
|
|
170
|
-
|
|
171
|
-
|
|
155
|
+
component: () => React.createElement(React.Fragment, null,
|
|
156
|
+
React.createElement("h2", { "data-testid": "child" }, "Second"),
|
|
157
|
+
React.createElement(Outlet, null)),
|
|
172
158
|
routes: [
|
|
173
159
|
{
|
|
174
160
|
path: '/nested-routes/second/one',
|
|
175
|
-
component: () =>
|
|
161
|
+
component: () => React.createElement("h3", { "data-testid": "nest-child" }, "One"),
|
|
176
162
|
},
|
|
177
163
|
{
|
|
178
164
|
path: '/nested-routes/second/two',
|
|
179
|
-
component: () =>
|
|
165
|
+
component: () => React.createElement("h3", { "data-testid": "nest-child" }, "Two"),
|
|
180
166
|
},
|
|
181
167
|
],
|
|
182
168
|
},
|
|
183
169
|
],
|
|
184
170
|
},
|
|
185
|
-
{ path: '/bar', component: () =>
|
|
171
|
+
{ path: '/bar', component: () => React.createElement("h1", { "data-testid": "test" }, "Bar") },
|
|
186
172
|
{
|
|
187
173
|
path: '/bar-exact',
|
|
188
174
|
exact: true,
|
|
189
|
-
component: () =>
|
|
175
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Exact"),
|
|
190
176
|
},
|
|
191
177
|
{
|
|
192
178
|
path: '/bar-strict/',
|
|
193
179
|
strict: true,
|
|
194
|
-
component: () =>
|
|
180
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Strict mode will not work"),
|
|
195
181
|
},
|
|
196
182
|
{
|
|
197
183
|
path: '/bar-sensitive',
|
|
198
184
|
sensitive: true,
|
|
199
|
-
component: () =>
|
|
185
|
+
component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Sensitive"),
|
|
200
186
|
},
|
|
201
187
|
{ path: '/redirect', redirect: '/d' },
|
|
202
|
-
{ path: '/d', component: () =>
|
|
188
|
+
{ path: '/d', component: () => React.createElement("h1", { "data-testid": "test" }, "Redirect") },
|
|
203
189
|
{ path: '/get-initial-props', component: TestInitialProps },
|
|
204
190
|
{
|
|
205
191
|
path: '/get-initial-props-without-unmount',
|
|
@@ -222,37 +208,37 @@ const routerConfig = {
|
|
|
222
208
|
{
|
|
223
209
|
path: '/props-route',
|
|
224
210
|
foo: 'bar',
|
|
225
|
-
component: (props) => (
|
|
211
|
+
component: (props) => (React.createElement("h1", { "data-testid": "test" }, `${props.route.path} ${props.route.foo}`)),
|
|
226
212
|
},
|
|
227
213
|
{
|
|
228
214
|
path: '/pass-props',
|
|
229
215
|
component: (props) => {
|
|
230
|
-
return
|
|
231
|
-
return
|
|
216
|
+
return React.Children.map(props.children, (child) => {
|
|
217
|
+
return React.cloneElement(child, { foo: 'bar' });
|
|
232
218
|
});
|
|
233
219
|
},
|
|
234
220
|
routes: [
|
|
235
221
|
{
|
|
236
222
|
path: '/pass-props',
|
|
237
|
-
component: (props) =>
|
|
223
|
+
component: (props) => React.createElement("h1", { "data-testid": "test" }, props.foo),
|
|
238
224
|
},
|
|
239
225
|
],
|
|
240
226
|
},
|
|
241
227
|
{
|
|
242
228
|
path: '/wrappers',
|
|
243
|
-
component: () =>
|
|
229
|
+
component: () => React.createElement("h1", null, "foo"),
|
|
244
230
|
wrappers: [
|
|
245
|
-
(props) => (
|
|
246
|
-
|
|
231
|
+
(props) => (React.createElement(React.Fragment, null,
|
|
232
|
+
React.createElement("h1", null,
|
|
247
233
|
"wrapper 1 ",
|
|
248
234
|
props.route.path),
|
|
249
235
|
props.children)),
|
|
250
|
-
(props) => (
|
|
251
|
-
|
|
236
|
+
(props) => (React.createElement(React.Fragment, null,
|
|
237
|
+
React.createElement("h1", null, "wrapper 2"),
|
|
252
238
|
props.children)),
|
|
253
239
|
],
|
|
254
240
|
},
|
|
255
|
-
{ component: () =>
|
|
241
|
+
{ component: () => React.createElement("h1", { "data-testid": "test" }, "Fallback") },
|
|
256
242
|
],
|
|
257
243
|
// plugin: new Plugin(),
|
|
258
244
|
};
|
|
@@ -274,193 +260,193 @@ const routerConfig = {
|
|
|
274
260
|
// })
|
|
275
261
|
// }
|
|
276
262
|
// routerConfig.routes = setComponent(testRoutes);
|
|
277
|
-
const routes = (
|
|
263
|
+
const routes = renderRoutes(routerConfig);
|
|
278
264
|
beforeEach(() => {
|
|
279
265
|
window.g_useSSR = true;
|
|
280
266
|
window.g_initialProps = null;
|
|
281
267
|
mountCount = 0;
|
|
282
268
|
renderCount = 0;
|
|
283
269
|
});
|
|
284
|
-
afterEach(() =>
|
|
270
|
+
afterEach(async () => {
|
|
285
271
|
delete window.g_useSSR;
|
|
286
272
|
delete window.g_initialProps;
|
|
287
|
-
|
|
288
|
-
})
|
|
273
|
+
await cleanup();
|
|
274
|
+
});
|
|
289
275
|
// test('/o/:orgName/dashboard', async () => {
|
|
290
276
|
// const router = createMemoryRouter(routes, {initialEntries: ['/o/toka/dashboard']});
|
|
291
277
|
// const { container } = render(<RouterProvider router={router} />)
|
|
292
278
|
// expect(container).toMatchSnapshot();
|
|
293
279
|
// });
|
|
294
|
-
test('/layout', () =>
|
|
295
|
-
const router =
|
|
296
|
-
const { container } =
|
|
280
|
+
test('/layout', async () => {
|
|
281
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/layout'] });
|
|
282
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
297
283
|
// const { container } = render(
|
|
298
284
|
// <MemoryRouter initialEntries={['/layout']}>
|
|
299
285
|
// {routes}
|
|
300
286
|
// </MemoryRouter>
|
|
301
287
|
// );
|
|
302
288
|
// expect(container).toMatchSnapshot();
|
|
303
|
-
expect((
|
|
304
|
-
expect((
|
|
305
|
-
expect((
|
|
306
|
-
expect((
|
|
307
|
-
})
|
|
308
|
-
test('/layout/top', () =>
|
|
309
|
-
const router =
|
|
310
|
-
|
|
311
|
-
expect((
|
|
312
|
-
})
|
|
313
|
-
test('/layout-without-component', () =>
|
|
314
|
-
const router =
|
|
315
|
-
|
|
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 }));
|
|
316
302
|
// render(
|
|
317
303
|
// <MemoryRouter initialEntries={['/layout-without-component/foo']}>
|
|
318
304
|
// {routes}
|
|
319
305
|
// </MemoryRouter>,
|
|
320
306
|
// );
|
|
321
|
-
expect((
|
|
322
|
-
})
|
|
323
|
-
test('/with-loader', () =>
|
|
324
|
-
const router =
|
|
325
|
-
|
|
326
|
-
expect((
|
|
327
|
-
expect((
|
|
328
|
-
})
|
|
329
|
-
test('/with-loader/child', () =>
|
|
330
|
-
const router =
|
|
331
|
-
|
|
332
|
-
expect((
|
|
333
|
-
expect((
|
|
334
|
-
expect((
|
|
335
|
-
expect((
|
|
336
|
-
})
|
|
337
|
-
test('/nested-routes/first', () =>
|
|
338
|
-
const router =
|
|
339
|
-
|
|
340
|
-
expect((
|
|
341
|
-
})
|
|
342
|
-
test('/nested-routes/second/one', () =>
|
|
343
|
-
const router =
|
|
344
|
-
|
|
345
|
-
expect((
|
|
346
|
-
})
|
|
347
|
-
test('/bar', () =>
|
|
348
|
-
const router =
|
|
349
|
-
|
|
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 }));
|
|
350
336
|
// render(<MemoryRouter initialEntries={['/bar']}>{routes}</MemoryRouter>);
|
|
351
|
-
expect((
|
|
352
|
-
})
|
|
353
|
-
test('/BAR', () =>
|
|
354
|
-
const router =
|
|
355
|
-
|
|
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 }));
|
|
356
342
|
// render(<MemoryRouter initialEntries={['/BAR']}>{routes}</MemoryRouter>);
|
|
357
|
-
expect((
|
|
358
|
-
})
|
|
359
|
-
test('/bar-exact/foo', () =>
|
|
360
|
-
const router =
|
|
361
|
-
|
|
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 }));
|
|
362
348
|
// render(
|
|
363
349
|
// <MemoryRouter initialEntries={['/bar-exact/foo']}>{routes}</MemoryRouter>,
|
|
364
350
|
// );
|
|
365
|
-
expect((
|
|
366
|
-
})
|
|
367
|
-
test('/bar-strict', () =>
|
|
368
|
-
const router =
|
|
369
|
-
|
|
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 }));
|
|
370
356
|
// render(
|
|
371
357
|
// <MemoryRouter initialEntries={['/bar-strict']}>{routes}</MemoryRouter>,
|
|
372
358
|
// );
|
|
373
|
-
expect((
|
|
374
|
-
})
|
|
375
|
-
test('/BAR-sensitive', () =>
|
|
376
|
-
const router =
|
|
377
|
-
|
|
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 }));
|
|
378
364
|
// render(
|
|
379
365
|
// <MemoryRouter initialEntries={['/BAR-sensitive']}>{routes}</MemoryRouter>,
|
|
380
366
|
// );
|
|
381
|
-
expect((
|
|
382
|
-
})
|
|
383
|
-
test('/users/123', () =>
|
|
384
|
-
const router =
|
|
385
|
-
|
|
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 }));
|
|
386
372
|
// render(<MemoryRouter initialEntries={['/users/123']}>{routes}</MemoryRouter>);
|
|
387
|
-
expect((
|
|
388
|
-
})
|
|
389
|
-
test('/users/123/dashboard', () =>
|
|
390
|
-
const router =
|
|
391
|
-
|
|
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 }));
|
|
392
378
|
// render(<MemoryRouter initialEntries={['/users/123']}>{routes}</MemoryRouter>);
|
|
393
|
-
expect((
|
|
394
|
-
})
|
|
395
|
-
test('/redirect', () =>
|
|
396
|
-
const router =
|
|
397
|
-
|
|
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 }));
|
|
398
384
|
// const newRoutes = renderRoutes({...routerConfig, withRoutesElement: true});
|
|
399
385
|
// render(<MemoryRouter initialEntries={['/redirect']}>{newRoutes}</MemoryRouter>);
|
|
400
|
-
expect((
|
|
401
|
-
})
|
|
402
|
-
test('/props-route', () =>
|
|
403
|
-
const router =
|
|
404
|
-
|
|
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 }));
|
|
405
391
|
// render(
|
|
406
392
|
// <MemoryRouter initialEntries={['/props-route']}>{routes}</MemoryRouter>,
|
|
407
393
|
// );
|
|
408
|
-
expect((
|
|
409
|
-
})
|
|
410
|
-
test('/pass-props', () =>
|
|
411
|
-
const router =
|
|
412
|
-
const { container } =
|
|
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 }));
|
|
413
399
|
// const { container } = render(
|
|
414
400
|
// <MemoryRouter initialEntries={['/pass-props']}>{routes}</MemoryRouter>,
|
|
415
401
|
// );
|
|
416
|
-
|
|
417
|
-
expect((
|
|
418
|
-
})
|
|
419
|
-
test('/get-initial-props-with-mount', () =>
|
|
420
|
-
const newRoutes = (
|
|
421
|
-
const router =
|
|
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'] });
|
|
422
408
|
expect(mountCount).toEqual(0);
|
|
423
409
|
expect(renderCount).toEqual(0);
|
|
424
|
-
const { container } =
|
|
410
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
425
411
|
// const { container } = render(
|
|
426
412
|
// <MemoryRouter initialEntries={['/get-initial-props-with-mount']}>
|
|
427
413
|
// {newRoutes}
|
|
428
414
|
// </MemoryRouter>,
|
|
429
415
|
// );
|
|
430
|
-
|
|
416
|
+
await waitFor(() => getByText(container, 'bar'));
|
|
431
417
|
expect(mountCount).toEqual(1);
|
|
432
418
|
expect(renderCount).toEqual(2);
|
|
433
|
-
})
|
|
434
|
-
test('/get-initial-props-embed', () =>
|
|
435
|
-
const newRoutes = (
|
|
436
|
-
const router =
|
|
437
|
-
const { container } =
|
|
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 }));
|
|
438
424
|
// const { container } = render(
|
|
439
425
|
// <MemoryRouter initialEntries={['/get-initial-props-embed']}>
|
|
440
426
|
// {newRoutes}
|
|
441
427
|
// </MemoryRouter>,
|
|
442
428
|
// );
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
expect((
|
|
446
|
-
expect((
|
|
447
|
-
})
|
|
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
|
+
});
|
|
448
434
|
test('/wrappers', () => {
|
|
449
|
-
const router =
|
|
450
|
-
const { container } =
|
|
435
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/wrappers'] });
|
|
436
|
+
const { container } = render(React.createElement(RouterProvider, { router: router }));
|
|
451
437
|
// const { container } = render(
|
|
452
438
|
// <MemoryRouter initialEntries={['/wrappers']}>{routes}</MemoryRouter>,
|
|
453
439
|
// );
|
|
454
440
|
expect(container.innerHTML).toEqual('<h1>wrapper 1 /wrappers</h1><h1>wrapper 2</h1><h1>foo</h1>');
|
|
455
441
|
});
|
|
456
|
-
test('/fallback-20140924', () =>
|
|
457
|
-
const router =
|
|
458
|
-
|
|
442
|
+
test('/fallback-20140924', async () => {
|
|
443
|
+
const router = createMemoryRouter(routes, { initialEntries: ['/fallback-20140924'] });
|
|
444
|
+
render(React.createElement(RouterProvider, { router: router }));
|
|
459
445
|
// render(
|
|
460
446
|
// <MemoryRouter initialEntries={['/fallback-20140924']}>
|
|
461
447
|
// {routes}
|
|
462
448
|
// </MemoryRouter>,
|
|
463
449
|
// );
|
|
464
|
-
expect((
|
|
465
|
-
})
|
|
450
|
+
expect((await screen.findByTestId('test')).innerHTML).toEqual('Fallback');
|
|
451
|
+
});
|
|
466
452
|
//# sourceMappingURL=render-routes.test.js.map
|