Skip to content

Commit 1b868fd

Browse files
authored
refactor: remove usage of Angular Router in example apps
Merge pull request #62 from brandonroberts/examples-cleanup
2 parents c179875 + 5d76891 commit 1b868fd

16 files changed

+15
-295
lines changed

apps/example-app/src/app/app-routing.module.ts

-26
This file was deleted.

apps/example-app/src/app/auth/auth-routing.module.ts

-13
This file was deleted.

apps/example-app/src/app/auth/effects/auth.effects.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TestBed } from '@angular/core/testing';
22
import { MatDialog } from '@angular/material/dialog';
3-
import { Router } from '@angular/router';
3+
import { Router } from 'angular-routing';
44
import { Actions } from '@ngrx/effects';
55
import { provideMockActions } from '@ngrx/effects/testing';
66
import { cold, hot } from 'jasmine-marbles';
@@ -33,7 +33,7 @@ describe('AuthEffects', () => {
3333
provideMockActions(() => actions$),
3434
{
3535
provide: Router,
36-
useValue: { navigate: jest.fn() },
36+
useValue: { go: jest.fn() },
3737
},
3838
{
3939
provide: MatDialog,

apps/example-app/src/app/auth/services/auth-guard.service.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Injectable } from '@angular/core';
2-
import { CanActivate } from '@angular/router';
32
import { Store, select } from '@ngrx/store';
43
import { Observable } from 'rxjs';
54
import { map, take } from 'rxjs/operators';
@@ -9,10 +8,10 @@ import * as fromAuth from '@example-app/auth/reducers';
98
@Injectable({
109
providedIn: 'root',
1110
})
12-
export class AuthGuard implements CanActivate {
11+
export class AuthGuard {
1312
constructor(private store: Store<fromAuth.State>) {}
1413

15-
canActivate(): Observable<boolean> {
14+
isLoggedIn(): Observable<boolean> {
1615
return this.store.pipe(
1716
select(fromAuth.selectLoggedIn),
1817
map((authed) => {

apps/example-app/src/app/books/books-routing.module.ts

-34
This file was deleted.

apps/example-app/src/app/books/books.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import * as fromBooks from '@example-app/books/reducers';
4444
`,
4545
})
4646
export class BooksComponent {
47-
loggedIn$ = this.authGuard.canActivate();
47+
loggedIn$ = this.authGuard.isLoggedIn();
4848

4949
constructor(private authGuard: AuthGuard) {}
5050
}

apps/example-app/src/app/books/containers/collection-page.component.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3-
import { RouterTestingModule } from '@angular/router/testing';
3+
import { RoutingModule } from 'angular-routing';
44

55
import { MockStore, provideMockStore } from '@ngrx/store/testing';
66

@@ -23,7 +23,7 @@ describe('Collection Page', () => {
2323

2424
beforeEach(() => {
2525
TestBed.configureTestingModule({
26-
imports: [NoopAnimationsModule, MaterialModule, RouterTestingModule],
26+
imports: [NoopAnimationsModule, MaterialModule, RoutingModule],
2727
declarations: [
2828
CollectionPageComponent,
2929
BookPreviewListComponent,

apps/example-app/src/app/books/containers/find-book-page.component.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { ReactiveFormsModule } from '@angular/forms';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4-
import { RouterTestingModule } from '@angular/router/testing';
4+
import { RoutingModule } from 'angular-routing';
55

66
import { MockStore, provideMockStore } from '@ngrx/store/testing';
77

@@ -27,7 +27,7 @@ describe('Find Book Page', () => {
2727
TestBed.configureTestingModule({
2828
imports: [
2929
NoopAnimationsModule,
30-
RouterTestingModule,
30+
RoutingModule,
3131
MaterialModule,
3232
ReactiveFormsModule,
3333
],

apps/example-app/src/app/books/containers/view-book-page.component.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { ActivatedRoute } from '@angular/router';
2+
import { RouteParams } from 'angular-routing';
33

44
import { provideMockStore, MockStore } from '@ngrx/store/testing';
55
import { BehaviorSubject } from 'rxjs';
@@ -18,15 +18,15 @@ import { MaterialModule } from '@example-app/material';
1818
describe('View Book Page', () => {
1919
let fixture: ComponentFixture<ViewBookPageComponent>;
2020
let store: MockStore;
21-
let route: ActivatedRoute;
21+
let routeParams: RouteParams;
2222

2323
beforeEach(() => {
2424
TestBed.configureTestingModule({
2525
imports: [MaterialModule],
2626
providers: [
2727
{
28-
provide: ActivatedRoute,
29-
useValue: { params: new BehaviorSubject({}) },
28+
provide: RouteParams,
29+
useValue: new BehaviorSubject({}),
3030
},
3131
provideMockStore(),
3232
],
@@ -41,7 +41,7 @@ describe('View Book Page', () => {
4141

4242
fixture = TestBed.createComponent(ViewBookPageComponent);
4343
store = TestBed.inject(MockStore);
44-
route = TestBed.inject(ActivatedRoute);
44+
routeParams = TestBed.inject(RouteParams);
4545

4646
jest.spyOn(store, 'dispatch');
4747
});
@@ -55,7 +55,7 @@ describe('View Book Page', () => {
5555
it('should dispatch a book.Select action on init', () => {
5656
const action = ViewBookPageActions.selectBook({ id: '2' });
5757

58-
(route.params as BehaviorSubject<any>).next({ id: '2' });
58+
(routeParams as BehaviorSubject<any>).next({ id: '2' });
5959

6060
expect(store.dispatch).toHaveBeenLastCalledWith(action);
6161
});

apps/example-app/src/app/books/guards/book-exists.guard.ts

-102
This file was deleted.

apps/example-app/src/app/books/guards/index.ts

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './user.effects';
2-
export * from './router.effects';

apps/example-app/src/app/core/effects/router.effects.spec.ts

-41
This file was deleted.

apps/example-app/src/app/core/effects/router.effects.ts

-34
This file was deleted.

0 commit comments

Comments
 (0)