Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router-store): Add urlAfterRedirects to Minimal #2775

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions modules/router-store/spec/router_store_module.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing';
import { Router, RouterEvent } from '@angular/router';
import { Router, RouterEvent, NavigationEnd } from '@angular/router';
import {
routerReducer,
RouterReducerState,
Expand All @@ -11,7 +11,7 @@ import {
DefaultRouterStateSerializer,
} from '@ngrx/router-store';
import { select, Store, ActionsSubject } from '@ngrx/store';
import { withLatestFrom, filter } from 'rxjs/operators';
import { withLatestFrom, filter, skip } from 'rxjs/operators';

import { createTestModule } from './utils';

Expand Down Expand Up @@ -155,13 +155,12 @@ describe('Router Store Module', () => {
a.payload && a.payload.event;

describe('Full', () => {
it('should dispatch the full event', async () => {
it('should dispatch the full event', async (done) => {
const { actions, router } = setup(RouterState.Full);
actions
.pipe(filter(onlyRouterActions))
.subscribe(({ payload }) =>
expect(payload.event instanceof RouterEvent).toBe(true)
);
actions.pipe(filter(onlyRouterActions)).subscribe(({ payload }) => {
expect(payload.event instanceof RouterEvent).toBe(true);
done();
});

await router.navigateByUrl('/');
});
Expand Down Expand Up @@ -191,18 +190,43 @@ describe('Router Store Module', () => {
});

describe('Minimal', () => {
it('should dispatch the navigation id with url', async () => {
it('should dispatch the navigation id with url', async (done) => {
const { actions, router } = setup(RouterState.Minimal);
actions
.pipe(filter(onlyRouterActions))
.subscribe(({ payload }: any) => {
expect(payload.event instanceof RouterEvent).toBe(false);
expect(payload.event).toEqual({ id: 1, url: '/' });
done();
});

await router.navigateByUrl('/');
});

it('should dispatch the navigation with urlAfterRedirects', async (done) => {
const { actions, router } = setup(RouterState.Minimal);
actions
.pipe(
filter(onlyRouterActions),
// wait until NavigationEnd router event
filter(
({ payload }) =>
!!(payload.event as NavigationEnd).urlAfterRedirects
)
)
.subscribe(({ payload }: any) => {
expect(payload.event instanceof RouterEvent).toBe(false);
expect(payload.event).toEqual({
id: 1,
url: '/redirect',
urlAfterRedirects: '/next',
});
done();
});

await router.navigateByUrl('/redirect');
});

it('should use the minimal router serializer', () => {
const { serializer } = setup(RouterState.Minimal);
expect(serializer).toEqual(new MinimalRouterStateSerializer());
Expand Down
5 changes: 5 additions & 0 deletions modules/router-store/spec/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export function createTestModule(
loadChildren: 'test',
canLoad: ['CanLoadNext'],
},
{
path: 'redirect',
pathMatch: 'full',
redirectTo: 'next',
},
]),
StoreRouterConnectingModule.forRoot(opts.config),
],
Expand Down
8 changes: 7 additions & 1 deletion modules/router-store/src/router_store_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ export class StoreRouterConnectingModule {
event:
this.config.routerState === RouterState.Full
? payload.event
: { id: payload.event.id, url: payload.event.url },
: {
id: payload.event.id,
url: payload.event.url,
// safe, as it will just be `undefined` for non-NavigationEnd router events
urlAfterRedirects: (payload.event as NavigationEnd)
.urlAfterRedirects,
},
},
});
} finally {
Expand Down