Skip to content

Commit

Permalink
feat: add url property to RouteNavigation
Browse files Browse the repository at this point in the history
- cleanup unused parameters of constructors in tests
- safety checks
  • Loading branch information
dhhyi committed Feb 19, 2020
1 parent 3563c41 commit 8f0168e
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 44 deletions.
10 changes: 3 additions & 7 deletions src/app/core/store/checkout/basket/basket.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,22 @@ describe('Basket Effects', () => {

describe('routeListenerForResettingBasketErrors$', () => {
it('should fire ResetBasketErrors when route basket or checkout/* is navigated', () => {
const action = new RouteNavigation({
path: 'checkout/payment',
params: {},
queryParams: {},
});
const action = new RouteNavigation({ path: 'checkout/payment' });
const expected = new basketActions.ResetBasketErrors();

actions$ = hot('a', { a: action });
expect(effects.routeListenerForResettingBasketErrors$).toBeObservable(cold('a', { a: expected }));
});

it('should not fire ResetBasketErrors when route basket or checkout/* is navigated with query param error=true', () => {
const action = new RouteNavigation({ path: 'checkout/payment', params: {}, queryParams: { error: true } });
const action = new RouteNavigation({ path: 'checkout/payment', queryParams: { error: true } });

actions$ = hot('a', { a: action });
expect(effects.routeListenerForResettingBasketErrors$).toBeObservable(cold('-'));
});

it('should not fire ResetBasketErrors when route /something is navigated', () => {
const action = new RouteNavigation({ path: 'something', params: {}, queryParams: {} });
const action = new RouteNavigation({ path: 'something' });

actions$ = hot('a', { a: action });
expect(effects.routeListenerForResettingBasketErrors$).toBeObservable(cold('-'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Viewconf Integration', () => {

expect(getCheckoutStep(store$.state)).toBe(2);

store$.dispatch(new RouteNavigation({ path: 'checkout', data: {} }));
store$.dispatch(new RouteNavigation({ path: 'checkout' }));

expect(getCheckoutStep(store$.state)).toBeUndefined();
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/store/error/error.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Error Reducer', () => {
},
{
state: { current: {}, type: ErrorActionTypes.TimeoutError },
action: new RouteNavigation({ path: 'error', params: {}, queryParams: {} }),
action: new RouteNavigation({ path: 'error' }),
expected: { current: {}, type: ErrorActionTypes.TimeoutError },
},
];
Expand Down
3 changes: 1 addition & 2 deletions src/app/core/store/orders/orders.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ describe('Orders Effects', () => {
const action = new RouteNavigation({
path: 'account/orders/:orderId',
params: { orderId },
queryParams: {},
});
const expected = new orderActions.SelectOrder({ orderId });

Expand All @@ -299,7 +298,7 @@ describe('Orders Effects', () => {
});

it('should not fire SelectOrder when route /something is navigated', () => {
const action = new RouteNavigation({ path: 'something', params: {}, queryParams: {} });
const action = new RouteNavigation({ path: 'something' });

actions$ = hot('a', { a: action });
expect(effects.routeListenerForSelectingOrder$).toBeObservable(cold('-'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('Categories Effects', () => {
const action = new RouteNavigation({
path: 'category/:categoryUniqueId',
params: { categoryUniqueId: 'dummy' },
queryParams: {},
});
const expected = new fromActions.SelectCategory({ categoryId: 'dummy' });

Expand All @@ -91,7 +90,6 @@ describe('Categories Effects', () => {
const action = new RouteNavigation({
path: 'category/:categoryUniqueId/product/:sku',
params: { categoryUniqueId: 'dummy', sku: 'foobar' },
queryParams: {},
});
const expected = new fromActions.SelectCategory({ categoryId: 'dummy' });

Expand All @@ -100,11 +98,7 @@ describe('Categories Effects', () => {
});

it('should not trigger SelectCategory when /something is visited', () => {
const action = new RouteNavigation({
path: 'something',
params: {},
queryParams: {},
});
const action = new RouteNavigation({ path: 'something' });

actions$ = hot('a', { a: action });
expect(effects.routeListenerForSelectingCategory$).toBeObservable(cold('-'));
Expand All @@ -114,7 +108,6 @@ describe('Categories Effects', () => {
const action = new RouteNavigation({
path: 'category/:categoryUniqueId',
params: { categoryUniqueId: 'dummy' },
queryParams: {},
});
const expected = new fromActions.SelectCategory({ categoryId: 'dummy' });

Expand Down Expand Up @@ -342,7 +335,6 @@ describe('Categories Effects', () => {
a: new RouteNavigation({
path: 'category/:categoryUniqueId',
params: { categoryUniqueId: category.uniqueId },
queryParams: {},
}),
});

Expand All @@ -359,7 +351,6 @@ describe('Categories Effects', () => {
a: new RouteNavigation({
path: 'category/:categoryUniqueId/product/:sku',
params: { categoryUniqueId: category.uniqueId, sku: 'dummy' },
queryParams: {},
}),
b: new fromActions.SelectedCategoryAvailable({ categoryId: category.uniqueId }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ describe('Products Effects', () => {
const action = new RouteNavigation({
path: 'category/:categoryUniqueId/product/:sku',
params: { categoryUniqueId: 'dummy', sku: 'foobar' },
queryParams: {},
});
const expected = new fromActions.SelectProduct({ sku: 'foobar' });

Expand All @@ -319,7 +318,6 @@ describe('Products Effects', () => {
const action = new RouteNavigation({
path: 'product/:sku',
params: { sku: 'foobar' },
queryParams: {},
});
const expected = new fromActions.SelectProduct({ sku: 'foobar' });

Expand All @@ -328,7 +326,7 @@ describe('Products Effects', () => {
});

it('should not fire SelectProduct when route /something is navigated', () => {
const action = new RouteNavigation({ path: 'something', params: {}, queryParams: {} });
const action = new RouteNavigation({ path: 'something' });

actions$ = hot('a', { a: action });
expect(effects.routeListenerForSelectingProducts$).toBeObservable(cold('-'));
Expand Down
1 change: 0 additions & 1 deletion src/app/core/store/shopping/search/search.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('Search Effects', () => {
const action = new RouteNavigation({
path: 'search/:searchTerm',
params: { searchTerm: 'dummy' },
queryParams: [],
});
actions$ = hot('a-a-|', { a: action });

Expand Down
22 changes: 22 additions & 0 deletions src/app/core/store/shopping/shopping-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/home"
path: "home"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down Expand Up @@ -269,6 +270,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123"}
queryParams: {}
data: {}
url: "/category/A.123"
path: "category/:categoryUniqueId"
[Shopping] Select Category:
categoryId: "A.123"
Expand Down Expand Up @@ -321,6 +323,7 @@ describe('Shopping Store', () => {
params: {"searchTerm":"something"}
queryParams: {}
data: {}
url: "/search/something"
path: "search/:searchTerm"
[Shopping] Set Search Term:
searchTerm: "something"
Expand Down Expand Up @@ -364,6 +367,7 @@ describe('Shopping Store', () => {
params: {"sku":"P2"}
queryParams: {}
data: {}
url: "/product/P2"
path: "product/:sku"
[Shopping] Select Product:
sku: "P2"
Expand Down Expand Up @@ -398,6 +402,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123"}
queryParams: {}
data: {}
url: "/category/A.123"
path: "category/:categoryUniqueId"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down Expand Up @@ -441,6 +446,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/compare"
path: "compare"
[Shopping] Deselect Category
`);
Expand Down Expand Up @@ -471,6 +477,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456"}
queryParams: {}
data: {}
url: "/category/A.123.456"
path: "category/:categoryUniqueId"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down Expand Up @@ -546,6 +553,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456","sku":"P1"}
queryParams: {}
data: {}
url: "/category/A.123.456/product/P1"
path: "category/:categoryUniqueId/product/:sku"
[Shopping] Select Product:
sku: "P1"
Expand Down Expand Up @@ -576,6 +584,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456"}
queryParams: {}
data: {}
url: "/category/A.123.456"
path: "category/:categoryUniqueId"
[ProductListing] Load More Products:
id: {"type":"category","value":"A.123.456"}
Expand All @@ -599,6 +608,7 @@ describe('Shopping Store', () => {
params: {"searchTerm":"something"}
queryParams: {}
data: {}
url: "/search/something"
path: "search/:searchTerm"
[Shopping] Deselect Category
[Shopping] Set Search Term:
Expand Down Expand Up @@ -643,6 +653,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456"}
queryParams: {}
data: {}
url: "/category/A.123.456"
path: "category/:categoryUniqueId"
[Shopping] Select Category:
categoryId: "A.123.456"
Expand Down Expand Up @@ -683,6 +694,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/compare"
path: "compare"
[Shopping] Deselect Category
`);
Expand Down Expand Up @@ -713,6 +725,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456","sku":"P1"}
queryParams: {}
data: {}
url: "/category/A.123.456/product/P1"
path: "category/:categoryUniqueId/product/:sku"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down Expand Up @@ -773,6 +786,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456"}
queryParams: {}
data: {}
url: "/category/A.123.456"
path: "category/:categoryUniqueId"
[ProductListing] Load More Products:
id: {"type":"category","value":"A.123.456"}
Expand Down Expand Up @@ -829,6 +843,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/compare"
path: "compare"
[Shopping] Deselect Category
[Shopping] Select Product:
Expand Down Expand Up @@ -861,6 +876,7 @@ describe('Shopping Store', () => {
params: {"sku":"P1"}
queryParams: {}
data: {}
url: "/product/P1"
path: "product/:sku"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down Expand Up @@ -901,6 +917,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/compare"
path: "compare"
[Shopping] Select Product:
sku: undefined
Expand Down Expand Up @@ -932,6 +949,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.456","sku":"P3"}
queryParams: {}
data: {}
url: "/category/A.123.456/product/P3"
path: "category/:categoryUniqueId/product/:sku"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down Expand Up @@ -968,6 +986,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/error"
path: "error"
[Shopping] Deselect Category
[Shopping] Select Product:
Expand Down Expand Up @@ -1003,6 +1022,7 @@ describe('Shopping Store', () => {
params: {"categoryUniqueId":"A.123.XXX"}
queryParams: {}
data: {}
url: "/category/A.123.XXX"
path: "category/:categoryUniqueId"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand All @@ -1022,6 +1042,7 @@ describe('Shopping Store', () => {
params: {}
queryParams: {}
data: {}
url: "/error"
path: "error"
[Shopping] Deselect Category
`);
Expand Down Expand Up @@ -1049,6 +1070,7 @@ describe('Shopping Store', () => {
params: {"searchTerm":"something"}
queryParams: {}
data: {}
url: "/search/something"
path: "search/:searchTerm"
[Viewconf Internal] Set Device Type:
deviceType: "pc"
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/store/user/user.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('User Effects', () => {

store$.dispatch(new ua.LoginUserSuccess(loginResponseData));

actions$ = of(new RouteNavigation({ path: 'login', queryParams: {} }));
actions$ = of(new RouteNavigation({ path: 'login' }));

effects.redirectAfterLogin$.subscribe(noop, fail, noop);

Expand All @@ -234,7 +234,7 @@ describe('User Effects', () => {

store$.dispatch(new ua.LoginUserSuccess(loginResponseData));

actions$ = of(new RouteNavigation({ path: 'home', queryParams: {} }));
actions$ = of(new RouteNavigation({ path: 'home' }));

effects.redirectAfterLogin$.subscribe(noop, fail, noop);

Expand Down Expand Up @@ -493,15 +493,15 @@ describe('User Effects', () => {

describe('resetUserError$', () => {
it('should not dispatch UserErrorReset action on router navigation if error is not set', () => {
actions$ = hot('a', { a: new RouteNavigation({ path: 'any', params: {}, queryParams: {} }) });
actions$ = hot('a', { a: new RouteNavigation({ path: 'any' }) });

expect(effects.resetUserError$).toBeObservable(cold('-'));
});

it('should dispatch UserErrorReset action on router navigation if error was set', () => {
store$.dispatch(new ua.LoginUserFail({ error: { message: 'error' } as HttpError }));

actions$ = hot('a', { a: new RouteNavigation({ path: 'any', params: {}, queryParams: {} }) });
actions$ = hot('a', { a: new RouteNavigation({ path: 'any' }) });

expect(effects.resetUserError$).toBeObservable(cold('a', { a: new ua.UserErrorReset() }));
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/store/viewconf/viewconf.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Viewconf Integration', () => {

expect(getWrapperClass(store$.state)).toEqual('something');

store$.dispatch(new RouteNavigation({ path: 'any', data: {} }));
store$.dispatch(new RouteNavigation({ path: 'any' }));

expect(getWrapperClass(store$.state)).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,6 @@ describe('Quote Request Effects', () => {
const action = new RouteNavigation({
path: 'quote-request/:quoteRequestId',
params: { quoteRequestId: 'QRID' },
queryParams: {},
});
const expected = new quoteRequestActions.SelectQuoteRequest({ id: 'QRID' });

Expand All @@ -1021,7 +1020,7 @@ describe('Quote Request Effects', () => {
});

it('should not fire SelectQuoteRequest when route /something is navigated', () => {
const action = new RouteNavigation({ path: 'something', params: {}, queryParams: {} });
const action = new RouteNavigation({ path: 'something' });

actions$ = hot('a', { a: action });
expect(effects.routeListenerForSelectingQuote$).toBeObservable(cold('-'));
Expand Down
6 changes: 5 additions & 1 deletion src/ngrx-router/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ export const ROUTER_NAVIGATION_TYPE = '[Router] Navigation';
export class RouteNavigation implements Action {
readonly type = ROUTER_NAVIGATION_TYPE;
// tslint:disable-next-line:no-any
constructor(public payload: { path: string; params?: any; queryParams?: any; data?: any }) {}
constructor(public payload: { path: string; url?: string; params?: any; queryParams?: any; data?: any }) {
if (!this.payload.url) {
this.payload.url = '/' + this.payload.path;
}
}
}
Loading

0 comments on commit 8f0168e

Please sign in to comment.