-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#7 created item details module and changed the home page service to w…
…ikidata
- Loading branch information
1 parent
c5e8147
commit 9684578
Showing
24 changed files
with
1,160 additions
and
850 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface ItemDetails { | ||
name: string; | ||
label?: string; | ||
language: string; | ||
wdt: string; | ||
wd: string; | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/app/features/category-item-details/category-item-details.service.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,59 @@ | ||
import { Type } from '@angular/core'; | ||
import { TestBed, async } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
|
||
import { CoreModule, HttpCacheService } from '@app/core'; | ||
import { QuoteService } from './quote.service'; | ||
|
||
describe('QuoteService', () => { | ||
let quoteService: QuoteService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [CoreModule, HttpClientTestingModule], | ||
providers: [HttpCacheService, QuoteService] | ||
}); | ||
|
||
quoteService = TestBed.get(QuoteService); | ||
httpMock = TestBed.get(HttpTestingController as Type<HttpTestingController>); | ||
|
||
const htttpCacheService = TestBed.get(HttpCacheService); | ||
htttpCacheService.cleanCache(); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
|
||
describe('getRandomQuote', () => { | ||
it('should return a random Chuck Norris quote', () => { | ||
// Arrange | ||
const mockQuote = { value: 'a random quote' }; | ||
|
||
// Act | ||
const randomQuoteSubscription = quoteService.getRandomQuote({ category: 'toto' }); | ||
|
||
// Assert | ||
randomQuoteSubscription.subscribe((quote: string) => { | ||
expect(quote).toEqual(mockQuote.value); | ||
}); | ||
httpMock.expectOne({}).flush(mockQuote); | ||
}); | ||
|
||
it('should return a string in case of error', () => { | ||
// Act | ||
const randomQuoteSubscription = quoteService.getRandomQuote({ category: 'toto' }); | ||
|
||
// Assert | ||
randomQuoteSubscription.subscribe((quote: string) => { | ||
expect(typeof quote).toEqual('string'); | ||
expect(quote).toContain('Error'); | ||
}); | ||
httpMock.expectOne({}).flush(null, { | ||
status: 500, | ||
statusText: 'error' | ||
}); | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/app/features/category-item-details/category-item-details.service.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,29 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable, of } from 'rxjs'; | ||
import { map, catchError } from 'rxjs/operators'; | ||
|
||
const routes = { | ||
entities: (c: WikidataContext) => `/Special:EntityData/Q295150${c.qcode}.json` | ||
}; | ||
|
||
export interface WikidataContext { | ||
qcode: string; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class CategoryItemDetailsService { | ||
constructor(private httpClient: HttpClient) {} | ||
|
||
getRandomQuote(context: WikidataContext): Observable<string> { | ||
return this.httpClient | ||
.cache() | ||
.get(routes.entities(context)) | ||
.pipe( | ||
map((body: any) => body.value), | ||
catchError(() => of('Error, could not load joke :-(')) | ||
); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...es/category-item-details/item-details/components/item-details/item-details.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,3 @@ | ||
<ion-item color="primary"> | ||
Coming soon. | ||
</ion-item> |
3 changes: 3 additions & 0 deletions
3
...es/category-item-details/item-details/components/item-details/item-details.component.scss
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,3 @@ | ||
ion-item { | ||
cursor: pointer; | ||
} |
15 changes: 15 additions & 0 deletions
15
...ures/category-item-details/item-details/components/item-details/item-details.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,15 @@ | ||
import { Component, OnInit, Input } from '@angular/core'; | ||
import { ItemDetails } from '@app/core/interfaces/item-details'; | ||
|
||
@Component({ | ||
selector: 'item-details', | ||
templateUrl: './item-details.component.html', | ||
styleUrls: ['./item-details.component.scss'] | ||
}) | ||
export class ItemDetailsComponent implements OnInit { | ||
@Input() itemDetails: ItemDetails; | ||
|
||
constructor() {} | ||
|
||
ngOnInit() {} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ry-item-details/item-details/container/item-details/item-details-container.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,17 @@ | ||
<ion-header> | ||
<ion-toolbar color="primary"> | ||
<ion-buttons slot="start"> | ||
<ion-menu-button></ion-menu-button> | ||
</ion-buttons> | ||
<ion-title><span translate>Categories</span></ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<ion-card class="ion-text-center"> | ||
<ion-card-content> | ||
<ion-list *ngFor="let category of (store.state$ | async).categories"> | ||
<categories-category [category]="category"></categories-category> | ||
</ion-list> | ||
</ion-card-content> | ||
</ion-card> | ||
</ion-content> |
Empty file.
23 changes: 23 additions & 0 deletions
23
...item-details/item-details/container/item-details/item-details-container.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,23 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { CategoriesContainerComponent } from './categories-container.component'; | ||
|
||
describe('CategoriesComponent', () => { | ||
let component: CategoriesContainerComponent; | ||
let fixture: ComponentFixture<CategoriesContainerComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [CategoriesContainerComponent] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CategoriesContainerComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...gory-item-details/item-details/container/item-details/item-details-container.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,18 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { categoriesList } from '@env/environment'; | ||
import { ItemDetailsStore } from '../../item-details-store'; | ||
|
||
@Component({ | ||
selector: 'app-categories', | ||
templateUrl: './item-details-container.component.html', | ||
styleUrls: ['./item-details-container.component.scss'], | ||
providers: [ItemDetailsStore] | ||
}) | ||
export class ItemDetailsContainerComponent implements OnInit { | ||
constructor(public store: ItemDetailsStore) {} | ||
|
||
ngOnInit() { | ||
// this.store.fetchList(); | ||
console.log(' this.store', this.store); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/app/features/category-item-details/item-details/item-details-store-state.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,7 @@ | ||
import { ItemDetails } from '@app/core/interfaces/item-details'; | ||
|
||
const initItemDetails: ItemDetails[] = []; | ||
|
||
export class ItemDetailsState { | ||
itemDetails: ItemDetails[] = initItemDetails; | ||
} |
Oops, something went wrong.