-
-
+
+
+ {[
+ undefined,
+ null,
+
+
+ ,
+ ]}
+
>
}
/>,
@@ -415,389 +479,351 @@ describe('routingV2Collector', () => {
collectors: {
routing: routingV2Collector,
},
- }),
- ).toThrow('Route element may not contain multiple routable extensions');
- });
+ });
- it('should not support inline path', () => {
- expect(() =>
- traverseElementTree({
- root: routeRoot(),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
- }),
- ).toThrow('Path property may not be set directly on a routable extension');
- });
-
- it('should associate the path with extensions deep in the element prop', () => {
- const { routing } = traverseElementTree({
- root: routeRoot(
-
-
-
- {[
- undefined,
- null,
-
-
- ,
- ]}
-
- >
- }
- />,
- ),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
+ expect(sortedEntries(routing.paths)).toEqual([[ref1, '/foo']]);
+ expect(sortedEntries(routing.parents)).toEqual([[ref1, undefined]]);
+ expect(routing.objects).toEqual([
+ routeObj('/foo', [ref1], [], undefined, plugin),
+ ]);
});
- expect(sortedEntries(routing.paths)).toEqual([[ref1, '/foo']]);
- expect(sortedEntries(routing.parents)).toEqual([[ref1, undefined]]);
- expect(routing.objects).toEqual([
- routeObj('/foo', [ref1], [], undefined, plugin),
- ]);
- });
+ it('should not associate path with extension in children prop', () => {
+ expect(() =>
+ traverseElementTree({
+ root: routeRoot(
+
+
+ ,
+ ),
+ discoverers: [childDiscoverer, routeElementDiscoverer],
+ collectors: {
+ routing: routingV2Collector,
+ },
+ }),
+ ).toThrow('Routable extension must be assigned a path');
+ });
- it('should not associate path with extension in children prop', () => {
- expect(() =>
- traverseElementTree({
+ it('should assign parent for extension in element prop', () => {
+ const { routing } = traverseElementTree({
root: routeRoot(
-
-
+ }>
+ } />
,
),
discoverers: [childDiscoverer, routeElementDiscoverer],
collectors: {
routing: routingV2Collector,
},
- }),
- ).toThrow('Routable extension must be assigned a path');
- });
-
- it('should assign parent for extension in element prop', () => {
- const { routing } = traverseElementTree({
- root: routeRoot(
- }>
- } />
- ,
- ),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
- });
-
- expect(sortedEntries(routing.paths)).toEqual([
- [ref1, '/foo'],
- [ref2, '/bar'],
- ]);
- expect(sortedEntries(routing.parents)).toEqual([
- [ref1, undefined],
- [ref2, ref1],
- ]);
- expect(routing.objects).toEqual([
- routeObj(
- '/foo',
- [ref1],
- [routeObj('/bar', [ref2], [], undefined, plugin)],
- undefined,
- plugin,
- ),
- ]);
- });
-
- it('should not allow paths within element props', () => {
- expect(() => {
- traverseElementTree({
- root: routeRoot(
- } />}
- />,
- ),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
});
- }).toThrow('Elements within the element prop tree may not contain paths');
- });
- it('should not allow extensions within the element prop to have path props either', () => {
- expect(() => {
- traverseElementTree({
- root: routeRoot(
- } />,
+ expect(sortedEntries(routing.paths)).toEqual([
+ [ref1, '/foo'],
+ [ref2, '/bar'],
+ ]);
+ expect(sortedEntries(routing.parents)).toEqual([
+ [ref1, undefined],
+ [ref2, ref1],
+ ]);
+ expect(routing.objects).toEqual([
+ routeObj(
+ '/foo',
+ [ref1],
+ [routeObj('/bar', [ref2], [], undefined, plugin)],
+ undefined,
+ plugin,
),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
- });
- }).toThrow('Elements within the element prop tree may not contain paths');
- });
-
- it('should gather extension', () => {
- const { routing } = traverseElementTree({
- root: routeRoot(
-
-
- ,
- ),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
+ ]);
});
- expect(sortedEntries(routing.paths)).toEqual([[ref1, '/foo']]);
- expect(sortedEntries(routing.parents)).toEqual([[ref1, undefined]]);
- expect(routing.objects).toEqual([routeObj('/foo', [ref1], [], 'gathered')]);
- });
-
- it('should reset gathering if path prop is encountered', () => {
- const { routing } = traverseElementTree({
- root: routeRoot(
-
-
- } />
-
- ,
- ),
- discoverers: [childDiscoverer, routeElementDiscoverer],
- collectors: {
- routing: routingV2Collector,
- },
- });
-
- expect(sortedEntries(routing.paths)).toEqual([
- [ref1, '/foo'],
- [ref2, '/bar'],
- ]);
- expect(sortedEntries(routing.parents)).toEqual([
- [ref1, undefined],
- [ref2, ref1],
- ]);
- expect(routing.objects).toEqual([
- routeObj(
- '/foo',
- [ref1],
- [routeObj('/bar', [ref2], [], undefined, plugin)],
- 'gathered',
- ),
- ]);
- });
-
- it('should collect routes defined with different patterns', () => {
- const list = [
- ,
- ,
-
- } />
-
,
- ];
-
- const { routing } = traverseElementTree({
- root: routeRoot(
- <>
- }>
-
-
}>
-
-
- Some text here shouldn't be a problem
-
- {null}
-
-
} />
-
-
- {false}
- {list}
- {true}
- {0}
-
-
-