one 1.1.473 → 1.1.475

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 (245) hide show
  1. package/dist/cjs/Root.cjs +5 -1
  2. package/dist/cjs/Root.js +2 -2
  3. package/dist/cjs/Root.js.map +1 -1
  4. package/dist/cjs/Root.native.js +5 -2
  5. package/dist/cjs/Root.native.js.map +2 -2
  6. package/dist/cjs/createApp.cjs +2 -0
  7. package/dist/cjs/createApp.js +16 -2
  8. package/dist/cjs/createApp.js.map +1 -1
  9. package/dist/cjs/createApp.native.js +1 -0
  10. package/dist/cjs/createApp.native.js.map +2 -2
  11. package/dist/cjs/fork/__tests__/getPathFromState.test.cjs +1440 -0
  12. package/dist/cjs/fork/__tests__/getPathFromState.test.js +1559 -0
  13. package/dist/cjs/fork/__tests__/getPathFromState.test.js.map +6 -0
  14. package/dist/cjs/fork/__tests__/getPathFromState.test.native.js +1726 -0
  15. package/dist/cjs/fork/__tests__/getPathFromState.test.native.js.map +6 -0
  16. package/dist/cjs/fork/__tests__/getStateFromPath.test.cjs +2565 -0
  17. package/dist/cjs/fork/__tests__/getStateFromPath.test.js +2702 -0
  18. package/dist/cjs/fork/__tests__/getStateFromPath.test.js.map +6 -0
  19. package/dist/cjs/fork/__tests__/getStateFromPath.test.native.js +2861 -0
  20. package/dist/cjs/fork/__tests__/getStateFromPath.test.native.js.map +6 -0
  21. package/dist/cjs/fork/getPathFromState.cjs +2 -1
  22. package/dist/cjs/fork/getPathFromState.js +1 -1
  23. package/dist/cjs/fork/getPathFromState.js.map +1 -1
  24. package/dist/cjs/fork/getPathFromState.native.js +10 -5
  25. package/dist/cjs/fork/getPathFromState.native.js.map +1 -1
  26. package/dist/cjs/fork/getPathFromState.test.cjs +113 -0
  27. package/dist/cjs/fork/getPathFromState.test.js +122 -0
  28. package/dist/cjs/fork/getPathFromState.test.js.map +6 -0
  29. package/dist/cjs/fork/getPathFromState.test.native.js +135 -0
  30. package/dist/cjs/fork/getPathFromState.test.native.js.map +6 -0
  31. package/dist/cjs/fork/getStateFromPath.test.cjs +229 -0
  32. package/dist/cjs/fork/getStateFromPath.test.js +290 -0
  33. package/dist/cjs/fork/getStateFromPath.test.js.map +6 -0
  34. package/dist/cjs/fork/getStateFromPath.test.native.js +374 -0
  35. package/dist/cjs/fork/getStateFromPath.test.native.js.map +6 -0
  36. package/dist/cjs/render.cjs +1 -1
  37. package/dist/cjs/render.js +1 -1
  38. package/dist/cjs/render.js.map +1 -1
  39. package/dist/cjs/router/FlagsContext.cjs +27 -0
  40. package/dist/cjs/router/FlagsContext.js +22 -0
  41. package/dist/cjs/router/FlagsContext.js.map +6 -0
  42. package/dist/cjs/router/FlagsContext.native.js +26 -0
  43. package/dist/cjs/router/FlagsContext.native.js.map +6 -0
  44. package/dist/cjs/router/getRoutes.cjs +11 -1
  45. package/dist/cjs/router/getRoutes.js +11 -1
  46. package/dist/cjs/router/getRoutes.js.map +1 -1
  47. package/dist/cjs/router/getRoutes.native.js +11 -1
  48. package/dist/cjs/router/getRoutes.native.js.map +2 -2
  49. package/dist/cjs/router/matchers.test.cjs +38 -0
  50. package/dist/cjs/router/matchers.test.js +42 -0
  51. package/dist/cjs/router/matchers.test.js.map +6 -0
  52. package/dist/cjs/router/matchers.test.native.js +39 -0
  53. package/dist/cjs/router/matchers.test.native.js.map +6 -0
  54. package/dist/cjs/router/router.cjs +3 -35
  55. package/dist/cjs/router/router.js +2 -26
  56. package/dist/cjs/router/router.js.map +1 -1
  57. package/dist/cjs/router/router.native.js +2 -33
  58. package/dist/cjs/router/router.native.js.map +2 -2
  59. package/dist/cjs/router/utils/getNavigateAction.cjs +61 -0
  60. package/dist/cjs/router/utils/getNavigateAction.js +46 -0
  61. package/dist/cjs/router/utils/getNavigateAction.js.map +6 -0
  62. package/dist/cjs/router/utils/getNavigateAction.native.js +58 -0
  63. package/dist/cjs/router/utils/getNavigateAction.native.js.map +6 -0
  64. package/dist/cjs/router/utils/getNavigateAction.test.cjs +259 -0
  65. package/dist/cjs/router/utils/getNavigateAction.test.js +295 -0
  66. package/dist/cjs/router/utils/getNavigateAction.test.js.map +6 -0
  67. package/dist/cjs/router/utils/getNavigateAction.test.native.js +330 -0
  68. package/dist/cjs/router/utils/getNavigateAction.test.native.js.map +6 -0
  69. package/dist/cjs/testing-utils.cjs +63 -0
  70. package/dist/cjs/testing-utils.js +55 -0
  71. package/dist/cjs/testing-utils.js.map +6 -0
  72. package/dist/cjs/testing-utils.native.js +79 -0
  73. package/dist/cjs/testing-utils.native.js.map +6 -0
  74. package/dist/cjs/views/Navigator.cjs +8 -1
  75. package/dist/cjs/views/Navigator.js +25 -11
  76. package/dist/cjs/views/Navigator.js.map +1 -1
  77. package/dist/cjs/views/Navigator.native.js +7 -4
  78. package/dist/cjs/views/Navigator.native.js.map +2 -2
  79. package/dist/cjs/vite/one.cjs +6 -1
  80. package/dist/cjs/vite/one.js +6 -1
  81. package/dist/cjs/vite/one.js.map +1 -1
  82. package/dist/cjs/vite/one.native.js +7 -2
  83. package/dist/cjs/vite/one.native.js.map +2 -2
  84. package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +2 -0
  85. package/dist/cjs/vite/plugins/virtualEntryPlugin.js +2 -0
  86. package/dist/cjs/vite/plugins/virtualEntryPlugin.js.map +1 -1
  87. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +2 -0
  88. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +2 -2
  89. package/dist/esm/Root.js +2 -1
  90. package/dist/esm/Root.js.map +1 -1
  91. package/dist/esm/Root.mjs +5 -1
  92. package/dist/esm/Root.mjs.map +1 -1
  93. package/dist/esm/Root.native.js +5 -1
  94. package/dist/esm/Root.native.js.map +1 -1
  95. package/dist/esm/createApp.js +16 -2
  96. package/dist/esm/createApp.js.map +1 -1
  97. package/dist/esm/createApp.mjs +2 -0
  98. package/dist/esm/createApp.mjs.map +1 -1
  99. package/dist/esm/createApp.native.js +1 -0
  100. package/dist/esm/createApp.native.js.map +1 -1
  101. package/dist/esm/fork/__tests__/getPathFromState.test.js +1561 -0
  102. package/dist/esm/fork/__tests__/getPathFromState.test.js.map +6 -0
  103. package/dist/esm/fork/__tests__/getPathFromState.test.mjs +1441 -0
  104. package/dist/esm/fork/__tests__/getPathFromState.test.mjs.map +1 -0
  105. package/dist/esm/fork/__tests__/getPathFromState.test.native.js +1580 -0
  106. package/dist/esm/fork/__tests__/getPathFromState.test.native.js.map +1 -0
  107. package/dist/esm/fork/__tests__/getStateFromPath.test.js +2706 -0
  108. package/dist/esm/fork/__tests__/getStateFromPath.test.js.map +6 -0
  109. package/dist/esm/fork/__tests__/getStateFromPath.test.mjs +2566 -0
  110. package/dist/esm/fork/__tests__/getStateFromPath.test.mjs.map +1 -0
  111. package/dist/esm/fork/__tests__/getStateFromPath.test.native.js +2636 -0
  112. package/dist/esm/fork/__tests__/getStateFromPath.test.native.js.map +1 -0
  113. package/dist/esm/fork/getPathFromState.js +1 -1
  114. package/dist/esm/fork/getPathFromState.js.map +1 -1
  115. package/dist/esm/fork/getPathFromState.mjs +2 -1
  116. package/dist/esm/fork/getPathFromState.mjs.map +1 -1
  117. package/dist/esm/fork/getPathFromState.native.js +9 -5
  118. package/dist/esm/fork/getPathFromState.native.js.map +1 -1
  119. package/dist/esm/fork/getPathFromState.test.js +123 -0
  120. package/dist/esm/fork/getPathFromState.test.js.map +6 -0
  121. package/dist/esm/fork/getPathFromState.test.mjs +114 -0
  122. package/dist/esm/fork/getPathFromState.test.mjs.map +1 -0
  123. package/dist/esm/fork/getPathFromState.test.native.js +122 -0
  124. package/dist/esm/fork/getPathFromState.test.native.js.map +1 -0
  125. package/dist/esm/fork/getStateFromPath.test.js +294 -0
  126. package/dist/esm/fork/getStateFromPath.test.js.map +6 -0
  127. package/dist/esm/fork/getStateFromPath.test.mjs +230 -0
  128. package/dist/esm/fork/getStateFromPath.test.mjs.map +1 -0
  129. package/dist/esm/fork/getStateFromPath.test.native.js +233 -0
  130. package/dist/esm/fork/getStateFromPath.test.native.js.map +1 -0
  131. package/dist/esm/render.js +1 -1
  132. package/dist/esm/render.js.map +1 -1
  133. package/dist/esm/render.mjs +1 -1
  134. package/dist/esm/render.mjs.map +1 -1
  135. package/dist/esm/router/FlagsContext.js +6 -0
  136. package/dist/esm/router/FlagsContext.js.map +6 -0
  137. package/dist/esm/router/FlagsContext.mjs +4 -0
  138. package/dist/esm/router/FlagsContext.mjs.map +1 -0
  139. package/dist/esm/router/FlagsContext.native.js +4 -0
  140. package/dist/esm/router/FlagsContext.native.js.map +1 -0
  141. package/dist/esm/router/getRoutes.js +11 -1
  142. package/dist/esm/router/getRoutes.js.map +1 -1
  143. package/dist/esm/router/getRoutes.mjs +11 -1
  144. package/dist/esm/router/getRoutes.mjs.map +1 -1
  145. package/dist/esm/router/getRoutes.native.js +11 -1
  146. package/dist/esm/router/getRoutes.native.js.map +1 -1
  147. package/dist/esm/router/matchers.test.js +50 -0
  148. package/dist/esm/router/matchers.test.js.map +6 -0
  149. package/dist/esm/router/matchers.test.mjs +39 -0
  150. package/dist/esm/router/matchers.test.mjs.map +1 -0
  151. package/dist/esm/router/matchers.test.native.js +39 -0
  152. package/dist/esm/router/matchers.test.native.js.map +1 -0
  153. package/dist/esm/router/router.js +1 -26
  154. package/dist/esm/router/router.js.map +1 -1
  155. package/dist/esm/router/router.mjs +1 -33
  156. package/dist/esm/router/router.mjs.map +1 -1
  157. package/dist/esm/router/router.native.js +1 -37
  158. package/dist/esm/router/router.native.js.map +1 -1
  159. package/dist/esm/router/utils/getNavigateAction.js +32 -0
  160. package/dist/esm/router/utils/getNavigateAction.js.map +6 -0
  161. package/dist/esm/router/utils/getNavigateAction.mjs +38 -0
  162. package/dist/esm/router/utils/getNavigateAction.mjs.map +1 -0
  163. package/dist/esm/router/utils/getNavigateAction.native.js +42 -0
  164. package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -0
  165. package/dist/esm/router/utils/getNavigateAction.test.js +296 -0
  166. package/dist/esm/router/utils/getNavigateAction.test.js.map +6 -0
  167. package/dist/esm/router/utils/getNavigateAction.test.mjs +260 -0
  168. package/dist/esm/router/utils/getNavigateAction.test.mjs.map +1 -0
  169. package/dist/esm/router/utils/getNavigateAction.test.native.js +273 -0
  170. package/dist/esm/router/utils/getNavigateAction.test.native.js.map +1 -0
  171. package/dist/esm/testing-utils.js +33 -0
  172. package/dist/esm/testing-utils.js.map +6 -0
  173. package/dist/esm/testing-utils.mjs +27 -0
  174. package/dist/esm/testing-utils.mjs.map +1 -0
  175. package/dist/esm/testing-utils.native.js +38 -0
  176. package/dist/esm/testing-utils.native.js.map +1 -0
  177. package/dist/esm/views/Navigator.js +29 -11
  178. package/dist/esm/views/Navigator.js.map +1 -1
  179. package/dist/esm/views/Navigator.mjs +8 -1
  180. package/dist/esm/views/Navigator.mjs.map +1 -1
  181. package/dist/esm/views/Navigator.native.js +8 -2
  182. package/dist/esm/views/Navigator.native.js.map +1 -1
  183. package/dist/esm/vite/one.js +6 -1
  184. package/dist/esm/vite/one.js.map +1 -1
  185. package/dist/esm/vite/one.mjs +6 -1
  186. package/dist/esm/vite/one.mjs.map +1 -1
  187. package/dist/esm/vite/one.native.js +9 -2
  188. package/dist/esm/vite/one.native.js.map +1 -1
  189. package/dist/esm/vite/plugins/virtualEntryPlugin.js +2 -0
  190. package/dist/esm/vite/plugins/virtualEntryPlugin.js.map +1 -1
  191. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +2 -0
  192. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
  193. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +2 -0
  194. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  195. package/package.json +13 -10
  196. package/src/Root.tsx +12 -2
  197. package/src/createApp.native.tsx +8 -2
  198. package/src/createApp.tsx +18 -3
  199. package/src/fork/__tests__/README.md +8 -0
  200. package/src/fork/__tests__/getPathFromState.test.tsx +1809 -0
  201. package/src/fork/__tests__/getStateFromPath.test.tsx +3188 -0
  202. package/src/fork/getPathFromState.test.ts +146 -0
  203. package/src/fork/getPathFromState.ts +1 -1
  204. package/src/fork/getStateFromPath.test.ts +345 -0
  205. package/src/render.tsx +3 -3
  206. package/src/router/FlagsContext.ts +4 -0
  207. package/src/router/getRoutes.ts +14 -2
  208. package/src/router/matchers.test.ts +120 -0
  209. package/src/router/router.ts +1 -113
  210. package/src/router/utils/getNavigateAction.test.ts +334 -0
  211. package/src/router/utils/getNavigateAction.ts +120 -0
  212. package/src/testing-utils.ts +56 -0
  213. package/src/views/Navigator.tsx +34 -10
  214. package/src/vite/one.ts +5 -0
  215. package/src/vite/plugins/virtualEntryPlugin.ts +4 -1
  216. package/src/vite/types.ts +18 -0
  217. package/types/Root.d.ts +1 -0
  218. package/types/Root.d.ts.map +1 -1
  219. package/types/createApp.d.ts +2 -0
  220. package/types/createApp.d.ts.map +1 -1
  221. package/types/createApp.native.d.ts +2 -0
  222. package/types/createApp.native.d.ts.map +1 -1
  223. package/types/fork/getPathFromState.test.d.ts +2 -0
  224. package/types/fork/getPathFromState.test.d.ts.map +1 -0
  225. package/types/fork/getStateFromPath.test.d.ts +2 -0
  226. package/types/fork/getStateFromPath.test.d.ts.map +1 -0
  227. package/types/router/FlagsContext.d.ts +3 -0
  228. package/types/router/FlagsContext.d.ts.map +1 -0
  229. package/types/router/getRoutes.d.ts.map +1 -1
  230. package/types/router/matchers.test.d.ts +2 -0
  231. package/types/router/matchers.test.d.ts.map +1 -0
  232. package/types/router/router.d.ts.map +1 -1
  233. package/types/router/utils/getNavigateAction.d.ts +17 -0
  234. package/types/router/utils/getNavigateAction.d.ts.map +1 -0
  235. package/types/router/utils/getNavigateAction.test.d.ts +2 -0
  236. package/types/router/utils/getNavigateAction.test.d.ts.map +1 -0
  237. package/types/testing-utils.d.ts +26 -0
  238. package/types/testing-utils.d.ts.map +1 -0
  239. package/types/views/Navigator.d.ts +1 -1
  240. package/types/views/Navigator.d.ts.map +1 -1
  241. package/types/vite/one.d.ts.map +1 -1
  242. package/types/vite/plugins/virtualEntryPlugin.d.ts +2 -0
  243. package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
  244. package/types/vite/types.d.ts +16 -0
  245. package/types/vite/types.d.ts.map +1 -1
@@ -0,0 +1,2636 @@
1
+ import { expect, test } from "vitest";
2
+ import { produce } from "immer";
3
+ import { findFocusedRoute } from "../findFocusedRoute.native.js";
4
+ import { getPathFromState } from "../getPathFromState.native.js";
5
+ import { getStateFromPath } from "../getStateFromPath.native.js";
6
+ var changePath = function (state, path) {
7
+ return produce(state, function (draftState) {
8
+ var route = findFocusedRoute(draftState);
9
+ route.path = path;
10
+ });
11
+ };
12
+ test("returns undefined for invalid path", function () {
13
+ expect(getStateFromPath("//")).toBeUndefined();
14
+ });
15
+ test.skip("converts path string to initial state", function () {
16
+ var path = "foo/bar/baz%20qux?author=jane%20%26%20co&valid=true",
17
+ state = {
18
+ routes: [{
19
+ name: "foo",
20
+ state: {
21
+ routes: [{
22
+ name: "bar",
23
+ state: {
24
+ routes: [{
25
+ name: "baz qux",
26
+ params: {
27
+ author: "jane & co",
28
+ valid: "true"
29
+ },
30
+ path
31
+ }]
32
+ }
33
+ }]
34
+ }
35
+ }]
36
+ };
37
+ expect(getStateFromPath(path)).toEqual(state), expect(getStateFromPath(getPathFromState(state))).toEqual(changePath(state, "/foo/bar/baz%20qux?author=jane%20%26%20co&valid=true"));
38
+ });
39
+ test.skip("decodes encoded params in path", function () {
40
+ var path = "/foo/bar/bar_%23_foo",
41
+ config = {
42
+ screens: {
43
+ Foo: {
44
+ path: "foo",
45
+ screens: {
46
+ Bar: {
47
+ path: "/bar/:id"
48
+ }
49
+ }
50
+ }
51
+ }
52
+ },
53
+ state = {
54
+ routes: [{
55
+ name: "Foo",
56
+ state: {
57
+ routes: [{
58
+ name: "Bar",
59
+ params: {
60
+ id: "bar_#_foo"
61
+ },
62
+ path
63
+ }]
64
+ }
65
+ }]
66
+ };
67
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getPathFromState(getStateFromPath(path, config), config)).toEqual(path);
68
+ });
69
+ test.skip("decodes encoded params in path that have encoded /", function () {
70
+ var path = "/foo/bar/bar_%2F_foo",
71
+ config = {
72
+ screens: {
73
+ Foo: {
74
+ path: "foo",
75
+ screens: {
76
+ Bar: {
77
+ path: "/bar/:id"
78
+ }
79
+ }
80
+ }
81
+ }
82
+ },
83
+ state = {
84
+ routes: [{
85
+ name: "Foo",
86
+ state: {
87
+ routes: [{
88
+ name: "Bar",
89
+ params: {
90
+ id: "bar_/_foo"
91
+ },
92
+ path
93
+ }]
94
+ }
95
+ }]
96
+ };
97
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getPathFromState(getStateFromPath(path, config), config)).toEqual(path);
98
+ });
99
+ test.skip("converts path string to initial state with config", function () {
100
+ var path = "/foo/bar/sweet/apple/baz/jane?count=10&answer=42&valid=true",
101
+ config = {
102
+ screens: {
103
+ Foo: {
104
+ path: "foo",
105
+ screens: {
106
+ Bar: {
107
+ path: "bar/:type/:fruit",
108
+ screens: {
109
+ Baz: {
110
+ path: "baz/:author",
111
+ parse: {
112
+ author: function (author) {
113
+ return author.replace(/^\w/, function (c) {
114
+ return c.toUpperCase();
115
+ });
116
+ },
117
+ count: Number,
118
+ valid: Boolean
119
+ },
120
+ stringify: {
121
+ author: function (author) {
122
+ return author.toLowerCase();
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ },
132
+ state = {
133
+ routes: [{
134
+ name: "Foo",
135
+ state: {
136
+ routes: [{
137
+ name: "Bar",
138
+ params: {
139
+ fruit: "apple",
140
+ type: "sweet"
141
+ },
142
+ state: {
143
+ routes: [{
144
+ name: "Baz",
145
+ params: {
146
+ author: "Jane",
147
+ count: 10,
148
+ answer: "42",
149
+ valid: !0
150
+ },
151
+ path
152
+ }]
153
+ }
154
+ }]
155
+ }
156
+ }]
157
+ };
158
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
159
+ });
160
+ test("handles leading slash when converting", function () {
161
+ var path = "/foo/bar/?count=42";
162
+ expect(getStateFromPath(path)).toEqual({
163
+ routes: [{
164
+ name: "foo",
165
+ state: {
166
+ routes: [{
167
+ name: "bar",
168
+ params: {
169
+ count: "42"
170
+ },
171
+ path
172
+ }]
173
+ }
174
+ }]
175
+ });
176
+ });
177
+ test("handles ending slash when converting", function () {
178
+ var path = "foo/bar/?count=42";
179
+ expect(getStateFromPath(path)).toEqual({
180
+ routes: [{
181
+ name: "foo",
182
+ state: {
183
+ routes: [{
184
+ name: "bar",
185
+ params: {
186
+ count: "42"
187
+ },
188
+ path
189
+ }]
190
+ }
191
+ }]
192
+ });
193
+ });
194
+ test("handles route without param", function () {
195
+ var path = "foo/bar",
196
+ state = {
197
+ routes: [{
198
+ name: "foo",
199
+ state: {
200
+ routes: [{
201
+ name: "bar",
202
+ path
203
+ }]
204
+ }
205
+ }]
206
+ };
207
+ expect(getStateFromPath(path)).toEqual(state), expect(getStateFromPath(getPathFromState(state))).toEqual(changePath(state, "/foo/bar"));
208
+ });
209
+ test.skip("converts path string to initial state with config with nested screens", function () {
210
+ var path = "/foe/bar/sweet/apple/baz/jane?count=10&answer=42&valid=true",
211
+ config = {
212
+ screens: {
213
+ Foo: {
214
+ path: "foo",
215
+ screens: {
216
+ Foe: {
217
+ path: "foe",
218
+ exact: !0,
219
+ screens: {
220
+ Bar: {
221
+ path: "bar/:type/:fruit",
222
+ screens: {
223
+ Baz: {
224
+ path: "baz/:author",
225
+ parse: {
226
+ author: function (author) {
227
+ return author.replace(/^\w/, function (c) {
228
+ return c.toUpperCase();
229
+ });
230
+ },
231
+ count: Number,
232
+ valid: Boolean
233
+ },
234
+ stringify: {
235
+ author: function (author) {
236
+ return author.toLowerCase();
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ },
248
+ state = {
249
+ routes: [{
250
+ name: "Foo",
251
+ state: {
252
+ routes: [{
253
+ name: "Foe",
254
+ state: {
255
+ routes: [{
256
+ name: "Bar",
257
+ params: {
258
+ fruit: "apple",
259
+ type: "sweet"
260
+ },
261
+ state: {
262
+ routes: [{
263
+ name: "Baz",
264
+ params: {
265
+ author: "Jane",
266
+ count: 10,
267
+ answer: "42",
268
+ valid: !0
269
+ },
270
+ path
271
+ }]
272
+ }
273
+ }]
274
+ }
275
+ }]
276
+ }
277
+ }]
278
+ };
279
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
280
+ });
281
+ test.skip("converts path string to initial state with config with nested screens and unused parse functions", function () {
282
+ var path = "/foe/baz/jane?count=10&answer=42&valid=true",
283
+ config = {
284
+ screens: {
285
+ Foo: {
286
+ path: "foo",
287
+ screens: {
288
+ Foe: {
289
+ path: "foe",
290
+ exact: !0,
291
+ screens: {
292
+ Baz: {
293
+ path: "baz/:author",
294
+ parse: {
295
+ author: function (author) {
296
+ return author.replace(/^\w/, function (c) {
297
+ return c.toUpperCase();
298
+ });
299
+ },
300
+ count: Number,
301
+ valid: Boolean,
302
+ id: Boolean
303
+ }
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ },
311
+ state = {
312
+ routes: [{
313
+ name: "Foo",
314
+ state: {
315
+ routes: [{
316
+ name: "Foe",
317
+ state: {
318
+ routes: [{
319
+ name: "Baz",
320
+ params: {
321
+ author: "Jane",
322
+ count: 10,
323
+ answer: "42",
324
+ valid: !0
325
+ },
326
+ path
327
+ }]
328
+ }
329
+ }]
330
+ }
331
+ }]
332
+ };
333
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/foe/baz/Jane?count=10&answer=42&valid=true"));
334
+ });
335
+ test.skip("handles nested object with unused configs and with parse in it", function () {
336
+ var path = "/bar/sweet/apple/foe/bis/jane?count=10&answer=42&valid=true",
337
+ config = {
338
+ screens: {
339
+ Bar: {
340
+ path: "bar/:type/:fruit",
341
+ screens: {
342
+ Foo: {
343
+ screens: {
344
+ Foe: {
345
+ path: "foe",
346
+ screens: {
347
+ Baz: {
348
+ screens: {
349
+ Bos: {
350
+ path: "bos",
351
+ exact: !0
352
+ },
353
+ Bis: {
354
+ path: "bis/:author",
355
+ stringify: {
356
+ author: function (author) {
357
+ return author.replace(/^\w/, function (c) {
358
+ return c.toLowerCase();
359
+ });
360
+ }
361
+ },
362
+ parse: {
363
+ author: function (author) {
364
+ return author.replace(/^\w/, function (c) {
365
+ return c.toUpperCase();
366
+ });
367
+ },
368
+ count: Number,
369
+ valid: Boolean
370
+ }
371
+ }
372
+ }
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+ }
379
+ }
380
+ }
381
+ },
382
+ state = {
383
+ routes: [{
384
+ name: "Bar",
385
+ params: {
386
+ fruit: "apple",
387
+ type: "sweet"
388
+ },
389
+ state: {
390
+ routes: [{
391
+ name: "Foo",
392
+ state: {
393
+ routes: [{
394
+ name: "Foe",
395
+ state: {
396
+ routes: [{
397
+ name: "Baz",
398
+ state: {
399
+ routes: [{
400
+ name: "Bis",
401
+ params: {
402
+ author: "Jane",
403
+ count: 10,
404
+ answer: "42",
405
+ valid: !0
406
+ },
407
+ path
408
+ }]
409
+ }
410
+ }]
411
+ }
412
+ }]
413
+ }
414
+ }]
415
+ }
416
+ }]
417
+ };
418
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
419
+ });
420
+ test("handles parse in nested object for second route depth", function () {
421
+ var path = "/baz",
422
+ config = {
423
+ screens: {
424
+ Foo: {
425
+ path: "foo",
426
+ screens: {
427
+ Foe: {
428
+ path: "foe",
429
+ exact: !0
430
+ },
431
+ Bar: {
432
+ path: "bar",
433
+ exact: !0,
434
+ screens: {
435
+ Baz: {
436
+ path: "baz",
437
+ exact: !0
438
+ }
439
+ }
440
+ }
441
+ }
442
+ }
443
+ }
444
+ },
445
+ state = {
446
+ routes: [{
447
+ name: "Foo",
448
+ state: {
449
+ routes: [{
450
+ name: "Bar",
451
+ state: {
452
+ routes: [{
453
+ name: "Baz",
454
+ path
455
+ }]
456
+ }
457
+ }]
458
+ }
459
+ }]
460
+ };
461
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
462
+ });
463
+ test("handles parse in nested object for second route depth and and path and parse in roots", function () {
464
+ var path = "/baz",
465
+ config = {
466
+ screens: {
467
+ Foo: {
468
+ path: "foo/:id",
469
+ parse: {
470
+ id: Number
471
+ },
472
+ stringify: {
473
+ id: function (id) {
474
+ return `id=${id}`;
475
+ }
476
+ },
477
+ screens: {
478
+ Foe: "foe",
479
+ Bar: {
480
+ screens: {
481
+ Baz: {
482
+ path: "baz",
483
+ exact: !0
484
+ }
485
+ }
486
+ }
487
+ }
488
+ }
489
+ }
490
+ },
491
+ state = {
492
+ routes: [{
493
+ name: "Foo",
494
+ state: {
495
+ routes: [{
496
+ name: "Bar",
497
+ state: {
498
+ routes: [{
499
+ name: "Baz",
500
+ path
501
+ }]
502
+ }
503
+ }]
504
+ }
505
+ }]
506
+ };
507
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
508
+ });
509
+ test.skip("handles path at top level", function () {
510
+ var path = "/foo/fruits/apple",
511
+ config = {
512
+ path: "foo",
513
+ screens: {
514
+ Foo: {
515
+ screens: {
516
+ Fruits: "fruits/:fruit"
517
+ }
518
+ }
519
+ }
520
+ },
521
+ state = {
522
+ routes: [{
523
+ name: "Foo",
524
+ state: {
525
+ routes: [{
526
+ name: "Fruits",
527
+ params: {
528
+ fruit: "apple"
529
+ },
530
+ path
531
+ }]
532
+ }
533
+ }]
534
+ };
535
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
536
+ });
537
+ test("handles initialRouteName at top level", function () {
538
+ var path = "/baz",
539
+ config = {
540
+ initialRouteName: "Boo",
541
+ screens: {
542
+ Foo: {
543
+ screens: {
544
+ Foe: "foe",
545
+ Bar: {
546
+ screens: {
547
+ Baz: "baz"
548
+ }
549
+ }
550
+ }
551
+ }
552
+ }
553
+ },
554
+ state = {
555
+ index: 1,
556
+ routes: [{
557
+ name: "Boo"
558
+ }, {
559
+ name: "Foo",
560
+ state: {
561
+ routes: [{
562
+ name: "Bar",
563
+ state: {
564
+ routes: [{
565
+ name: "Baz",
566
+ path
567
+ }]
568
+ }
569
+ }]
570
+ }
571
+ }]
572
+ };
573
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
574
+ });
575
+ test("handles initialRouteName inside a screen", function () {
576
+ var path = "/baz",
577
+ config = {
578
+ screens: {
579
+ Foo: {
580
+ initialRouteName: "Foe",
581
+ screens: {
582
+ Foe: "foe",
583
+ Bar: {
584
+ screens: {
585
+ Baz: "baz"
586
+ }
587
+ }
588
+ }
589
+ }
590
+ }
591
+ },
592
+ state = {
593
+ routes: [{
594
+ name: "Foo",
595
+ state: {
596
+ index: 1,
597
+ routes: [{
598
+ name: "Foe"
599
+ }, {
600
+ name: "Bar",
601
+ state: {
602
+ routes: [{
603
+ name: "Baz",
604
+ path
605
+ }]
606
+ }
607
+ }]
608
+ }
609
+ }]
610
+ };
611
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
612
+ });
613
+ test("handles initialRouteName included in path", function () {
614
+ var path = "/baz",
615
+ config = {
616
+ screens: {
617
+ Foo: {
618
+ initialRouteName: "Foe",
619
+ screens: {
620
+ Foe: {
621
+ screens: {
622
+ Baz: "baz"
623
+ }
624
+ },
625
+ Bar: "bar"
626
+ }
627
+ }
628
+ }
629
+ },
630
+ state = {
631
+ routes: [{
632
+ name: "Foo",
633
+ state: {
634
+ routes: [{
635
+ name: "Foe",
636
+ state: {
637
+ routes: [{
638
+ name: "Baz",
639
+ path
640
+ }]
641
+ }
642
+ }]
643
+ }
644
+ }]
645
+ };
646
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
647
+ });
648
+ test.skip("handles two initialRouteNames", function () {
649
+ var path = "/bar/sweet/apple/foe/bis/jane?answer=42&count=10&valid=true",
650
+ config = {
651
+ screens: {
652
+ Bar: {
653
+ path: "bar/:type/:fruit",
654
+ screens: {
655
+ Foo: {
656
+ screens: {
657
+ Foe: {
658
+ path: "foe",
659
+ screens: {
660
+ Baz: {
661
+ initialRouteName: "Bos",
662
+ screens: {
663
+ Bos: {
664
+ path: "bos",
665
+ exact: !0
666
+ },
667
+ Bis: {
668
+ path: "bis/:author",
669
+ stringify: {
670
+ author: function (author) {
671
+ return author.replace(/^\w/, function (c) {
672
+ return c.toLowerCase();
673
+ });
674
+ }
675
+ },
676
+ parse: {
677
+ author: function (author) {
678
+ return author.replace(/^\w/, function (c) {
679
+ return c.toUpperCase();
680
+ });
681
+ },
682
+ count: Number,
683
+ valid: Boolean
684
+ }
685
+ }
686
+ }
687
+ }
688
+ }
689
+ }
690
+ }
691
+ }
692
+ }
693
+ }
694
+ }
695
+ },
696
+ state = {
697
+ routes: [{
698
+ name: "Bar",
699
+ params: {
700
+ fruit: "apple",
701
+ type: "sweet"
702
+ },
703
+ state: {
704
+ routes: [{
705
+ name: "Foo",
706
+ state: {
707
+ routes: [{
708
+ name: "Foe",
709
+ state: {
710
+ routes: [{
711
+ name: "Baz",
712
+ state: {
713
+ index: 1,
714
+ routes: [{
715
+ name: "Bos"
716
+ }, {
717
+ name: "Bis",
718
+ params: {
719
+ answer: "42",
720
+ author: "Jane",
721
+ count: 10,
722
+ valid: !0
723
+ },
724
+ path
725
+ }]
726
+ }
727
+ }]
728
+ }
729
+ }]
730
+ }
731
+ }]
732
+ }
733
+ }]
734
+ };
735
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
736
+ });
737
+ test.skip("accepts initialRouteName without config for it", function () {
738
+ var path = "/bar/sweet/apple/foe/bis/jane?answer=42&count=10&valid=true",
739
+ config = {
740
+ screens: {
741
+ Bar: {
742
+ path: "bar/:type/:fruit",
743
+ screens: {
744
+ Foo: {
745
+ screens: {
746
+ Foe: {
747
+ path: "foe",
748
+ screens: {
749
+ Baz: {
750
+ initialRouteName: "Bas",
751
+ screens: {
752
+ Bos: {
753
+ path: "bos",
754
+ exact: !0
755
+ },
756
+ Bis: {
757
+ path: "bis/:author",
758
+ stringify: {
759
+ author: function (author) {
760
+ return author.replace(/^\w/, function (c) {
761
+ return c.toLowerCase();
762
+ });
763
+ }
764
+ },
765
+ parse: {
766
+ author: function (author) {
767
+ return author.replace(/^\w/, function (c) {
768
+ return c.toUpperCase();
769
+ });
770
+ },
771
+ count: Number,
772
+ valid: Boolean
773
+ }
774
+ }
775
+ }
776
+ }
777
+ }
778
+ }
779
+ }
780
+ }
781
+ }
782
+ }
783
+ }
784
+ },
785
+ state = {
786
+ routes: [{
787
+ name: "Bar",
788
+ params: {
789
+ fruit: "apple",
790
+ type: "sweet"
791
+ },
792
+ state: {
793
+ routes: [{
794
+ name: "Foo",
795
+ state: {
796
+ routes: [{
797
+ name: "Foe",
798
+ state: {
799
+ routes: [{
800
+ name: "Baz",
801
+ state: {
802
+ index: 1,
803
+ routes: [{
804
+ name: "Bas"
805
+ }, {
806
+ name: "Bis",
807
+ params: {
808
+ answer: "42",
809
+ author: "Jane",
810
+ count: 10,
811
+ valid: !0
812
+ },
813
+ path
814
+ }]
815
+ }
816
+ }]
817
+ }
818
+ }]
819
+ }
820
+ }]
821
+ }
822
+ }]
823
+ };
824
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
825
+ });
826
+ test("returns undefined if no matching screen is present (top level path)", function () {
827
+ var path = "/foo/bar",
828
+ config = {
829
+ path: "qux",
830
+ screens: {
831
+ Foo: {
832
+ screens: {
833
+ Foe: "foo",
834
+ Bar: {
835
+ screens: {
836
+ Baz: "bar"
837
+ }
838
+ }
839
+ }
840
+ }
841
+ }
842
+ };
843
+ expect(getStateFromPath(path, config)).toBeUndefined();
844
+ });
845
+ test("returns undefined if no matching screen is present", function () {
846
+ var path = "/baz",
847
+ config = {
848
+ screens: {
849
+ Foo: {
850
+ path: "foo",
851
+ screens: {
852
+ Foe: "foe",
853
+ Bar: {
854
+ screens: {
855
+ Baz: "baz"
856
+ }
857
+ }
858
+ }
859
+ }
860
+ }
861
+ };
862
+ expect(getStateFromPath(path, config)).toBeUndefined();
863
+ });
864
+ test("returns undefined if path is empty and no matching screen is present", function () {
865
+ var path = "",
866
+ config = {
867
+ screens: {
868
+ Foo: {
869
+ screens: {
870
+ Foe: "foe",
871
+ Bar: {
872
+ screens: {
873
+ Baz: "baz"
874
+ }
875
+ }
876
+ }
877
+ }
878
+ }
879
+ };
880
+ expect(getStateFromPath(path, config)).toBeUndefined();
881
+ });
882
+ test.skip("returns matching screen if path is empty", function () {
883
+ var path = "",
884
+ config = {
885
+ screens: {
886
+ Foo: {
887
+ screens: {
888
+ Foe: "foe",
889
+ Bar: {
890
+ screens: {
891
+ Qux: "",
892
+ Baz: "baz"
893
+ }
894
+ }
895
+ }
896
+ }
897
+ }
898
+ },
899
+ state = {
900
+ routes: [{
901
+ name: "Foo",
902
+ state: {
903
+ routes: [{
904
+ name: "Bar",
905
+ state: {
906
+ routes: [{
907
+ name: "Qux",
908
+ path
909
+ }]
910
+ }
911
+ }]
912
+ }
913
+ }]
914
+ };
915
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, ""));
916
+ });
917
+ test.skip("returns matching screen if path is only slash", function () {
918
+ var path = "/",
919
+ config = {
920
+ screens: {
921
+ Foo: {
922
+ screens: {
923
+ Foe: "foe",
924
+ Bar: {
925
+ screens: {
926
+ Qux: "",
927
+ Baz: "baz"
928
+ }
929
+ }
930
+ }
931
+ }
932
+ }
933
+ },
934
+ state = {
935
+ routes: [{
936
+ name: "Foo",
937
+ state: {
938
+ routes: [{
939
+ name: "Bar",
940
+ state: {
941
+ routes: [{
942
+ name: "Qux",
943
+ path: ""
944
+ }]
945
+ }
946
+ }]
947
+ }
948
+ }]
949
+ };
950
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, ""));
951
+ });
952
+ test("returns matching screen with params if path is empty", function () {
953
+ var path = "?foo=42",
954
+ config = {
955
+ screens: {
956
+ Foo: {
957
+ screens: {
958
+ Foe: "foe",
959
+ Bar: {
960
+ screens: {
961
+ Qux: {
962
+ path: "",
963
+ parse: {
964
+ foo: Number
965
+ }
966
+ },
967
+ Baz: "baz"
968
+ }
969
+ }
970
+ }
971
+ }
972
+ }
973
+ },
974
+ state = {
975
+ routes: [{
976
+ name: "Foo",
977
+ state: {
978
+ routes: [{
979
+ name: "Bar",
980
+ state: {
981
+ routes: [{
982
+ name: "Qux",
983
+ params: {
984
+ foo: 42
985
+ },
986
+ path
987
+ }]
988
+ }
989
+ }]
990
+ }
991
+ }]
992
+ };
993
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/?foo=42"));
994
+ });
995
+ test("doesn't match nested screen if path is empty", function () {
996
+ var config = {
997
+ screens: {
998
+ Foo: {
999
+ screens: {
1000
+ Foe: "foe",
1001
+ Bar: {
1002
+ path: "bar",
1003
+ screens: {
1004
+ Qux: {
1005
+ path: "",
1006
+ parse: {
1007
+ foo: Number
1008
+ }
1009
+ }
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ },
1016
+ path = "";
1017
+ expect(getStateFromPath(path, config)).toBeUndefined();
1018
+ });
1019
+ test.skip("chooses more exhaustive pattern", function () {
1020
+ var path = "/foo/5",
1021
+ config = {
1022
+ screens: {
1023
+ Foe: {
1024
+ path: "/",
1025
+ initialRouteName: "Foo",
1026
+ screens: {
1027
+ Foo: "foo",
1028
+ Bis: {
1029
+ path: "foo/:id",
1030
+ parse: {
1031
+ id: Number
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+ },
1038
+ state = {
1039
+ routes: [{
1040
+ name: "Foe",
1041
+ state: {
1042
+ index: 1,
1043
+ routes: [{
1044
+ name: "Foo"
1045
+ }, {
1046
+ name: "Bis",
1047
+ params: {
1048
+ id: 5
1049
+ },
1050
+ path
1051
+ }]
1052
+ }
1053
+ }]
1054
+ };
1055
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1056
+ });
1057
+ test("handles same paths beginnings", function () {
1058
+ var path = "/foos",
1059
+ config = {
1060
+ screens: {
1061
+ Foe: {
1062
+ path: "/",
1063
+ initialRouteName: "Foo",
1064
+ screens: {
1065
+ Foo: "foo",
1066
+ Bis: {
1067
+ path: "foos"
1068
+ }
1069
+ }
1070
+ }
1071
+ }
1072
+ },
1073
+ state = {
1074
+ routes: [{
1075
+ name: "Foe",
1076
+ state: {
1077
+ index: 1,
1078
+ routes: [{
1079
+ name: "Foo"
1080
+ }, {
1081
+ name: "Bis",
1082
+ path
1083
+ }]
1084
+ }
1085
+ }]
1086
+ };
1087
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1088
+ });
1089
+ test.skip("handles same paths beginnings with params", function () {
1090
+ var path = "/foos/5",
1091
+ config = {
1092
+ screens: {
1093
+ Foe: {
1094
+ path: "/",
1095
+ initialRouteName: "Foo",
1096
+ screens: {
1097
+ Foo: "foo",
1098
+ Bis: {
1099
+ path: "foos/:id",
1100
+ parse: {
1101
+ id: Number
1102
+ }
1103
+ }
1104
+ }
1105
+ }
1106
+ }
1107
+ },
1108
+ state = {
1109
+ routes: [{
1110
+ name: "Foe",
1111
+ state: {
1112
+ index: 1,
1113
+ routes: [{
1114
+ name: "Foo"
1115
+ }, {
1116
+ name: "Bis",
1117
+ params: {
1118
+ id: 5
1119
+ },
1120
+ path
1121
+ }]
1122
+ }
1123
+ }]
1124
+ };
1125
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1126
+ });
1127
+ test.skip("handles not taking path with too many segments", function () {
1128
+ var path = "/foos/5",
1129
+ config = {
1130
+ screens: {
1131
+ Foe: {
1132
+ path: "/",
1133
+ initialRouteName: "Foo",
1134
+ screens: {
1135
+ Foo: "foo",
1136
+ Bis: {
1137
+ path: "foos/:id",
1138
+ parse: {
1139
+ id: Number
1140
+ }
1141
+ },
1142
+ Bas: {
1143
+ path: "foos/:id/:nip",
1144
+ parse: {
1145
+ id: Number,
1146
+ pwd: Number
1147
+ }
1148
+ }
1149
+ }
1150
+ }
1151
+ }
1152
+ },
1153
+ state = {
1154
+ routes: [{
1155
+ name: "Foe",
1156
+ state: {
1157
+ index: 1,
1158
+ routes: [{
1159
+ name: "Foo"
1160
+ }, {
1161
+ name: "Bis",
1162
+ params: {
1163
+ id: 5
1164
+ },
1165
+ path
1166
+ }]
1167
+ }
1168
+ }]
1169
+ };
1170
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1171
+ });
1172
+ test.skip("handles differently ordered params v1", function () {
1173
+ var path = "/foos/5/res/20",
1174
+ config = {
1175
+ screens: {
1176
+ Foe: {
1177
+ path: "/",
1178
+ initialRouteName: "Foo",
1179
+ screens: {
1180
+ Foo: "foo",
1181
+ Bis: {
1182
+ path: "foos/:id",
1183
+ parse: {
1184
+ id: Number
1185
+ }
1186
+ },
1187
+ Bas: {
1188
+ path: "foos/:id/res/:pwd",
1189
+ parse: {
1190
+ id: Number,
1191
+ pwd: Number
1192
+ }
1193
+ }
1194
+ }
1195
+ }
1196
+ }
1197
+ },
1198
+ state = {
1199
+ routes: [{
1200
+ name: "Foe",
1201
+ state: {
1202
+ index: 1,
1203
+ routes: [{
1204
+ name: "Foo"
1205
+ }, {
1206
+ name: "Bas",
1207
+ params: {
1208
+ id: 5,
1209
+ pwd: 20
1210
+ },
1211
+ path
1212
+ }]
1213
+ }
1214
+ }]
1215
+ };
1216
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1217
+ });
1218
+ test.skip("handles differently ordered params v2", function () {
1219
+ var path = "/5/20/foos/res",
1220
+ config = {
1221
+ screens: {
1222
+ Foe: {
1223
+ path: "/",
1224
+ initialRouteName: "Foo",
1225
+ screens: {
1226
+ Foo: "foo",
1227
+ Bis: {
1228
+ path: "foos/:id",
1229
+ parse: {
1230
+ id: Number
1231
+ }
1232
+ },
1233
+ Bas: {
1234
+ path: ":id/:pwd/foos/res",
1235
+ parse: {
1236
+ id: Number,
1237
+ pwd: Number
1238
+ }
1239
+ }
1240
+ }
1241
+ }
1242
+ }
1243
+ },
1244
+ state = {
1245
+ routes: [{
1246
+ name: "Foe",
1247
+ state: {
1248
+ index: 1,
1249
+ routes: [{
1250
+ name: "Foo"
1251
+ }, {
1252
+ name: "Bas",
1253
+ params: {
1254
+ id: 5,
1255
+ pwd: 20
1256
+ },
1257
+ path
1258
+ }]
1259
+ }
1260
+ }]
1261
+ };
1262
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1263
+ });
1264
+ test.skip("handles differently ordered params v3", function () {
1265
+ var path = "/foos/5/20/res",
1266
+ config = {
1267
+ screens: {
1268
+ Foe: {
1269
+ path: "/",
1270
+ initialRouteName: "Foo",
1271
+ screens: {
1272
+ Foo: "foo",
1273
+ Bis: {
1274
+ path: "foos/:id",
1275
+ parse: {
1276
+ id: Number
1277
+ }
1278
+ },
1279
+ Bas: {
1280
+ path: "foos/:id/:pwd/res",
1281
+ parse: {
1282
+ id: Number,
1283
+ pwd: Number
1284
+ }
1285
+ }
1286
+ }
1287
+ }
1288
+ }
1289
+ },
1290
+ state = {
1291
+ routes: [{
1292
+ name: "Foe",
1293
+ state: {
1294
+ index: 1,
1295
+ routes: [{
1296
+ name: "Foo"
1297
+ }, {
1298
+ name: "Bas",
1299
+ params: {
1300
+ id: 5,
1301
+ pwd: 20
1302
+ },
1303
+ path
1304
+ }]
1305
+ }
1306
+ }]
1307
+ };
1308
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1309
+ });
1310
+ test.skip("handles differently ordered params v4", function () {
1311
+ var path = "5/foos/res/20",
1312
+ config = {
1313
+ screens: {
1314
+ Foe: {
1315
+ path: "/",
1316
+ initialRouteName: "Foo",
1317
+ screens: {
1318
+ Foo: "foo",
1319
+ Bis: {
1320
+ path: "foos/:id",
1321
+ parse: {
1322
+ id: Number
1323
+ }
1324
+ },
1325
+ Bas: {
1326
+ path: ":id/foos/res/:pwd",
1327
+ parse: {
1328
+ id: Number,
1329
+ pwd: Number
1330
+ }
1331
+ }
1332
+ }
1333
+ }
1334
+ }
1335
+ },
1336
+ state = {
1337
+ routes: [{
1338
+ name: "Foe",
1339
+ state: {
1340
+ index: 1,
1341
+ routes: [{
1342
+ name: "Foo"
1343
+ }, {
1344
+ name: "Bas",
1345
+ params: {
1346
+ id: 5,
1347
+ pwd: 20
1348
+ },
1349
+ path
1350
+ }]
1351
+ }
1352
+ }]
1353
+ };
1354
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/5/foos/res/20"));
1355
+ });
1356
+ test.skip("handles simple optional params", function () {
1357
+ var path = "/foos/5",
1358
+ config = {
1359
+ screens: {
1360
+ Foe: {
1361
+ path: "/",
1362
+ initialRouteName: "Foo",
1363
+ screens: {
1364
+ Foo: "foo",
1365
+ Bis: {
1366
+ path: "foo/:id",
1367
+ parse: {
1368
+ id: Number
1369
+ }
1370
+ },
1371
+ Bas: {
1372
+ path: "foos/:id/:nip?",
1373
+ parse: {
1374
+ id: Number,
1375
+ nip: Number
1376
+ }
1377
+ }
1378
+ }
1379
+ }
1380
+ }
1381
+ },
1382
+ state = {
1383
+ routes: [{
1384
+ name: "Foe",
1385
+ state: {
1386
+ index: 1,
1387
+ routes: [{
1388
+ name: "Foo"
1389
+ }, {
1390
+ name: "Bas",
1391
+ params: {
1392
+ id: 5
1393
+ },
1394
+ path
1395
+ }]
1396
+ }
1397
+ }]
1398
+ };
1399
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1400
+ });
1401
+ test.skip("handle 2 optional params at the end v1", function () {
1402
+ var path = "/foos/5",
1403
+ config = {
1404
+ screens: {
1405
+ Foe: {
1406
+ path: "/",
1407
+ initialRouteName: "Foo",
1408
+ screens: {
1409
+ Foo: "foo",
1410
+ Bis: {
1411
+ path: "foo/:id",
1412
+ parse: {
1413
+ id: Number
1414
+ }
1415
+ },
1416
+ Bas: {
1417
+ path: "foos/:id/:nip?/:pwd?",
1418
+ parse: {
1419
+ id: Number,
1420
+ nip: Number
1421
+ }
1422
+ }
1423
+ }
1424
+ }
1425
+ }
1426
+ },
1427
+ state = {
1428
+ routes: [{
1429
+ name: "Foe",
1430
+ state: {
1431
+ index: 1,
1432
+ routes: [{
1433
+ name: "Foo"
1434
+ }, {
1435
+ name: "Bas",
1436
+ params: {
1437
+ id: 5
1438
+ },
1439
+ path
1440
+ }]
1441
+ }
1442
+ }]
1443
+ };
1444
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1445
+ });
1446
+ test.skip("handle 2 optional params at the end v2", function () {
1447
+ var path = "/foos/5/10",
1448
+ config = {
1449
+ screens: {
1450
+ Foe: {
1451
+ path: "/",
1452
+ initialRouteName: "Foo",
1453
+ screens: {
1454
+ Foo: "foo",
1455
+ Bis: {
1456
+ path: "foo/:id",
1457
+ parse: {
1458
+ id: Number
1459
+ }
1460
+ },
1461
+ Bas: {
1462
+ path: "foos/:id/:nip?/:pwd?",
1463
+ parse: {
1464
+ id: Number,
1465
+ nip: Number
1466
+ }
1467
+ }
1468
+ }
1469
+ }
1470
+ }
1471
+ },
1472
+ state = {
1473
+ routes: [{
1474
+ name: "Foe",
1475
+ state: {
1476
+ index: 1,
1477
+ routes: [{
1478
+ name: "Foo"
1479
+ }, {
1480
+ name: "Bas",
1481
+ params: {
1482
+ id: 5,
1483
+ nip: 10
1484
+ },
1485
+ path
1486
+ }]
1487
+ }
1488
+ }]
1489
+ };
1490
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1491
+ });
1492
+ test.skip("handle 2 optional params at the end v3", function () {
1493
+ var path = "/foos/5/10/15",
1494
+ config = {
1495
+ screens: {
1496
+ Foe: {
1497
+ path: "/",
1498
+ initialRouteName: "Foo",
1499
+ screens: {
1500
+ Foo: "foo",
1501
+ Bis: {
1502
+ path: "foo/:id",
1503
+ parse: {
1504
+ id: Number
1505
+ }
1506
+ },
1507
+ Bas: {
1508
+ path: "foos/:id/:nip?/:pwd?",
1509
+ parse: {
1510
+ id: Number,
1511
+ nip: Number,
1512
+ pwd: Number
1513
+ }
1514
+ }
1515
+ }
1516
+ }
1517
+ }
1518
+ },
1519
+ state = {
1520
+ routes: [{
1521
+ name: "Foe",
1522
+ state: {
1523
+ index: 1,
1524
+ routes: [{
1525
+ name: "Foo"
1526
+ }, {
1527
+ name: "Bas",
1528
+ params: {
1529
+ id: 5,
1530
+ nip: 10,
1531
+ pwd: 15
1532
+ },
1533
+ path
1534
+ }]
1535
+ }
1536
+ }]
1537
+ };
1538
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1539
+ });
1540
+ test.skip("handle optional params in the middle v1", function () {
1541
+ var path = "/foos/5/10",
1542
+ config = {
1543
+ screens: {
1544
+ Foe: {
1545
+ path: "/",
1546
+ initialRouteName: "Foo",
1547
+ screens: {
1548
+ Foo: "foo",
1549
+ Bis: {
1550
+ path: "foo/:id",
1551
+ parse: {
1552
+ id: Number
1553
+ }
1554
+ },
1555
+ Bas: {
1556
+ path: "foos/:id/:nip?/:pwd",
1557
+ parse: {
1558
+ id: Number,
1559
+ nip: Number,
1560
+ pwd: Number
1561
+ }
1562
+ }
1563
+ }
1564
+ }
1565
+ }
1566
+ },
1567
+ state = {
1568
+ routes: [{
1569
+ name: "Foe",
1570
+ state: {
1571
+ index: 1,
1572
+ routes: [{
1573
+ name: "Foo"
1574
+ }, {
1575
+ name: "Bas",
1576
+ params: {
1577
+ id: 5,
1578
+ pwd: 10
1579
+ },
1580
+ path
1581
+ }]
1582
+ }
1583
+ }]
1584
+ };
1585
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1586
+ });
1587
+ test.skip("handle optional params in the middle v2", function () {
1588
+ var path = "/foos/5/10/15",
1589
+ config = {
1590
+ screens: {
1591
+ Foe: {
1592
+ path: "/",
1593
+ initialRouteName: "Foo",
1594
+ screens: {
1595
+ Foo: "foo",
1596
+ Bis: {
1597
+ path: "foo/:id",
1598
+ parse: {
1599
+ id: Number
1600
+ }
1601
+ },
1602
+ Bas: {
1603
+ path: "foos/:id/:nip?/:pwd",
1604
+ parse: {
1605
+ id: Number,
1606
+ nip: Number,
1607
+ pwd: Number
1608
+ }
1609
+ }
1610
+ }
1611
+ }
1612
+ }
1613
+ },
1614
+ state = {
1615
+ routes: [{
1616
+ name: "Foe",
1617
+ state: {
1618
+ index: 1,
1619
+ routes: [{
1620
+ name: "Foo"
1621
+ }, {
1622
+ name: "Bas",
1623
+ params: {
1624
+ id: 5,
1625
+ nip: 10,
1626
+ pwd: 15
1627
+ },
1628
+ path
1629
+ }]
1630
+ }
1631
+ }]
1632
+ };
1633
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1634
+ });
1635
+ test.skip("handle optional params in the middle v3", function () {
1636
+ var path = "/foos/5/10/15",
1637
+ config = {
1638
+ screens: {
1639
+ Foe: {
1640
+ path: "/",
1641
+ initialRouteName: "Foo",
1642
+ screens: {
1643
+ Foo: "foo",
1644
+ Bis: {
1645
+ path: "foo/:id",
1646
+ parse: {
1647
+ id: Number
1648
+ }
1649
+ },
1650
+ Bas: {
1651
+ path: "foos/:id/:nip?/:pwd/:smh",
1652
+ parse: {
1653
+ id: Number,
1654
+ nip: Number,
1655
+ pwd: Number,
1656
+ smh: Number
1657
+ }
1658
+ }
1659
+ }
1660
+ }
1661
+ }
1662
+ },
1663
+ state = {
1664
+ routes: [{
1665
+ name: "Foe",
1666
+ state: {
1667
+ index: 1,
1668
+ routes: [{
1669
+ name: "Foo"
1670
+ }, {
1671
+ name: "Bas",
1672
+ params: {
1673
+ id: 5,
1674
+ pwd: 10,
1675
+ smh: 15
1676
+ },
1677
+ path
1678
+ }]
1679
+ }
1680
+ }]
1681
+ };
1682
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1683
+ });
1684
+ test.skip("handle optional params in the middle v4", function () {
1685
+ var path = "/foos/5/10",
1686
+ config = {
1687
+ screens: {
1688
+ Foe: {
1689
+ path: "/",
1690
+ initialRouteName: "Foo",
1691
+ screens: {
1692
+ Foo: "foo",
1693
+ Bis: {
1694
+ path: "foo/:id",
1695
+ parse: {
1696
+ id: Number
1697
+ }
1698
+ },
1699
+ Bas: {
1700
+ path: "foos/:nip?/:pwd/:smh?/:id",
1701
+ parse: {
1702
+ id: Number,
1703
+ nip: Number,
1704
+ pwd: Number,
1705
+ smh: Number
1706
+ }
1707
+ }
1708
+ }
1709
+ }
1710
+ }
1711
+ },
1712
+ state = {
1713
+ routes: [{
1714
+ name: "Foe",
1715
+ state: {
1716
+ index: 1,
1717
+ routes: [{
1718
+ name: "Foo"
1719
+ }, {
1720
+ name: "Bas",
1721
+ params: {
1722
+ pwd: 5,
1723
+ id: 10
1724
+ },
1725
+ path
1726
+ }]
1727
+ }
1728
+ }]
1729
+ };
1730
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1731
+ });
1732
+ test.skip("handle optional params in the middle v5", function () {
1733
+ var path = "/foos/5/10/15",
1734
+ config = {
1735
+ screens: {
1736
+ Foe: {
1737
+ path: "/",
1738
+ initialRouteName: "Foo",
1739
+ screens: {
1740
+ Foo: "foo",
1741
+ Bis: {
1742
+ path: "foo/:id",
1743
+ parse: {
1744
+ id: Number
1745
+ }
1746
+ },
1747
+ Bas: {
1748
+ path: "foos/:nip?/:pwd/:smh?/:id",
1749
+ parse: {
1750
+ id: Number,
1751
+ nip: Number,
1752
+ pwd: Number,
1753
+ smh: Number
1754
+ }
1755
+ }
1756
+ }
1757
+ }
1758
+ }
1759
+ },
1760
+ state = {
1761
+ routes: [{
1762
+ name: "Foe",
1763
+ state: {
1764
+ index: 1,
1765
+ routes: [{
1766
+ name: "Foo"
1767
+ }, {
1768
+ name: "Bas",
1769
+ params: {
1770
+ nip: 5,
1771
+ pwd: 10,
1772
+ id: 15
1773
+ },
1774
+ path
1775
+ }]
1776
+ }
1777
+ }]
1778
+ };
1779
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1780
+ });
1781
+ test.skip("handle optional params in the beginning v1", function () {
1782
+ var path = "5/10/foos/15",
1783
+ config = {
1784
+ screens: {
1785
+ Foe: {
1786
+ path: "/",
1787
+ initialRouteName: "Foo",
1788
+ screens: {
1789
+ Foo: "foo",
1790
+ Bis: {
1791
+ path: "foo/:id",
1792
+ parse: {
1793
+ id: Number
1794
+ }
1795
+ },
1796
+ Bas: {
1797
+ path: ":nip?/:pwd/foos/:smh?/:id",
1798
+ parse: {
1799
+ id: Number,
1800
+ nip: Number,
1801
+ pwd: Number,
1802
+ smh: Number
1803
+ }
1804
+ }
1805
+ }
1806
+ }
1807
+ }
1808
+ },
1809
+ state = {
1810
+ routes: [{
1811
+ name: "Foe",
1812
+ state: {
1813
+ index: 1,
1814
+ routes: [{
1815
+ name: "Foo"
1816
+ }, {
1817
+ name: "Bas",
1818
+ params: {
1819
+ nip: 5,
1820
+ pwd: 10,
1821
+ id: 15
1822
+ },
1823
+ path
1824
+ }]
1825
+ }
1826
+ }]
1827
+ };
1828
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/5/10/foos/15"));
1829
+ });
1830
+ test.skip("handle optional params in the beginning v2", function () {
1831
+ var path = "5/10/foos/15",
1832
+ config = {
1833
+ screens: {
1834
+ Foe: {
1835
+ path: "/",
1836
+ initialRouteName: "Foo",
1837
+ screens: {
1838
+ Foo: "foo",
1839
+ Bis: {
1840
+ path: "foo/:id",
1841
+ parse: {
1842
+ id: Number
1843
+ }
1844
+ },
1845
+ Bas: {
1846
+ path: ":nip?/:smh?/:pwd/foos/:id",
1847
+ parse: {
1848
+ id: Number,
1849
+ nip: Number,
1850
+ pwd: Number,
1851
+ smh: Number
1852
+ }
1853
+ }
1854
+ }
1855
+ }
1856
+ }
1857
+ },
1858
+ state = {
1859
+ routes: [{
1860
+ name: "Foe",
1861
+ state: {
1862
+ index: 1,
1863
+ routes: [{
1864
+ name: "Foo"
1865
+ }, {
1866
+ name: "Bas",
1867
+ params: {
1868
+ nip: 5,
1869
+ pwd: 10,
1870
+ id: 15
1871
+ },
1872
+ path
1873
+ }]
1874
+ }
1875
+ }]
1876
+ };
1877
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/5/10/foos/15"));
1878
+ });
1879
+ test.skip("merges parent patterns if needed", function () {
1880
+ var path = "foo/42/baz/babel",
1881
+ config = {
1882
+ screens: {
1883
+ Foo: {
1884
+ path: "foo/:bar",
1885
+ parse: {
1886
+ bar: Number
1887
+ },
1888
+ screens: {
1889
+ Baz: "baz/:qux"
1890
+ }
1891
+ }
1892
+ }
1893
+ },
1894
+ state = {
1895
+ routes: [{
1896
+ name: "Foo",
1897
+ params: {
1898
+ bar: 42
1899
+ },
1900
+ state: {
1901
+ routes: [{
1902
+ name: "Baz",
1903
+ params: {
1904
+ qux: "babel"
1905
+ },
1906
+ path
1907
+ }]
1908
+ }
1909
+ }]
1910
+ };
1911
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/foo/42/baz/babel"));
1912
+ });
1913
+ test.skip("ignores extra slashes in the pattern", function () {
1914
+ var path = "/bar/42",
1915
+ config = {
1916
+ screens: {
1917
+ Foo: {
1918
+ screens: {
1919
+ Bar: {
1920
+ path: "/bar//:id/"
1921
+ }
1922
+ }
1923
+ }
1924
+ }
1925
+ },
1926
+ state = {
1927
+ routes: [{
1928
+ name: "Foo",
1929
+ state: {
1930
+ routes: [{
1931
+ name: "Bar",
1932
+ params: {
1933
+ id: "42"
1934
+ },
1935
+ path
1936
+ }]
1937
+ }
1938
+ }]
1939
+ };
1940
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
1941
+ });
1942
+ test.skip("matches wildcard patterns at root", function () {
1943
+ var path = "/test/bar/42/whatever",
1944
+ config = {
1945
+ screens: {
1946
+ 404: "*",
1947
+ Foo: {
1948
+ screens: {
1949
+ Bar: {
1950
+ path: "/bar/:id/"
1951
+ }
1952
+ }
1953
+ }
1954
+ }
1955
+ },
1956
+ state = {
1957
+ routes: [{
1958
+ name: "404",
1959
+ path
1960
+ }]
1961
+ };
1962
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/404"));
1963
+ });
1964
+ test.skip("matches wildcard patterns at nested level", function () {
1965
+ var path = "/bar/42/whatever/baz/initt",
1966
+ config = {
1967
+ screens: {
1968
+ Foo: {
1969
+ screens: {
1970
+ Bar: {
1971
+ path: "/bar/:id/",
1972
+ screens: {
1973
+ 404: "*"
1974
+ }
1975
+ }
1976
+ }
1977
+ }
1978
+ }
1979
+ },
1980
+ state = {
1981
+ routes: [{
1982
+ name: "Foo",
1983
+ state: {
1984
+ routes: [{
1985
+ name: "Bar",
1986
+ params: {
1987
+ id: "42"
1988
+ },
1989
+ state: {
1990
+ routes: [{
1991
+ name: "404",
1992
+ path
1993
+ }]
1994
+ }
1995
+ }]
1996
+ }
1997
+ }]
1998
+ };
1999
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/bar/42/404"));
2000
+ });
2001
+ test.skip("matches wildcard patterns at nested level with exact", function () {
2002
+ var path = "/whatever",
2003
+ config = {
2004
+ screens: {
2005
+ Foo: {
2006
+ screens: {
2007
+ Bar: {
2008
+ path: "/bar/:id/",
2009
+ screens: {
2010
+ 404: {
2011
+ path: "*",
2012
+ exact: !0
2013
+ }
2014
+ }
2015
+ },
2016
+ Baz: {}
2017
+ }
2018
+ }
2019
+ }
2020
+ },
2021
+ state = {
2022
+ routes: [{
2023
+ name: "Foo",
2024
+ state: {
2025
+ routes: [{
2026
+ name: "Bar",
2027
+ state: {
2028
+ routes: [{
2029
+ name: "404",
2030
+ path
2031
+ }]
2032
+ }
2033
+ }]
2034
+ }
2035
+ }]
2036
+ };
2037
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/404"));
2038
+ });
2039
+ test.skip("tries to match wildcard patterns at the end", function () {
2040
+ var path = "/bar/42/test",
2041
+ config = {
2042
+ screens: {
2043
+ Foo: {
2044
+ screens: {
2045
+ Bar: {
2046
+ path: "/bar/:id/",
2047
+ screens: {
2048
+ 404: "*",
2049
+ UserProfile: ":userSlug",
2050
+ Test: "test"
2051
+ }
2052
+ }
2053
+ }
2054
+ }
2055
+ }
2056
+ },
2057
+ state = {
2058
+ routes: [{
2059
+ name: "Foo",
2060
+ state: {
2061
+ routes: [{
2062
+ name: "Bar",
2063
+ params: {
2064
+ id: "42"
2065
+ },
2066
+ state: {
2067
+ routes: [{
2068
+ name: "Test",
2069
+ path
2070
+ }]
2071
+ }
2072
+ }]
2073
+ }
2074
+ }]
2075
+ };
2076
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
2077
+ });
2078
+ test.skip("uses nearest parent wildcard match for unmatched paths", function () {
2079
+ var path = "/bar/42/baz/test",
2080
+ config = {
2081
+ screens: {
2082
+ Foo: {
2083
+ screens: {
2084
+ Bar: {
2085
+ path: "/bar/:id/",
2086
+ screens: {
2087
+ Baz: "baz"
2088
+ }
2089
+ },
2090
+ 404: "*"
2091
+ }
2092
+ }
2093
+ }
2094
+ },
2095
+ state = {
2096
+ routes: [{
2097
+ name: "Foo",
2098
+ state: {
2099
+ routes: [{
2100
+ name: "404",
2101
+ path
2102
+ }]
2103
+ }
2104
+ }]
2105
+ };
2106
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/404"));
2107
+ });
2108
+ test.skip("matches screen with overlapping initial path and wildcard", function () {
2109
+ var path = "/bar/42/baz/test/whatever",
2110
+ config = {
2111
+ screens: {
2112
+ Foo: {
2113
+ screens: {
2114
+ Bar: {
2115
+ path: "/bar/:id/",
2116
+ screens: {
2117
+ Baz: "baz"
2118
+ }
2119
+ },
2120
+ Baz: "/bar/:id/*"
2121
+ }
2122
+ }
2123
+ }
2124
+ },
2125
+ state = {
2126
+ routes: [{
2127
+ name: "Foo",
2128
+ state: {
2129
+ routes: [{
2130
+ name: "Baz",
2131
+ params: {
2132
+ id: "42"
2133
+ },
2134
+ path
2135
+ }]
2136
+ }
2137
+ }]
2138
+ };
2139
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(changePath(state, "/bar/42/Baz"));
2140
+ });
2141
+ test("throws if two screens map to the same pattern", function () {
2142
+ var path = "/bar/42/baz/test";
2143
+ expect(function () {
2144
+ return getStateFromPath(path, {
2145
+ screens: {
2146
+ Foo: {
2147
+ screens: {
2148
+ Bar: {
2149
+ path: "/bar/:id/",
2150
+ screens: {
2151
+ Baz: "baz"
2152
+ }
2153
+ },
2154
+ Bax: "/bar/:id/baz"
2155
+ }
2156
+ }
2157
+ }
2158
+ });
2159
+ }).toThrow("Found conflicting screens with the same pattern. The pattern 'bar/:id/baz' resolves to both 'Foo > Bax' and 'Foo > Bar > Baz'. Patterns must be unique and cannot resolve to more than one screen."), expect(function () {
2160
+ return getStateFromPath(path, {
2161
+ screens: {
2162
+ Foo: {
2163
+ screens: {
2164
+ Bar: {
2165
+ path: "/bar/:id/",
2166
+ screens: {
2167
+ Baz: ""
2168
+ }
2169
+ }
2170
+ }
2171
+ }
2172
+ }
2173
+ });
2174
+ }).not.toThrow();
2175
+ });
2176
+ test("correctly applies initialRouteName for config with similar route names", function () {
2177
+ var path = "/weekly-earnings",
2178
+ config = {
2179
+ screens: {
2180
+ RootTabs: {
2181
+ screens: {
2182
+ HomeTab: {
2183
+ screens: {
2184
+ Home: "",
2185
+ WeeklyEarnings: "weekly-earnings",
2186
+ EventDetails: "event-details/:eventId"
2187
+ }
2188
+ },
2189
+ EarningsTab: {
2190
+ initialRouteName: "Earnings",
2191
+ path: "earnings",
2192
+ screens: {
2193
+ Earnings: "",
2194
+ WeeklyEarnings: "weekly-earnings"
2195
+ }
2196
+ }
2197
+ }
2198
+ }
2199
+ }
2200
+ },
2201
+ state = {
2202
+ routes: [{
2203
+ name: "RootTabs",
2204
+ state: {
2205
+ routes: [{
2206
+ name: "HomeTab",
2207
+ state: {
2208
+ routes: [{
2209
+ name: "WeeklyEarnings",
2210
+ path
2211
+ }]
2212
+ }
2213
+ }]
2214
+ }
2215
+ }]
2216
+ };
2217
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
2218
+ });
2219
+ test("correctly applies initialRouteName for config with similar route names v2", function () {
2220
+ var path = "/earnings/weekly-earnings",
2221
+ config = {
2222
+ screens: {
2223
+ RootTabs: {
2224
+ screens: {
2225
+ HomeTab: {
2226
+ initialRouteName: "Home",
2227
+ screens: {
2228
+ Home: "",
2229
+ WeeklyEarnings: "weekly-earnings"
2230
+ }
2231
+ },
2232
+ EarningsTab: {
2233
+ initialRouteName: "Earnings",
2234
+ path: "earnings",
2235
+ screens: {
2236
+ Earnings: "",
2237
+ WeeklyEarnings: "weekly-earnings"
2238
+ }
2239
+ }
2240
+ }
2241
+ }
2242
+ }
2243
+ },
2244
+ state = {
2245
+ routes: [{
2246
+ name: "RootTabs",
2247
+ state: {
2248
+ routes: [{
2249
+ name: "EarningsTab",
2250
+ state: {
2251
+ index: 1,
2252
+ routes: [{
2253
+ name: "Earnings"
2254
+ }, {
2255
+ name: "WeeklyEarnings",
2256
+ path
2257
+ }]
2258
+ }
2259
+ }]
2260
+ }
2261
+ }]
2262
+ };
2263
+ expect(getStateFromPath(path, config)).toEqual(state), expect(getStateFromPath(getPathFromState(state, config), config)).toEqual(state);
2264
+ });
2265
+ test.skip("throws when invalid properties are specified in the config", function () {
2266
+ expect(function () {
2267
+ return getStateFromPath("", {
2268
+ path: 42,
2269
+ Foo: "foo",
2270
+ Bar: {
2271
+ path: "bar"
2272
+ }
2273
+ });
2274
+ }).toThrowErrorMatchingInlineSnapshot(`
2275
+ "Found invalid properties in the configuration:
2276
+ - path (expected 'string', got 'number')
2277
+ - Foo (extraneous)
2278
+ - Bar (extraneous)
2279
+
2280
+ You can only specify the following properties:
2281
+ - path (string)
2282
+ - initialRouteName (string)
2283
+ - screens (object)
2284
+
2285
+ If you want to specify configuration for screens, you need to specify them under a 'screens' property.
2286
+
2287
+ See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."
2288
+ `), expect(function () {
2289
+ return getStateFromPath("", {
2290
+ screens: {
2291
+ Foo: "foo",
2292
+ Bar: {
2293
+ path: "bar"
2294
+ },
2295
+ Baz: {
2296
+ Qux: {
2297
+ path: "qux"
2298
+ }
2299
+ }
2300
+ }
2301
+ });
2302
+ }).toThrowErrorMatchingInlineSnapshot(`
2303
+ "Found invalid properties in the configuration:
2304
+ - Qux (extraneous)
2305
+
2306
+ You can only specify the following properties:
2307
+ - path (string)
2308
+ - initialRouteName (string)
2309
+ - screens (object)
2310
+ - alias (array)
2311
+ - exact (boolean)
2312
+ - stringify (object)
2313
+ - parse (object)
2314
+
2315
+ If you want to specify configuration for screens, you need to specify them under a 'screens' property.
2316
+
2317
+ See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration."
2318
+ `), expect(function () {
2319
+ return getStateFromPath("", {
2320
+ path: "foo/:id"
2321
+ });
2322
+ }).toThrowErrorMatchingInlineSnapshot(`"Found invalid path 'foo/:id'. The 'path' in the top-level configuration cannot contain patterns for params."`);
2323
+ });
2324
+ test.skip("encodes special characters in params", function () {
2325
+ var paramWithValidSymbols = "User09-A_Z~!$&'()*+,;=:@__",
2326
+ invalidSymbols = "#?[]{}%<>||",
2327
+ queryString = "user#email@gmail.com=2&4",
2328
+ path = `users/id/${paramWithValidSymbols}${encodeURIComponent(invalidSymbols)}?query=${encodeURIComponent(queryString)}`,
2329
+ config = {
2330
+ path: "users",
2331
+ screens: {
2332
+ Users: {
2333
+ screens: {
2334
+ User: "id/:id"
2335
+ }
2336
+ }
2337
+ }
2338
+ },
2339
+ state = {
2340
+ routes: [{
2341
+ name: "Users",
2342
+ state: {
2343
+ routes: [{
2344
+ name: "User",
2345
+ params: {
2346
+ id: `${paramWithValidSymbols}${invalidSymbols}`,
2347
+ query: queryString
2348
+ }
2349
+ }]
2350
+ }
2351
+ }]
2352
+ };
2353
+ expect(getPathFromState(state, config)).toBe(`/${path}`), expect(getPathFromState(getStateFromPath(path, config), config)).toBe(`/${path}`);
2354
+ });
2355
+ test.skip("resolves nested path params with same name to correct screen", function () {
2356
+ var path = "/foo/42/bar/43",
2357
+ config = {
2358
+ initialRouteName: "Foo",
2359
+ screens: {
2360
+ Foo: {
2361
+ path: "foo/:id",
2362
+ screens: {
2363
+ Bar: {
2364
+ path: "bar/:id"
2365
+ }
2366
+ }
2367
+ }
2368
+ }
2369
+ },
2370
+ state = {
2371
+ routes: [{
2372
+ name: "Foo",
2373
+ params: {
2374
+ id: "42"
2375
+ },
2376
+ state: {
2377
+ routes: [{
2378
+ name: "Bar",
2379
+ params: {
2380
+ id: "43"
2381
+ },
2382
+ path
2383
+ }]
2384
+ }
2385
+ }]
2386
+ };
2387
+ expect(getStateFromPath(path, config)).toEqual(state);
2388
+ });
2389
+ test("parses / same as empty string", function () {
2390
+ var config = {
2391
+ screens: {
2392
+ Foo: {
2393
+ path: "/"
2394
+ },
2395
+ Bar: {
2396
+ path: "bar"
2397
+ }
2398
+ }
2399
+ };
2400
+ expect(getStateFromPath("/", config)).toEqual(getStateFromPath("", config));
2401
+ });
2402
+ test.skip("matches regexp patterns when provided", function () {
2403
+ var config = {
2404
+ screens: {
2405
+ Foo: {
2406
+ path: "foo/:id(\\d+)",
2407
+ parse: {
2408
+ id: Number
2409
+ }
2410
+ },
2411
+ Bar: {
2412
+ path: "foo/:id([a-z]+)"
2413
+ },
2414
+ Baz: {
2415
+ path: "foo/:id(\\d+)/:name([a-z]+)"
2416
+ },
2417
+ Qux: {
2418
+ path: "foo/:id(@[a-z]+)",
2419
+ parse: {
2420
+ id: function (id) {
2421
+ return id.slice(1);
2422
+ }
2423
+ }
2424
+ },
2425
+ Quy: {
2426
+ path: "foo/bar/:category"
2427
+ },
2428
+ Quz: {
2429
+ path: "foo/bar/:special([a-z]+)"
2430
+ },
2431
+ Quu: {
2432
+ path: "foo/bar/baz"
2433
+ },
2434
+ NotFound: {
2435
+ path: "foo/bar/*"
2436
+ }
2437
+ }
2438
+ };
2439
+ expect(getStateFromPath("foo/42", config)).toEqual({
2440
+ routes: [{
2441
+ name: "Foo",
2442
+ params: {
2443
+ id: 42
2444
+ },
2445
+ path: "foo/42"
2446
+ }]
2447
+ }), expect(getStateFromPath("foo/bar", config)).toEqual({
2448
+ routes: [{
2449
+ name: "Bar",
2450
+ params: {
2451
+ id: "bar"
2452
+ },
2453
+ path: "foo/bar"
2454
+ }]
2455
+ }), expect(getStateFromPath("foo/42/bar", config)).toEqual({
2456
+ routes: [{
2457
+ name: "Baz",
2458
+ params: {
2459
+ id: "42",
2460
+ name: "bar"
2461
+ },
2462
+ path: "foo/42/bar"
2463
+ }]
2464
+ }), expect(getStateFromPath("foo/@bar", config)).toEqual({
2465
+ routes: [{
2466
+ name: "Qux",
2467
+ params: {
2468
+ id: "bar"
2469
+ },
2470
+ path: "foo/@bar"
2471
+ }]
2472
+ }), expect(getStateFromPath("foo/@bar", config)).toEqual({
2473
+ routes: [{
2474
+ name: "Qux",
2475
+ params: {
2476
+ id: "bar"
2477
+ },
2478
+ path: "foo/@bar"
2479
+ }]
2480
+ }), expect(getStateFromPath("foo/42a", config)).toBeUndefined(), expect(getStateFromPath("foo/bar/123", config)).toEqual({
2481
+ routes: [{
2482
+ name: "Quy",
2483
+ params: {
2484
+ category: "123"
2485
+ },
2486
+ path: "foo/bar/123"
2487
+ }]
2488
+ }), expect(getStateFromPath("foo/bar/test", config)).toEqual({
2489
+ routes: [{
2490
+ name: "Quz",
2491
+ params: {
2492
+ special: "test"
2493
+ },
2494
+ path: "foo/bar/test"
2495
+ }]
2496
+ }), expect(getStateFromPath("foo/bar/baz", config)).toEqual({
2497
+ routes: [{
2498
+ name: "Quu",
2499
+ path: "foo/bar/baz"
2500
+ }]
2501
+ }), expect(getStateFromPath("foo/bar/hello/world", config)).toEqual({
2502
+ routes: [{
2503
+ name: "NotFound",
2504
+ path: "foo/bar/hello/world"
2505
+ }]
2506
+ });
2507
+ });
2508
+ test("regexp pattern doesn't match slash", function () {
2509
+ var config = {
2510
+ screens: {
2511
+ Foo: {
2512
+ path: "foo/:id([a-z]+\\/)"
2513
+ }
2514
+ }
2515
+ };
2516
+ expect(getStateFromPath("foo/bar/", config)).toBeUndefined(), expect(getStateFromPath("foo/bar/baz", config)).toBeUndefined(), expect(getStateFromPath("foo/bar/baz/qux", config)).toBeUndefined();
2517
+ });
2518
+ test.skip("handles alias for paths", function () {
2519
+ var config = {
2520
+ screens: {
2521
+ Foo: {
2522
+ path: "foo",
2523
+ alias: ["first"],
2524
+ screens: {
2525
+ Baz: {
2526
+ path: "baz/:id?",
2527
+ parse: {
2528
+ id: function (value) {
2529
+ return value.replace(/@/, "");
2530
+ }
2531
+ },
2532
+ alias: [{
2533
+ path: "second/:id",
2534
+ exact: !0
2535
+ }, "third", {
2536
+ path: "fourth/:id",
2537
+ parse: {
2538
+ id: function (value) {
2539
+ return value.replace(/\$/, "");
2540
+ }
2541
+ }
2542
+ }]
2543
+ },
2544
+ Qux: {
2545
+ path: "qux/:id"
2546
+ }
2547
+ }
2548
+ }
2549
+ }
2550
+ };
2551
+ expect(getStateFromPath("foo", config)).toEqual({
2552
+ routes: [{
2553
+ name: "Foo",
2554
+ path: "foo"
2555
+ }]
2556
+ }), expect(getPathFromState(getStateFromPath("foo", config), config)).toBe("/foo"), expect(getStateFromPath("first", config)).toEqual({
2557
+ routes: [{
2558
+ name: "Foo",
2559
+ path: "first"
2560
+ }]
2561
+ }), expect(getPathFromState(getStateFromPath("first", config), config)).toBe("/foo"), expect(getStateFromPath("foo/baz/@$test", config)).toEqual({
2562
+ routes: [{
2563
+ name: "Foo",
2564
+ state: {
2565
+ routes: [{
2566
+ name: "Baz",
2567
+ params: {
2568
+ id: "$test"
2569
+ },
2570
+ path: "foo/baz/@$test"
2571
+ }]
2572
+ }
2573
+ }]
2574
+ }), expect(getPathFromState(getStateFromPath("foo/baz/@$test", config), config)).toBe("/foo/baz/$test"), expect(getStateFromPath("second/42", config)).toEqual({
2575
+ routes: [{
2576
+ name: "Foo",
2577
+ state: {
2578
+ routes: [{
2579
+ name: "Baz",
2580
+ params: {
2581
+ id: "42"
2582
+ },
2583
+ path: "second/42"
2584
+ }]
2585
+ }
2586
+ }]
2587
+ }), expect(getPathFromState(getStateFromPath("second/42", config), config)).toBe("/foo/baz/42"), expect(getStateFromPath("foo/third", config)).toEqual({
2588
+ routes: [{
2589
+ name: "Foo",
2590
+ state: {
2591
+ routes: [{
2592
+ name: "Baz",
2593
+ path: "foo/third"
2594
+ }]
2595
+ }
2596
+ }]
2597
+ }), expect(getPathFromState(getStateFromPath("foo/third", config), config)).toBe("/foo/baz"), expect(getStateFromPath("foo/fourth/@$test", config)).toEqual({
2598
+ routes: [{
2599
+ name: "Foo",
2600
+ state: {
2601
+ routes: [{
2602
+ name: "Baz",
2603
+ params: {
2604
+ id: "@test"
2605
+ },
2606
+ path: "foo/fourth/@$test"
2607
+ }]
2608
+ }
2609
+ }]
2610
+ }), expect(getPathFromState(getStateFromPath("foo/fourth/@$test", config), config)).toBe("/foo/baz/@test"), expect(getStateFromPath("foo/qux/42", config)).toEqual({
2611
+ routes: [{
2612
+ name: "Foo",
2613
+ state: {
2614
+ routes: [{
2615
+ name: "Qux",
2616
+ params: {
2617
+ id: "42"
2618
+ },
2619
+ path: "foo/qux/42"
2620
+ }]
2621
+ }
2622
+ }]
2623
+ }), expect(getPathFromState(getStateFromPath("foo/qux/42", config), config)).toBe("/foo/qux/42");
2624
+ });
2625
+ test.skip("throws if screen has alias but no path", function () {
2626
+ expect(function () {
2627
+ return getStateFromPath("", {
2628
+ screens: {
2629
+ Foo: {
2630
+ alias: ["bar"]
2631
+ }
2632
+ }
2633
+ });
2634
+ }).toThrow("Screen 'Foo' doesn't specify a 'path'. A 'path' needs to be specified in order to use 'alias'.");
2635
+ });
2636
+ //# sourceMappingURL=getStateFromPath.test.native.js.map