forked from ngrx/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Example): Add books containers test (ngrx#603)
- Loading branch information
1 parent
551da92
commit 2fbcd24
Showing
8 changed files
with
514 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
example-app/app/books/containers/__snapshots__/collection-page.spec.ts.snap
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,38 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Collection Page should compile 1`] = ` | ||
<bc-collection-page | ||
books$={[Function Store]} | ||
store={[Function Store]} | ||
> | ||
<mat-card | ||
_ngcontent-c0="" | ||
class="mat-card" | ||
> | ||
<mat-card-title | ||
_ngcontent-c0="" | ||
class="mat-card-title" | ||
> | ||
My Collection | ||
</mat-card-title> | ||
</mat-card> | ||
<bc-book-preview-list | ||
_ngcontent-c0="" | ||
_nghost-c2="" | ||
ng-reflect-books="" | ||
> | ||
</bc-book-preview-list> | ||
</bc-collection-page> | ||
`; |
163 changes: 163 additions & 0 deletions
163
example-app/app/books/containers/__snapshots__/find-book-page.spec.ts.snap
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,163 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Find Book Page should compile 1`] = ` | ||
<bc-find-book-page | ||
books$={[Function Store]} | ||
error$={[Function Store]} | ||
loading$={[Function Store]} | ||
searchQuery$={[Function Store]} | ||
store={[Function Store]} | ||
> | ||
<bc-book-search | ||
_nghost-c0="" | ||
ng-reflect-error="" | ||
ng-reflect-query="" | ||
ng-reflect-searching="false" | ||
> | ||
<mat-card | ||
_ngcontent-c0="" | ||
class="mat-card" | ||
> | ||
<mat-card-title | ||
_ngcontent-c0="" | ||
class="mat-card-title" | ||
> | ||
Find a Book | ||
</mat-card-title> | ||
<mat-card-content | ||
_ngcontent-c0="" | ||
class="mat-card-content" | ||
> | ||
<mat-input-container | ||
_ngcontent-c0="" | ||
class="mat-input-container mat-form-field ng-tns-c3-0 mat-form-field-type-mat-input mat-form-field-can-float mat-primary" | ||
> | ||
<div | ||
class="mat-input-wrapper mat-form-field-wrapper" | ||
> | ||
<div | ||
class="mat-input-flex mat-form-field-flex" | ||
> | ||
<div | ||
class="mat-input-infix mat-form-field-infix" | ||
> | ||
<input | ||
_ngcontent-c0="" | ||
aria-invalid="false" | ||
class="mat-input-element mat-form-field-autofill-control" | ||
id="mat-input-0" | ||
matinput="" | ||
ng-reflect-placeholder="Search for a book" | ||
ng-reflect-value="" | ||
placeholder="Search for a book" | ||
/> | ||
<span | ||
class="mat-input-placeholder-wrapper mat-form-field-placeholder-wrapper" | ||
> | ||
<label | ||
aria-owns="mat-input-0" | ||
class="mat-input-placeholder mat-form-field-placeholder ng-tns-c3-0 mat-empty mat-form-field-empty" | ||
for="mat-input-0" | ||
> | ||
Search for a book | ||
</label> | ||
</span> | ||
</div> | ||
</div> | ||
<div | ||
class="mat-input-underline mat-form-field-underline" | ||
> | ||
<span | ||
class="mat-input-ripple mat-form-field-ripple" | ||
/> | ||
</div> | ||
<div | ||
class="mat-input-subscript-wrapper mat-form-field-subscript-wrapper" | ||
ng-reflect-ng-switch="hint" | ||
> | ||
<div | ||
class="mat-input-hint-wrapper mat-form-field-hint-wrapper ng-tns-c3-0 ng-trigger ng-trigger-transitionMessages" | ||
style="opacity: 1;" | ||
> | ||
<div | ||
class="mat-input-hint-spacer mat-form-field-hint-spacer" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</mat-input-container> | ||
<mat-spinner | ||
_ngcontent-c0="" | ||
class="mat-spinner mat-progress-spinner mat-primary mat-progress-spinner-indeterminate-animation" | ||
mode="indeterminate" | ||
ng-reflect-diameter="30" | ||
ng-reflect-stroke-width="3" | ||
role="progressbar" | ||
style="width: 30px; height: 30px;" | ||
> | ||
<svg | ||
focusable="false" | ||
preserveAspectRatio="xMidYMid meet" | ||
style="width: 30px; height: 30px;" | ||
viewBox="0 0 30 30" | ||
> | ||
<circle | ||
cx="50%" | ||
cy="50%" | ||
r="10" | ||
style="stroke-dasharray: 62.83185307179586px; stroke-width: 3px;" | ||
/> | ||
</svg> | ||
</mat-spinner> | ||
</mat-card-content> | ||
<mat-card-footer | ||
_ngcontent-c0="" | ||
class="mat-card-footer" | ||
> | ||
</mat-card-footer> | ||
</mat-card> | ||
</bc-book-search> | ||
<bc-book-preview-list | ||
_nghost-c1="" | ||
ng-reflect-books="" | ||
> | ||
</bc-book-preview-list> | ||
</bc-find-book-page> | ||
`; |
23 changes: 23 additions & 0 deletions
23
example-app/app/books/containers/__snapshots__/selected-book-page.spec.ts.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Selected Book Page should compile 1`] = ` | ||
<bc-selected-book-page | ||
book$={[Function Store]} | ||
isSelectedBookInCollection$={[Function Store]} | ||
store={[Function Store]} | ||
> | ||
<bc-book-detail | ||
_nghost-c0="" | ||
ng-reflect-in-collection="false" | ||
> | ||
</bc-book-detail> | ||
</bc-selected-book-page> | ||
`; |
26 changes: 26 additions & 0 deletions
26
example-app/app/books/containers/__snapshots__/view-book-page.spec.ts.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`View Book Page should compile 1`] = ` | ||
<bc-view-book-page | ||
actionsSubscription={[Function Subscriber]} | ||
> | ||
<bc-selected-book-page> | ||
<bc-book-detail | ||
_nghost-c0="" | ||
> | ||
</bc-book-detail> | ||
</bc-selected-book-page> | ||
</bc-view-book-page> | ||
`; |
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,61 @@ | ||
import { CollectionPageComponent } from './collection-page'; | ||
import { combineReducers, Store, StoreModule } from '@ngrx/store'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { MatCardModule, MatInputModule } from '@angular/material'; | ||
import { BookPreviewListComponent } from '../components/book-preview-list'; | ||
import { BookPreviewComponent } from '../components/book-preview'; | ||
import * as collection from '../actions/collection'; | ||
import * as fromBooks from '../reducers'; | ||
import { EllipsisPipe } from '../../shared/pipes/ellipsis'; | ||
import { AddCommasPipe } from '../../shared/pipes/add-commas'; | ||
import { BookAuthorsComponent } from '../components/book-authors'; | ||
|
||
describe('Collection Page', () => { | ||
let fixture: ComponentFixture<CollectionPageComponent>; | ||
let store: Store<fromBooks.State>; | ||
let instance: CollectionPageComponent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NoopAnimationsModule, | ||
StoreModule.forRoot({ | ||
books: combineReducers(fromBooks.reducers), | ||
}), | ||
MatCardModule, | ||
MatInputModule, | ||
RouterTestingModule, | ||
], | ||
declarations: [ | ||
CollectionPageComponent, | ||
BookPreviewListComponent, | ||
BookPreviewComponent, | ||
BookAuthorsComponent, | ||
AddCommasPipe, | ||
EllipsisPipe, | ||
], | ||
}); | ||
|
||
fixture = TestBed.createComponent(CollectionPageComponent); | ||
instance = fixture.componentInstance; | ||
store = TestBed.get(Store); | ||
|
||
spyOn(store, 'dispatch').and.callThrough(); | ||
}); | ||
|
||
it('should compile', () => { | ||
fixture.detectChanges(); | ||
|
||
expect(fixture).toMatchSnapshot(); | ||
}); | ||
|
||
it('should dispatch a collection.Load on init', () => { | ||
const action = new collection.Load(); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(store.dispatch).toHaveBeenCalledWith(action); | ||
}); | ||
}); |
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,72 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { | ||
MatCardModule, | ||
MatInputModule, | ||
MatProgressSpinnerModule, | ||
} from '@angular/material'; | ||
import { combineReducers, Store, StoreModule } from '@ngrx/store'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
import { BookSearchComponent } from '../components/book-search'; | ||
import { BookPreviewComponent } from '../components/book-preview'; | ||
import { BookPreviewListComponent } from '../components/book-preview-list'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { EllipsisPipe } from '../../shared/pipes/ellipsis'; | ||
import { BookAuthorsComponent } from '../components/book-authors'; | ||
import { AddCommasPipe } from '../../shared/pipes/add-commas'; | ||
import { FindBookPageComponent } from './find-book-page'; | ||
import * as book from '../actions/book'; | ||
import * as fromBooks from '../reducers'; | ||
|
||
describe('Find Book Page', () => { | ||
let fixture: ComponentFixture<FindBookPageComponent>; | ||
let store: Store<fromBooks.State>; | ||
let instance: FindBookPageComponent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NoopAnimationsModule, | ||
StoreModule.forRoot({ | ||
books: combineReducers(fromBooks.reducers), | ||
}), | ||
RouterTestingModule, | ||
MatInputModule, | ||
MatCardModule, | ||
MatProgressSpinnerModule, | ||
ReactiveFormsModule, | ||
], | ||
declarations: [ | ||
FindBookPageComponent, | ||
BookSearchComponent, | ||
BookPreviewComponent, | ||
BookPreviewListComponent, | ||
BookAuthorsComponent, | ||
AddCommasPipe, | ||
EllipsisPipe, | ||
], | ||
}); | ||
|
||
fixture = TestBed.createComponent(FindBookPageComponent); | ||
instance = fixture.componentInstance; | ||
store = TestBed.get(Store); | ||
|
||
spyOn(store, 'dispatch').and.callThrough(); | ||
}); | ||
|
||
it('should compile', () => { | ||
fixture.detectChanges(); | ||
|
||
expect(fixture).toMatchSnapshot(); | ||
}); | ||
|
||
it('should dispatch a book.Search action on search', () => { | ||
const $event: string = 'book name'; | ||
const action = new book.Search($event); | ||
|
||
instance.search($event); | ||
|
||
expect(store.dispatch).toHaveBeenCalledWith(action); | ||
}); | ||
}); |
Oops, something went wrong.