@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.
Files changed (148) hide show
  1. package/lib/__tests__/fill-register-test.js +6 -31
  2. package/lib/__tests__/fill-register-test.js.map +1 -1
  3. package/lib/__tests__/helpers/sample-menu.js +1 -4
  4. package/lib/__tests__/helpers/sample-menu.js.map +1 -1
  5. package/lib/__tests__/integrated-routes.test.js +14 -42
  6. package/lib/__tests__/integrated-routes.test.js.map +1 -1
  7. package/lib/__tests__/router-render.test.js +13 -57
  8. package/lib/__tests__/router-render.test.js.map +1 -1
  9. package/lib/connector/base-connector.js +24 -48
  10. package/lib/connector/base-connector.js.map +1 -1
  11. package/lib/connector/connector.d.ts +3 -2
  12. package/lib/connector/connector.js +9 -13
  13. package/lib/connector/connector.js.map +1 -1
  14. package/lib/connector/connector.native.js +10 -17
  15. package/lib/connector/connector.native.js.map +1 -1
  16. package/lib/connector/connector.test.js +5 -30
  17. package/lib/connector/connector.test.js.map +1 -1
  18. package/lib/connector/index.js +1 -17
  19. package/lib/connector/index.js.map +1 -1
  20. package/lib/index.js +10 -28
  21. package/lib/index.js.map +1 -1
  22. package/lib/index.native.js +10 -28
  23. package/lib/index.native.js.map +1 -1
  24. package/lib/interfaces/extended-feature.js +1 -2
  25. package/lib/interfaces/feature.js +1 -2
  26. package/lib/interfaces/index.js +5 -21
  27. package/lib/interfaces/index.js.map +1 -1
  28. package/lib/interfaces/menu.js +2 -5
  29. package/lib/interfaces/menu.js.map +1 -1
  30. package/lib/interfaces/new-router.d.ts +9 -3
  31. package/lib/interfaces/new-router.js +1 -2
  32. package/lib/interfaces/router.js +1 -2
  33. package/lib/inversify/InversifyContext.js +6 -34
  34. package/lib/inversify/InversifyContext.js.map +1 -1
  35. package/lib/inversify/index.js +1 -17
  36. package/lib/inversify/index.js.map +1 -1
  37. package/lib/plugin-area/__tests__/higher-order-component-util.test.js +12 -37
  38. package/lib/plugin-area/__tests__/higher-order-component-util.test.js.map +1 -1
  39. package/lib/plugin-area/__tests__/plugin-api.test.js +11 -13
  40. package/lib/plugin-area/__tests__/plugin-api.test.js.map +1 -1
  41. package/lib/plugin-area/base-plugin-area.js +12 -39
  42. package/lib/plugin-area/base-plugin-area.js.map +1 -1
  43. package/lib/plugin-area/higher-order-component-util.js +3 -7
  44. package/lib/plugin-area/higher-order-component-util.js.map +1 -1
  45. package/lib/plugin-area/index.js +5 -35
  46. package/lib/plugin-area/index.js.map +1 -1
  47. package/lib/plugin-area/index.native.js +7 -37
  48. package/lib/plugin-area/index.native.js.map +1 -1
  49. package/lib/plugin-area/plugin-api.js +15 -18
  50. package/lib/plugin-area/plugin-api.js.map +1 -1
  51. package/lib/plugin-area/plugin-context.js +5 -32
  52. package/lib/plugin-area/plugin-context.js.map +1 -1
  53. package/lib/route/__tests__/admin-new-routes.test.js +11 -45
  54. package/lib/route/__tests__/admin-new-routes.test.js.map +1 -1
  55. package/lib/route/__tests__/getFlatMenus.test.js +4 -6
  56. package/lib/route/__tests__/getFlatMenus.test.js.map +1 -1
  57. package/lib/route/__tests__/render-routes-config.test.js +6 -18
  58. package/lib/route/__tests__/render-routes-config.test.js.map +1 -1
  59. package/lib/route/__tests__/route-type.test.js +1 -2
  60. package/lib/route/__tests__/route-type.test.js.map +1 -1
  61. package/lib/route/get-routes.js +24 -31
  62. package/lib/route/get-routes.js.map +1 -1
  63. package/lib/route/get-routes.test.js +8 -19
  64. package/lib/route/get-routes.test.js.map +1 -1
  65. package/lib/route/index.js +2 -18
  66. package/lib/route/index.js.map +1 -1
  67. package/lib/route/index.native.d.ts +1 -1
  68. package/lib/route/index.native.js +1 -17
  69. package/lib/route/index.native.js.map +1 -1
  70. package/lib/route/old/__tests__/config-sidebar-menu.test.js +17 -15
  71. package/lib/route/old/__tests__/config-sidebar-menu.test.js.map +1 -1
  72. package/lib/route/old/get-menus.js +14 -21
  73. package/lib/route/old/get-menus.js.map +1 -1
  74. package/lib/route/old/get-routes-notused.js +15 -13
  75. package/lib/route/old/get-routes-notused.js.map +1 -1
  76. package/lib/route/old/render.d.ts +1 -1
  77. package/lib/route/old/render.js +7 -31
  78. package/lib/route/old/render.js.map +1 -1
  79. package/lib/route/react-navigation/get-navigation-utils.d.ts +8 -0
  80. package/lib/route/react-navigation/get-navigation-utils.js +35 -40
  81. package/lib/route/react-navigation/get-navigation-utils.js.map +1 -1
  82. package/lib/route/react-navigation/get-navigation-utils.test.js +15 -17
  83. package/lib/route/react-navigation/get-navigation-utils.test.js.map +1 -1
  84. package/lib/route/react-navigation/index.js +2 -18
  85. package/lib/route/react-navigation/index.js.map +1 -1
  86. package/lib/route/react-navigation/react-native.sample.test.js +8 -22
  87. package/lib/route/react-navigation/react-native.sample.test.js.map +1 -1
  88. package/lib/route/react-navigation/react-native.sample1.test.js +14 -48
  89. package/lib/route/react-navigation/react-native.sample1.test.js.map +1 -1
  90. package/lib/route/react-navigation/react-navigation-render.js +16 -31
  91. package/lib/route/react-navigation/react-navigation-render.js.map +1 -1
  92. package/lib/route/react-navigation/react-navigation-render.test.js +23 -37
  93. package/lib/route/react-navigation/react-navigation-render.test.js.map +1 -1
  94. package/lib/route/react-navigation/root-navigation.js +5 -9
  95. package/lib/route/react-navigation/root-navigation.js.map +1 -1
  96. package/lib/route/react-navigation/routes.js +1 -2
  97. package/lib/route/react-navigation/types.js +1 -5
  98. package/lib/route/react-navigation/types.js.map +1 -1
  99. package/lib/route/render-routes-native.d.ts +3 -0
  100. package/lib/route/render-routes-native.js +126 -0
  101. package/lib/route/render-routes-native.js.map +1 -0
  102. package/lib/route/render-routes.d.ts +1 -2
  103. package/lib/route/render-routes.js +132 -74
  104. package/lib/route/render-routes.js.map +1 -1
  105. package/lib/route/render-routes.test.js +317 -127
  106. package/lib/route/render-routes.test.js.map +1 -1
  107. package/lib/route/root-navigation.js +3 -7
  108. package/lib/route/root-navigation.js.map +1 -1
  109. package/lib/route/test-routes.d.ts +411 -0
  110. package/lib/route/test-routes.js +578 -0
  111. package/lib/route/test-routes.js.map +1 -0
  112. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js +12 -37
  113. package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js.map +1 -1
  114. package/lib/route-based-plugin-area/__tests__/plugin-api.test.js +11 -13
  115. package/lib/route-based-plugin-area/__tests__/plugin-api.test.js.map +1 -1
  116. package/lib/route-based-plugin-area/higher-order-component-util.js +3 -7
  117. package/lib/route-based-plugin-area/higher-order-component-util.js.map +1 -1
  118. package/lib/route-based-plugin-area/index.js +2 -18
  119. package/lib/route-based-plugin-area/index.js.map +1 -1
  120. package/lib/route-based-plugin-area/plugin-api.js +15 -18
  121. package/lib/route-based-plugin-area/plugin-api.js.map +1 -1
  122. package/lib/route-based-plugin-area/plugin-context.js +5 -32
  123. package/lib/route-based-plugin-area/plugin-context.js.map +1 -1
  124. package/lib/route-based-plugin-area/route-based-plugin-area.js +12 -39
  125. package/lib/route-based-plugin-area/route-based-plugin-area.js.map +1 -1
  126. package/lib/router-factory/index.js +5 -31
  127. package/lib/router-factory/index.js.map +1 -1
  128. package/lib/router-factory/index.native.js +5 -31
  129. package/lib/router-factory/index.native.js.map +1 -1
  130. package/lib/utils/before-ssr.js +6 -19
  131. package/lib/utils/before-ssr.js.map +1 -1
  132. package/lib/utils/combine.js +2 -6
  133. package/lib/utils/combine.js.map +1 -1
  134. package/lib/utils/hydrate.js +3 -7
  135. package/lib/utils/hydrate.js.map +1 -1
  136. package/lib/utils/index.js +5 -21
  137. package/lib/utils/index.js.map +1 -1
  138. package/lib/utils/sort-keys.d.ts +1 -0
  139. package/lib/utils/sort-keys.js +14 -10
  140. package/lib/utils/sort-keys.js.map +1 -1
  141. package/lib/utils/sort-keys.test.js +33 -7
  142. package/lib/utils/sort-keys.test.js.map +1 -1
  143. package/lib/utils/utils.js +1 -5
  144. package/lib/utils/utils.js.map +1 -1
  145. package/package.json +5 -4
  146. package/lib/route/render-routes.native.d.ts +0 -4
  147. package/lib/route/render-routes.native.js +0 -162
  148. package/lib/route/render-routes.native.js.map +0 -1
@@ -1,46 +1,32 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
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 react_2.default.createElement("h1", { "data-testid": "test" }, foo);
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
- react_2.default.useEffect(() => {
11
+ React.useEffect(() => {
26
12
  return () => {
27
13
  mountCount++;
28
14
  };
29
15
  }, []);
30
- return (react_2.default.createElement("div", null,
31
- react_2.default.createElement("h1", { "data-testid": "test2" }, foo),
32
- react_2.default.createElement("a", { href: "#bar" }, "link-bar"),
33
- react_2.default.createElement(react_router_dom_1.Link, { to: "/get-initial-props" }, "change-route"),
34
- react_2.default.createElement("h2", { id: "bar" }, "h2-bar")));
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
- react_2.default.useEffect(() => {
23
+ React.useEffect(() => {
38
24
  mountCount++;
39
25
  }, []);
40
26
  renderCount++;
41
- return react_2.default.createElement("h1", { "data-testid": "test" }, foo);
27
+ return React.createElement("h1", { "data-testid": "test" }, foo);
42
28
  }
43
- const getInitialProps = () => __awaiter(void 0, void 0, void 0, function* () {
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 (react_2.default.createElement(react_2.default.Fragment, null,
57
- react_2.default.createElement("h1", { "data-testid": "test-parent" }, foo),
42
+ return (React.createElement(React.Fragment, null,
43
+ React.createElement("h1", { "data-testid": "test-parent" }, foo),
58
44
  children));
59
45
  }
60
- TestInitialPropsParent.getInitialProps = () => __awaiter(void 0, void 0, void 0, function* () {
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) => (react_2.default.createElement(react_2.default.Fragment, null,
75
- react_2.default.createElement("h1", { "data-testid": "layout" }, "Layout"),
76
- react_2.default.createElement("h2", { "data-testid": "routes" }, props.routes.map((r) => r.path).join(',')),
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) => (react_2.default.createElement(react_2.default.Fragment, null,
82
- react_2.default.createElement("h1", { "data-testid": "test" }, "Foo"),
83
- react_2.default.createElement("h2", { "data-testid": "routes-embed" }, props.routes.map((r) => r.path).join(',')))),
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: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Foo"),
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
- return react_2.default.createElement("h1", { "data-testid": "test" }, props.match.params.id);
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
- { path: '/bar', component: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Bar") },
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: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Bar Exact"),
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: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Bar Strict"),
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: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Bar Sensitive"),
185
+ component: () => React.createElement("h1", { "data-testid": "test" }, "Bar Sensitive"),
117
186
  },
118
187
  { path: '/redirect', redirect: '/d' },
119
- { path: '/d', component: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Redirect") },
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) => (react_2.default.createElement("h1", { "data-testid": "test" }, `${props.route.path} ${props.route.foo}`)),
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 react_2.default.Children.map(props.children, (child) => {
148
- return react_2.default.cloneElement(child, { foo: 'bar' });
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) => react_2.default.createElement("h1", { "data-testid": "test" }, props.foo),
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: () => react_2.default.createElement("h1", null, "foo"),
229
+ component: () => React.createElement("h1", null, "foo"),
161
230
  wrappers: [
162
- (props) => (react_2.default.createElement(react_2.default.Fragment, null,
163
- react_2.default.createElement("h1", null,
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) => (react_2.default.createElement(react_2.default.Fragment, null,
168
- react_2.default.createElement("h1", null, "wrapper 2"),
236
+ (props) => (React.createElement(React.Fragment, null,
237
+ React.createElement("h1", null, "wrapper 2"),
169
238
  props.children)),
170
239
  ],
171
240
  },
172
- { component: () => react_2.default.createElement("h1", { "data-testid": "test" }, "Fallback") },
241
+ { component: () => React.createElement("h1", { "data-testid": "test" }, "Fallback") },
173
242
  ],
174
243
  // plugin: new Plugin(),
175
244
  };
176
- let routes = (0, render_routes_1.renderRoutes2)(routerConfig);
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(() => __awaiter(void 0, void 0, void 0, function* () {
270
+ afterEach(async () => {
184
271
  delete window.g_useSSR;
185
272
  delete window.g_initialProps;
186
- yield (0, react_1.cleanup)();
187
- }));
188
- test('/layout', () => __awaiter(void 0, void 0, void 0, function* () {
189
- const { container } = (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/layout'] }, routes));
190
- expect(container).toMatchSnapshot();
191
- expect((yield react_1.screen.findByTestId('layout')).innerHTML).toEqual('Layout');
192
- expect((yield react_1.screen.findByTestId('routes')).innerHTML).toContain('/layout,/layout-without-component,/users/:id');
193
- expect((yield react_1.screen.findByTestId('routes-embed')).innerHTML).toContain('/layout,/layout-without-component,/users/:id');
194
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Foo');
195
- }));
196
- test('/layout-without-component', () => __awaiter(void 0, void 0, void 0, function* () {
197
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/layout-without-component/foo'] }, routes));
198
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Foo');
199
- }));
200
- test('/bar', () => __awaiter(void 0, void 0, void 0, function* () {
201
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/bar'] }, routes));
202
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Bar');
203
- }));
204
- test('/BAR', () => __awaiter(void 0, void 0, void 0, function* () {
205
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/BAR'] }, routes));
206
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Bar');
207
- }));
208
- test('/bar-exact/foo', () => __awaiter(void 0, void 0, void 0, function* () {
209
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/bar-exact/foo'] }, routes));
210
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Fallback');
211
- }));
212
- test('/bar-strict', () => __awaiter(void 0, void 0, void 0, function* () {
213
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/bar-strict'] }, routes));
214
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Fallback');
215
- }));
216
- test('/BAR-sensitive', () => __awaiter(void 0, void 0, void 0, function* () {
217
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/BAR-sensitive'] }, routes));
218
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Fallback');
219
- }));
220
- test('/users/123', () => __awaiter(void 0, void 0, void 0, function* () {
221
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/users/123'] }, routes));
222
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('123');
223
- }));
224
- test('/redirect', () => __awaiter(void 0, void 0, void 0, function* () {
225
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/redirect'] }, routes));
226
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Redirect');
227
- }));
228
- test('/props-route', () => __awaiter(void 0, void 0, void 0, function* () {
229
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/props-route'] }, routes));
230
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('/props-route bar');
231
- }));
232
- test('/pass-props', () => __awaiter(void 0, void 0, void 0, function* () {
233
- const { container } = (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/pass-props'] }, routes));
234
- yield (0, react_1.waitFor)(() => (0, react_1.getByText)(container, 'bar'));
235
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('bar');
236
- }));
237
- test('/get-initial-props-with-mount', () => __awaiter(void 0, void 0, void 0, function* () {
238
- const newRoutes = (0, render_routes_1.renderRoutes2)(routerConfig);
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 } = (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/get-initial-props-with-mount'] }, newRoutes));
242
- yield (0, react_1.waitFor)(() => (0, react_1.getByText)(container, 'bar'));
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', () => __awaiter(void 0, void 0, void 0, function* () {
247
- const newRoutes = (0, render_routes_1.renderRoutes2)(routerConfig);
248
- const { container } = (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/get-initial-props-embed'] }, newRoutes));
249
- yield (0, react_1.waitFor)(() => (0, react_1.getByText)(container, 'bar'));
250
- yield (0, react_1.waitFor)(() => (0, react_1.getByText)(container, 'parent'));
251
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('bar');
252
- expect((yield react_1.screen.findByTestId('test-parent')).innerHTML).toEqual('parent');
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 { container } = (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/wrappers'] }, routes));
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', () => __awaiter(void 0, void 0, void 0, function* () {
259
- (0, react_1.render)(react_2.default.createElement(react_router_dom_1.MemoryRouter, { initialEntries: ['/fallback-20140924'] }, routes));
260
- expect((yield react_1.screen.findByTestId('test')).innerHTML).toEqual('Fallback');
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