@@ -30,6 +30,14 @@ function createTestComponent(name: string, selector: string) {
30
30
>< Back</a
31
31
>
32
32
33
+ <a
34
+ id="forward-link"
35
+ *ngIf="routerHistory.nextUrl$ | async as nextUrl"
36
+ [href]="nextUrl"
37
+ (click)="onNext($event)"
38
+ >> Next</a
39
+ >
40
+
33
41
<a id="home-link" routerLink="/">Home</a>
34
42
<a id="about-link" routerLink="about">About</a>
35
43
<a id="company-link" routerLink="company">Company</a>
@@ -45,6 +53,11 @@ class TestAppComponent {
45
53
event . preventDefault ( ) ;
46
54
this . routerHistory . onNavigateBack ( ) ;
47
55
}
56
+
57
+ onNext ( event : MouseEvent ) {
58
+ event . preventDefault ( ) ;
59
+ this . routerHistory . onNavigateForward ( ) ;
60
+ }
48
61
}
49
62
50
63
describe ( RouterHistoryStore . name , ( ) => {
@@ -98,55 +111,176 @@ describe(RouterHistoryStore.name, () => {
98
111
}
99
112
100
113
it ( 'the URLs behave like the History API when navigating using links' , async ( ) => {
101
- expect . assertions ( 2 ) ;
114
+ expect . assertions ( 3 ) ;
102
115
103
116
const { click, routerHistory } = await setup ( ) ;
104
117
105
118
// At Home
119
+ // Previous: None
120
+ // Next: None
106
121
await click ( '#about-link' ) ;
107
122
// At About
123
+ // Previous: Home
124
+ // Next: None
108
125
await click ( '#company-link' ) ;
109
126
// At Company
127
+ // Previous: About
128
+ // Next: None
110
129
await click ( '#products-link' ) ;
111
130
// At Products
131
+ // Previous: Company
132
+ // Next: None
112
133
113
134
expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/products' ) ;
114
135
expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/company' ) ;
136
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( undefined ) ;
115
137
} ) ;
116
138
117
139
it ( 'the URLs behave like the History API when navigating back' , async ( ) => {
118
- expect . assertions ( 2 ) ;
140
+ expect . assertions ( 3 ) ;
141
+
142
+ const { click, routerHistory } = await setup ( ) ;
143
+
144
+ // At Home
145
+ // Previous: None
146
+ // Next: None
147
+ await click ( '#about-link' ) ;
148
+ // At About
149
+ // Previous: Home
150
+ // Next: None
151
+ await click ( '#company-link' ) ;
152
+ // At Company
153
+ // Previous: About
154
+ // Next: None
155
+ await click ( '#back-link' ) ;
156
+ // At About
157
+ // Previous: Home
158
+ // Next: Company
159
+
160
+ expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/about' ) ;
161
+ expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/home' ) ;
162
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( '/company' ) ;
163
+ } ) ;
164
+
165
+ it ( 'the URLs behave like the History API when navigating back twice' , async ( ) => {
166
+ expect . assertions ( 3 ) ;
167
+
168
+ const { click, routerHistory } = await setup ( ) ;
169
+
170
+ // At Home
171
+ // Previous: None
172
+ // Next: None
173
+ await click ( '#about-link' ) ;
174
+ // At About
175
+ // Previous: Home
176
+ // Next: None
177
+ await click ( '#company-link' ) ;
178
+ // At Company
179
+ // Previous: About
180
+ // Next: None
181
+ await click ( '#back-link' ) ;
182
+ // At About
183
+ // Previous: Home
184
+ // Next: Company
185
+ await click ( '#back-link' ) ;
186
+ // At Home
187
+ // Previous: None
188
+ // Next: About
189
+
190
+ expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/home' ) ;
191
+ expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( undefined ) ;
192
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( '/about' ) ;
193
+ } ) ;
194
+
195
+ it ( 'the URLs behave like the History API when navigating back twice then forward' , async ( ) => {
196
+ expect . assertions ( 3 ) ;
119
197
120
198
const { click, routerHistory } = await setup ( ) ;
121
199
122
200
// At Home
201
+ // Previous: None
202
+ // Next: None
123
203
await click ( '#about-link' ) ;
124
204
// At About
205
+ // Previous: Home
206
+ // Next: None
125
207
await click ( '#company-link' ) ;
126
208
// At Company
209
+ // Previous: About
210
+ // Next: None
127
211
await click ( '#back-link' ) ;
128
212
// At About
213
+ // Previous: Home
214
+ // Next: Company
215
+ await click ( '#back-link' ) ;
216
+ // At Home
217
+ // Previous: None
218
+ // Next: About
219
+ await click ( '#forward-link' ) ;
220
+ // At About
221
+ // Previous: Home
222
+ // Next: Company
129
223
130
224
expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/about' ) ;
131
225
expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/home' ) ;
226
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( '/company' ) ;
132
227
} ) ;
133
228
134
229
it ( 'the URLs behave like the History API when navigating back then using links' , async ( ) => {
135
- expect . assertions ( 2 ) ;
230
+ expect . assertions ( 3 ) ;
136
231
137
232
const { click, routerHistory } = await setup ( ) ;
138
233
139
234
// At Home
235
+ // Previous: None
236
+ // Next: None
140
237
await click ( '#about-link' ) ;
141
238
// At About
239
+ // Previous: Home
240
+ // Next: None
142
241
await click ( '#company-link' ) ;
143
242
// At Company
243
+ // Previous: About
244
+ // Next: None
144
245
await click ( '#back-link' ) ;
145
246
// At About
247
+ // Previous: Home
248
+ // Next: Company
146
249
await click ( '#products-link' ) ;
147
250
// At Products
251
+ // Previous: About
252
+ // Next: None
148
253
149
254
expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/products' ) ;
150
255
expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/about' ) ;
256
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( undefined ) ;
257
+ } ) ;
258
+
259
+ it ( 'the URLs behave like the History API when navigating back then forward' , async ( ) => {
260
+ expect . assertions ( 3 ) ;
261
+
262
+ const { click, routerHistory } = await setup ( ) ;
263
+
264
+ // At Home
265
+ await click ( '#about-link' ) ;
266
+ // At About
267
+ // Previous: Home
268
+ // Next: None
269
+ await click ( '#company-link' ) ;
270
+ // At Company
271
+ // Previous: About
272
+ // Next: None
273
+ await click ( '#back-link' ) ;
274
+ // At About
275
+ // Previous: Home
276
+ // Next: Company
277
+ await click ( '#forward-link' ) ;
278
+ // At Company
279
+ // Previous: About
280
+ // Next: None
281
+
282
+ expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/company' ) ;
283
+ expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/about' ) ;
284
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( undefined ) ;
151
285
} ) ;
152
286
} ) ;
0 commit comments