-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router-store): serialize routeConfig inside the default serializ…
…er (#1384) BREAKING CHANGE: The default router serializer now returns a `null` value for `routeConfig` when `routeConfig` doesn't exist on the `ActivatedRouteSnapshot` instead of an empty object. BEFORE: ```json { "routeConfig": {} } ``` AFTER: ```json { "routeConfig": null } ```
- Loading branch information
1 parent
0e38673
commit 18a16d4
Showing
3 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { RouterStateSnapshot } from '@angular/router'; | ||
import { DefaultRouterStateSerializer } from '../src'; | ||
|
||
describe('serializer', () => { | ||
it('should serialize all properties', () => { | ||
const serializer = new DefaultRouterStateSerializer(); | ||
const snapshot = createSnapshot(); | ||
const routerState = { | ||
url: 'url', | ||
root: snapshot, | ||
} as RouterStateSnapshot; | ||
|
||
const actual = serializer.serialize(routerState); | ||
const expected = { | ||
url: 'url', | ||
root: createExpectedSnapshot(), | ||
}; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should serialize with an empty routeConfig', () => { | ||
const serializer = new DefaultRouterStateSerializer(); | ||
const snapshot = { ...createSnapshot(), routeConfig: null }; | ||
const routerState = { | ||
url: 'url', | ||
root: snapshot, | ||
} as RouterStateSnapshot; | ||
|
||
const actual = serializer.serialize(routerState); | ||
const expected = { | ||
url: 'url', | ||
root: { | ||
...createExpectedSnapshot(), | ||
routeConfig: null, | ||
component: undefined, | ||
}, | ||
}; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should serialize children', () => { | ||
const serializer = new DefaultRouterStateSerializer(); | ||
const snapshot = { | ||
...createSnapshot(), | ||
children: [createSnapshot('child')], | ||
}; | ||
const routerState = { | ||
url: 'url', | ||
root: snapshot, | ||
} as RouterStateSnapshot; | ||
|
||
const actual = serializer.serialize(routerState); | ||
|
||
const expected = { | ||
url: 'url', | ||
root: { | ||
...createExpectedSnapshot(), | ||
firstChild: createExpectedSnapshot('child'), | ||
children: [createExpectedSnapshot('child')], | ||
}, | ||
}; | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
function createSnapshot(prefix = 'root'): any { | ||
return { | ||
params: `${prefix}-route.params`, | ||
paramMap: `${prefix}-route.paramMap`, | ||
data: `${prefix}-route.data`, | ||
url: `${prefix}-route.url`, | ||
outlet: `${prefix}-route.outlet`, | ||
routeConfig: { | ||
component: `${prefix}-route.routeConfig.component`, | ||
path: `${prefix}-route.routeConfig.path`, | ||
pathMatch: `${prefix}-route.routeConfig.pathMatch`, | ||
redirectTo: `${prefix}-route.routeConfig.redirectTo`, | ||
outlet: `${prefix}-route.routeConfig.outlet`, | ||
}, | ||
queryParams: `${prefix}-route.queryParams`, | ||
queryParamMap: `${prefix}-route.queryParamMap`, | ||
fragment: `${prefix}-route.fragment`, | ||
root: `${prefix}-route.root`, | ||
parent: `${prefix}-route.parent`, | ||
pathFromRoot: `${prefix}-route.params`, | ||
firstChild: null, | ||
children: [], | ||
}; | ||
} | ||
|
||
function createExpectedSnapshot(prefix = 'root') { | ||
return { | ||
...createSnapshot(prefix), | ||
component: `${prefix}-route.routeConfig.component`, | ||
root: undefined, | ||
parent: undefined, | ||
firstChild: undefined, | ||
pathFromRoot: undefined, | ||
}; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters