@@ -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,7 +111,7 @@ 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
@@ -112,10 +125,11 @@ describe(RouterHistoryStore.name, () => {
112
125
113
126
expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/products' ) ;
114
127
expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/company' ) ;
128
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( undefined ) ;
115
129
} ) ;
116
130
117
131
it ( 'the URLs behave like the History API when navigating back' , async ( ) => {
118
- expect . assertions ( 2 ) ;
132
+ expect . assertions ( 3 ) ;
119
133
120
134
const { click, routerHistory } = await setup ( ) ;
121
135
@@ -129,10 +143,31 @@ describe(RouterHistoryStore.name, () => {
129
143
130
144
expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/about' ) ;
131
145
expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/home' ) ;
146
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( '/company' ) ;
147
+ } ) ;
148
+
149
+ it ( 'the URLs behave like the History API when navigating back twice' , async ( ) => {
150
+ expect . assertions ( 3 ) ;
151
+
152
+ const { click, routerHistory } = await setup ( ) ;
153
+
154
+ // At Home
155
+ await click ( '#about-link' ) ;
156
+ // At About
157
+ await click ( '#company-link' ) ;
158
+ // At Company
159
+ await click ( '#back-link' ) ;
160
+ // At About
161
+ await click ( '#back-link' ) ;
162
+ // At Home
163
+
164
+ expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/home' ) ;
165
+ expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( undefined ) ;
166
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( '/about' ) ;
132
167
} ) ;
133
168
134
169
it ( 'the URLs behave like the History API when navigating back then using links' , async ( ) => {
135
- expect . assertions ( 2 ) ;
170
+ expect . assertions ( 3 ) ;
136
171
137
172
const { click, routerHistory } = await setup ( ) ;
138
173
@@ -148,5 +183,34 @@ describe(RouterHistoryStore.name, () => {
148
183
149
184
expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/products' ) ;
150
185
expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/about' ) ;
186
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( undefined ) ;
187
+ } ) ;
188
+
189
+ it ( 'the URLs behave like the History API when navigating back then forward' , async ( ) => {
190
+ expect . assertions ( 3 ) ;
191
+
192
+ const { click, routerHistory } = await setup ( ) ;
193
+
194
+ // At Home
195
+ await click ( '#about-link' ) ;
196
+ // At About
197
+ // Previous: Home
198
+ // Next: None
199
+ await click ( '#company-link' ) ;
200
+ // At Company
201
+ // Previous: About
202
+ // Next: None
203
+ await click ( '#back-link' ) ;
204
+ // At About
205
+ // Previous: Home
206
+ // Next: Company
207
+ await click ( '#forward-link' ) ;
208
+ // At Company
209
+ // Previous: About
210
+ // Next: None
211
+
212
+ expect ( await firstValueFrom ( routerHistory . currentUrl$ ) ) . toBe ( '/company' ) ;
213
+ expect ( await firstValueFrom ( routerHistory . previousUrl$ ) ) . toBe ( '/about' ) ;
214
+ expect ( await firstValueFrom ( routerHistory . nextUrl$ ) ) . toBe ( undefined ) ;
151
215
} ) ;
152
216
} ) ;
0 commit comments