forked from comixed/comixed
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue comixed#49] Add the CollectionPage component and tests.
- Loading branch information
Showing
7 changed files
with
277 additions
and
2 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
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
24 changes: 24 additions & 0 deletions
24
comixed-frontend/src/app/library/pages/collection-page/collection-page.component.html
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,24 @@ | ||
<h2>{{'collection-page.page-title'|translate:{collectionType: collectionType, count: collection.length} }}</h2> | ||
<p-table [value]='collection' | ||
paginator='true' | ||
alwaysShowPaginator='true' | ||
[rows]='rows' | ||
paginatorPosition='both'> | ||
<ng-template pTemplate='colgroup'> | ||
<col> | ||
<col class='cx-table-column-large'> | ||
</ng-template> | ||
<ng-template pTemplate='header'> | ||
<tr> | ||
<th>{{'collection-page.table.header.collection-name'|translate:{collectionType: collectionType.toString().toUpperCase()} }}</th> | ||
<th>{{'collection-page.table.header.collection-count'|translate}}</th> | ||
</tr> | ||
</ng-template> | ||
<ng-template pTemplate='body' | ||
let-entry> | ||
<tr> | ||
<td><a [routerLink]='["/collections", collectionType, entry.name]'>{{entry.name}}</a></td> | ||
<td class='cx-table-column-align-center'>{{'collection-page.table.value.collection-count'|translate:{count: entry.comicCount} }}</td> | ||
</tr> | ||
</ng-template> | ||
</p-table> |
Empty file.
111 changes: 111 additions & 0 deletions
111
comixed-frontend/src/app/library/pages/collection-page/collection-page.component.spec.ts
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,111 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2019, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { EffectsModule } from '@ngrx/effects'; | ||
import { StoreModule } from '@ngrx/store'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { BreadcrumbAdaptor } from 'app/adaptors/breadcrumb.adaptor'; | ||
import { LibraryDisplayAdaptor } from 'app/library'; | ||
import { CollectionAdaptor } from 'app/library/adaptors/collection.adaptor'; | ||
import { CollectionEffects } from 'app/library/effects/collection.effects'; | ||
import { | ||
COLLECTION_FEATURE_KEY, | ||
reducer | ||
} from 'app/library/reducers/collection.reducer'; | ||
import { AuthenticationAdaptor } from 'app/user'; | ||
import { MessageService } from 'primeng/api'; | ||
import { TableModule } from 'primeng/table'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { CollectionPageComponent } from './collection-page.component'; | ||
import objectContaining = jasmine.objectContaining; | ||
|
||
describe('CollectionPageComponent', () => { | ||
let component: CollectionPageComponent; | ||
let fixture: ComponentFixture<CollectionPageComponent>; | ||
let activatedRoute: ActivatedRoute; | ||
let router: Router; | ||
let messageService: MessageService; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
HttpClientTestingModule, | ||
RouterTestingModule, | ||
TranslateModule.forRoot(), | ||
StoreModule.forRoot({}), | ||
StoreModule.forFeature(COLLECTION_FEATURE_KEY, reducer), | ||
EffectsModule.forRoot([]), | ||
EffectsModule.forFeature([CollectionEffects]), | ||
TableModule | ||
], | ||
declarations: [CollectionPageComponent], | ||
providers: [ | ||
CollectionAdaptor, | ||
LibraryDisplayAdaptor, | ||
AuthenticationAdaptor, | ||
BreadcrumbAdaptor, | ||
MessageService, | ||
{ | ||
provide: ActivatedRoute, | ||
useValue: { | ||
params: new BehaviorSubject<{}>({}), | ||
queryParams: new BehaviorSubject<{}>({}) | ||
} | ||
} | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(CollectionPageComponent); | ||
component = fixture.componentInstance; | ||
activatedRoute = TestBed.get(ActivatedRoute); | ||
(activatedRoute.params as BehaviorSubject<{}>).next({ | ||
collectionType: 'publishers' | ||
}); | ||
router = TestBed.get(Router); | ||
spyOn(router, 'navigateByUrl'); | ||
messageService = TestBed.get(MessageService); | ||
spyOn(messageService, 'add'); | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('when the collection type is invalid', () => { | ||
beforeEach(() => { | ||
(activatedRoute.params as BehaviorSubject<{}>).next({ | ||
collectionType: 'farkle' | ||
}); | ||
}); | ||
|
||
it('redirects the user to the root page', () => { | ||
expect(router.navigateByUrl).toHaveBeenCalledWith('/home'); | ||
}); | ||
|
||
it('shows an error message', () => { | ||
expect(messageService.add).toHaveBeenCalledWith( | ||
objectContaining({ severity: 'error' }) | ||
); | ||
}); | ||
}); | ||
}); |
111 changes: 111 additions & 0 deletions
111
comixed-frontend/src/app/library/pages/collection-page/collection-page.component.ts
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,111 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2019, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { Title } from '@angular/platform-browser'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { BreadcrumbAdaptor } from 'app/adaptors/breadcrumb.adaptor'; | ||
import { LibraryDisplayAdaptor } from 'app/library'; | ||
import { CollectionAdaptor } from 'app/library/adaptors/collection.adaptor'; | ||
import { CollectionEntry } from 'app/library/models/collection-entry'; | ||
import { CollectionType } from 'app/library/models/collection-type.enum'; | ||
import { MessageService } from 'primeng/api'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-collection-page', | ||
templateUrl: './collection-page.component.html', | ||
styleUrls: ['./collection-page.component.scss'] | ||
}) | ||
export class CollectionPageComponent implements OnInit, OnDestroy { | ||
activatedRouteSubscription: Subscription; | ||
langChangeSubscription: Subscription; | ||
collectionType: CollectionType; | ||
collectionSubscription: Subscription; | ||
collection: CollectionEntry[]; | ||
rowsSubscription: Subscription; | ||
rows = 10; | ||
|
||
constructor( | ||
private router: Router, | ||
private activatedRoute: ActivatedRoute, | ||
private titleService: Title, | ||
private breadcrumbAdaptor: BreadcrumbAdaptor, | ||
private collectionAdaptor: CollectionAdaptor, | ||
private displayAdaptor: LibraryDisplayAdaptor, | ||
private translateService: TranslateService, | ||
private messageService: MessageService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.activatedRouteSubscription = this.activatedRoute.params.subscribe( | ||
params => { | ||
const typeName = params['collectionType'].toString().toUpperCase(); | ||
this.collectionType = CollectionType[typeName] as CollectionType; | ||
if (!!this.collectionType) { | ||
this.collectionSubscription = this.collectionAdaptor.entries$.subscribe( | ||
collection => (this.collection = collection) | ||
); | ||
this.collectionAdaptor.getCollection(this.collectionType); | ||
} else { | ||
this.messageService.add({ | ||
severity: 'error', | ||
detail: this.translateService.instant( | ||
'collections.error.invalid-collection-type', | ||
{ name: typeName } | ||
) | ||
}); | ||
this.router.navigateByUrl('/home'); | ||
} | ||
} | ||
); | ||
this.langChangeSubscription = this.translateService.onLangChange.subscribe( | ||
() => this.loadTranslations() | ||
); | ||
this.loadTranslations(); | ||
this.rowsSubscription = this.displayAdaptor.rows$.subscribe( | ||
rows => (this.rows = rows) | ||
); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.activatedRouteSubscription.unsubscribe(); | ||
this.rowsSubscription.unsubscribe(); | ||
this.collectionSubscription.unsubscribe(); | ||
} | ||
|
||
private loadTranslations() { | ||
this.titleService.setTitle( | ||
this.translateService.instant('collection-page.title', { | ||
collectionType: this.collectionType.toString().toUpperCase() | ||
}) | ||
); | ||
this.breadcrumbAdaptor.loadEntries([ | ||
{ | ||
label: this.translateService.instant('breadcrumb.collections.root') | ||
}, | ||
{ | ||
label: this.translateService.instant( | ||
`breadcrumb.collections.${this.collectionType}` | ||
), | ||
routerLink: [`/collections/${this.collectionType}`] | ||
} | ||
]); | ||
} | ||
} |
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