Skip to content

Commit 1412405

Browse files
committed
test: cover nested route URL
1 parent 01583dd commit 1412405

2 files changed

Lines changed: 224 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { RouterConfigOptions, Routes } from '@angular/router';
2+
import { firstValueFrom } from 'rxjs';
3+
import { RouterStore } from '../router-store';
4+
import { GlobalRouterStore } from './global-router-store';
5+
import { globalRouterStoreSetup } from './test-util/global-router-store-setup';
6+
import {
7+
GlobalRouterStoreTestChildComponent,
8+
GlobalRouterStoreTestGrandchildComponent,
9+
GlobalRouterStoreTestParentComponent,
10+
} from './test-util/global-router-store-test-components';
11+
12+
const routes: Routes = [
13+
{
14+
path: 'parent',
15+
component: GlobalRouterStoreTestParentComponent,
16+
children: [
17+
{
18+
path: 'child',
19+
component: GlobalRouterStoreTestChildComponent,
20+
children: [
21+
{
22+
path: 'grandchild',
23+
component: GlobalRouterStoreTestGrandchildComponent,
24+
},
25+
],
26+
},
27+
],
28+
},
29+
];
30+
31+
const expectedUrls = {
32+
parent: '/parent?query=param#fragment',
33+
child: '/parent/child?query=param#fragment',
34+
grandchild: '/parent/child/grandchild?query=param#fragment',
35+
} as const;
36+
37+
describe(`${GlobalRouterStore.name} nested route URL`, () => {
38+
describe('Given three layers of routes with components', () => {
39+
const paramsInheritanceStrategies: RouterConfigOptions['paramsInheritanceStrategy'][] =
40+
['always', 'emptyOnly'];
41+
42+
describe.each(paramsInheritanceStrategies)(
43+
' And the "%s" route parameter inheritance strategy is used',
44+
(paramsInheritanceStrategy) => {
45+
it.each(
46+
[
47+
GlobalRouterStoreTestParentComponent,
48+
GlobalRouterStoreTestChildComponent,
49+
GlobalRouterStoreTestGrandchildComponent,
50+
].map((RoutedComponent) => ({ RoutedComponent }))
51+
)(
52+
` And ${RouterStore.name} is injected at $RoutedComponent.name
53+
When the ${GlobalRouterStoreTestGrandchildComponent.name} route is activated
54+
Then the full URL for the ${GlobalRouterStoreTestGrandchildComponent.name} route is emitted`,
55+
async ({ RoutedComponent }) => {
56+
expect.assertions(1);
57+
const { routerStore } = await globalRouterStoreSetup({
58+
navigateTo: '/parent/child/grandchild?query=param#fragment',
59+
paramsInheritanceStrategy,
60+
RoutedComponent,
61+
routes,
62+
});
63+
64+
await expect(firstValueFrom(routerStore.url$)).resolves.toEqual(
65+
expectedUrls.grandchild
66+
);
67+
}
68+
);
69+
70+
it.each(
71+
[
72+
GlobalRouterStoreTestParentComponent,
73+
GlobalRouterStoreTestChildComponent,
74+
].map((RoutedComponent) => ({ RoutedComponent }))
75+
)(
76+
` And ${RouterStore.name} is injected at $RoutedComponent.name
77+
When the ${GlobalRouterStoreTestChildComponent.name} route is activated
78+
Then the full URL for the ${GlobalRouterStoreTestChildComponent.name} route is emitted`,
79+
async ({ RoutedComponent }) => {
80+
expect.assertions(1);
81+
const { routerStore } = await globalRouterStoreSetup({
82+
navigateTo: '/parent/child?query=param#fragment',
83+
paramsInheritanceStrategy,
84+
RoutedComponent,
85+
routes,
86+
});
87+
88+
await expect(firstValueFrom(routerStore.url$)).resolves.toEqual(
89+
expectedUrls.child
90+
);
91+
}
92+
);
93+
94+
it(` And ${RouterStore.name} is injected at ${GlobalRouterStoreTestParentComponent}.name
95+
When the ${GlobalRouterStoreTestParentComponent.name} route is activated
96+
Then full URL for the ${GlobalRouterStoreTestParentComponent.name} route is emitted`, async () => {
97+
expect.assertions(1);
98+
const { routerStore } = await globalRouterStoreSetup({
99+
navigateTo: '/parent?query=param#fragment',
100+
paramsInheritanceStrategy,
101+
RoutedComponent: GlobalRouterStoreTestParentComponent,
102+
routes,
103+
});
104+
105+
await expect(firstValueFrom(routerStore.url$)).resolves.toEqual(
106+
expectedUrls.parent
107+
);
108+
});
109+
}
110+
);
111+
});
112+
});
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { RouterConfigOptions, Routes } from '@angular/router';
2+
import { firstValueFrom } from 'rxjs';
3+
import { RouterStore } from '../router-store';
4+
import { LocalRouterStore } from './local-router-store';
5+
import { localRouterStoreSetup } from './test-util/local-router-store-setup';
6+
import {
7+
LocalRouterStoreTestChildComponent,
8+
LocalRouterStoreTestGrandchildComponent,
9+
LocalRouterStoreTestParentComponent,
10+
} from './test-util/local-router-store-test-components';
11+
12+
const routes: Routes = [
13+
{
14+
path: 'parent',
15+
component: LocalRouterStoreTestParentComponent,
16+
children: [
17+
{
18+
path: 'child',
19+
component: LocalRouterStoreTestChildComponent,
20+
children: [
21+
{
22+
path: 'grandchild',
23+
component: LocalRouterStoreTestGrandchildComponent,
24+
},
25+
],
26+
},
27+
],
28+
},
29+
];
30+
31+
const expectedUrls = {
32+
parent: '/parent?query=param#fragment',
33+
child: '/parent/child?query=param#fragment',
34+
grandchild: '/parent/child/grandchild?query=param#fragment',
35+
} as const;
36+
37+
describe(`${LocalRouterStore.name} nested route URL`, () => {
38+
describe('Given three layers of routes with components', () => {
39+
const paramsInheritanceStrategies: RouterConfigOptions['paramsInheritanceStrategy'][] =
40+
['always', 'emptyOnly'];
41+
42+
describe.each(paramsInheritanceStrategies)(
43+
' And the "%s" route parameter inheritance strategy is used',
44+
(paramsInheritanceStrategy) => {
45+
it.each(
46+
[
47+
LocalRouterStoreTestParentComponent,
48+
LocalRouterStoreTestChildComponent,
49+
LocalRouterStoreTestGrandchildComponent,
50+
].map((RoutedComponent) => ({ RoutedComponent }))
51+
)(
52+
` And ${RouterStore.name} is injected at $RoutedComponent.name
53+
When the ${LocalRouterStoreTestGrandchildComponent.name} route is activated
54+
Then the full URL for the ${LocalRouterStoreTestGrandchildComponent.name} route is emitted`,
55+
async ({ RoutedComponent }) => {
56+
expect.assertions(1);
57+
const { routerStore } = await localRouterStoreSetup({
58+
navigateTo: '/parent/child/grandchild?query=param#fragment',
59+
paramsInheritanceStrategy,
60+
RoutedComponent,
61+
routes,
62+
});
63+
64+
await expect(firstValueFrom(routerStore.url$)).resolves.toEqual(
65+
expectedUrls.grandchild
66+
);
67+
}
68+
);
69+
70+
it.each(
71+
[
72+
LocalRouterStoreTestParentComponent,
73+
LocalRouterStoreTestChildComponent,
74+
].map((RoutedComponent) => ({ RoutedComponent }))
75+
)(
76+
` And ${RouterStore.name} is injected at $RoutedComponent.name
77+
When the ${LocalRouterStoreTestChildComponent.name} route is activated
78+
Then the full URL for the ${LocalRouterStoreTestChildComponent.name} route is emitted`,
79+
async ({ RoutedComponent }) => {
80+
expect.assertions(1);
81+
const { routerStore } = await localRouterStoreSetup({
82+
navigateTo: '/parent/child?query=param#fragment',
83+
paramsInheritanceStrategy,
84+
RoutedComponent,
85+
routes,
86+
});
87+
88+
await expect(firstValueFrom(routerStore.url$)).resolves.toEqual(
89+
expectedUrls.child
90+
);
91+
}
92+
);
93+
94+
it(` And ${RouterStore.name} is injected at ${LocalRouterStoreTestParentComponent}.name
95+
When the ${LocalRouterStoreTestParentComponent.name} route is activated
96+
Then full URL for the ${LocalRouterStoreTestParentComponent.name} route is emitted`, async () => {
97+
expect.assertions(1);
98+
const { routerStore } = await localRouterStoreSetup({
99+
navigateTo: '/parent?query=param#fragment',
100+
paramsInheritanceStrategy,
101+
RoutedComponent: LocalRouterStoreTestParentComponent,
102+
routes,
103+
});
104+
105+
await expect(firstValueFrom(routerStore.url$)).resolves.toEqual(
106+
expectedUrls.parent
107+
);
108+
});
109+
}
110+
);
111+
});
112+
});

0 commit comments

Comments
 (0)