-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(category,demo): add category view to demo (#2620)
- Loading branch information
Showing
15 changed files
with
298 additions
and
26 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
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,48 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { | ||
RouterModule, | ||
Routes, | ||
} from '@angular/router'; | ||
|
||
import { | ||
DaffCategoryPageIdResolver, | ||
DaffCategoryPageUrlResolver, | ||
DaffCategoryRoutingModule, | ||
} from '@daffodil/category/routing'; | ||
import { daffDataPathUrlMatcher } from '@daffodil/external-router'; | ||
|
||
import { CategoryViewComponent } from './pages/category-view/category-view.component'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: '', | ||
pathMatch: 'full', | ||
children: [ | ||
{ | ||
path: ':id', | ||
component: CategoryViewComponent, | ||
resolve: { | ||
product: DaffCategoryPageIdResolver, | ||
}, | ||
}, | ||
{ | ||
path: '', | ||
component: CategoryViewComponent, | ||
resolve: { | ||
product: DaffCategoryPageUrlResolver, | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ | ||
RouterModule.forChild(routes), | ||
DaffCategoryRoutingModule, | ||
], | ||
exports: [ | ||
RouterModule, | ||
], | ||
}) | ||
export class CategoryRoutingModule { } |
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 { NgModule } from '@angular/core'; | ||
|
||
import { CategoryRoutingModule } from './category-routing.module'; | ||
import { CategoryViewModule } from './pages/category-view/category-view.module'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CategoryViewModule, | ||
CategoryRoutingModule, | ||
], | ||
exports: [ | ||
CategoryViewModule, | ||
], | ||
}) | ||
export class CategoryModule { } |
7 changes: 7 additions & 0 deletions
7
apps/demo/src/app/category/pages/category-view/category-view.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,7 @@ | ||
<daff-container size="lg"> | ||
<ng-container *ngIf="(loading$ | async) === false"> | ||
<h1>{{(category$ | async).name}}</h1> | ||
<demo-product-grid [products]="products$ | async"></demo-product-grid> | ||
</ng-container> | ||
<daff-loading-icon *ngIf="loading$ | async"></daff-loading-icon> | ||
<daff-container> |
120 changes: 120 additions & 0 deletions
120
apps/demo/src/app/category/pages/category-view/category-view.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,120 @@ | ||
import { | ||
waitForAsync, | ||
ComponentFixture, | ||
TestBed, | ||
} from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffCategory } from '@daffodil/category'; | ||
import { | ||
DaffCategoryStateTestingModule, | ||
MockDaffCategoryFacade, | ||
} from '@daffodil/category/state/testing'; | ||
import { DaffCategoryFactory } from '@daffodil/category/testing'; | ||
import { | ||
DaffContainerModule, | ||
DaffLoadingIconModule, | ||
} from '@daffodil/design'; | ||
import { DaffProduct } from '@daffodil/product'; | ||
import { | ||
DaffProductFactory, | ||
DaffProductTestingModule, | ||
} from '@daffodil/product/testing'; | ||
|
||
import { CategoryViewComponent } from './category-view.component'; | ||
import { ProductGridComponent } from '../../../product/components/product-grid/product-grid.component'; | ||
import { ProductGridModule } from '../../../product/components/product-grid/product-grid.module'; | ||
|
||
|
||
describe('CategoryViewComponent', () => { | ||
let categoryFactory: DaffCategoryFactory; | ||
let productFactory: DaffProductFactory; | ||
let mockCategory: DaffCategory; | ||
let mockProducts: DaffProduct[]; | ||
let facade: MockDaffCategoryFacade; | ||
|
||
let component: CategoryViewComponent; | ||
let fixture: ComponentFixture<CategoryViewComponent>; | ||
let productGridComponent: ProductGridComponent; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
CategoryViewComponent, | ||
], | ||
imports: [ | ||
DaffContainerModule, | ||
DaffLoadingIconModule, | ||
ProductGridModule, | ||
DaffCategoryStateTestingModule, | ||
DaffProductTestingModule, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
facade = TestBed.inject(MockDaffCategoryFacade); | ||
categoryFactory = TestBed.inject(DaffCategoryFactory); | ||
productFactory = TestBed.inject(DaffProductFactory); | ||
|
||
mockCategory = categoryFactory.create(); | ||
mockProducts = productFactory.createMany(10); | ||
facade.category$.next(mockCategory); | ||
facade.products$.next(mockProducts); | ||
|
||
fixture = TestBed.createComponent(CategoryViewComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
|
||
productGridComponent = fixture.debugElement.query(By.css('demo-product-grid')).componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('on <demo-product-grid>', () => { | ||
it('should set products to value from the facade', () => { | ||
expect(productGridComponent.products).toEqual(mockProducts); | ||
}); | ||
}); | ||
|
||
describe('when loading$ becomes false', () => { | ||
|
||
beforeEach(() => { | ||
facade.loading$.next(false); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should render <demo-product-grid>', () => { | ||
const productGrid = fixture.debugElement.query(By.css('demo-product-grid')); | ||
|
||
expect(productGrid).not.toBeNull(); | ||
}); | ||
|
||
it('should not render daff-loading-icon', () => { | ||
const loadingIcon = fixture.debugElement.query(By.css('daff-loading-icon')); | ||
|
||
expect(loadingIcon).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('when loading$ becomes true', () => { | ||
|
||
beforeEach(() => { | ||
facade.loading$.next(true); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should not render <demo-product-grid>', () => { | ||
const productGrid = fixture.debugElement.query(By.css('demo-product-grid')); | ||
expect(productGrid).toBeNull(); | ||
}); | ||
|
||
it('should render daff-loading-icon', () => { | ||
const loadingIcon = fixture.debugElement.query(By.css('daff-loading-icon')); | ||
expect(loadingIcon).not.toBeNull(); | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
apps/demo/src/app/category/pages/category-view/category-view.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,29 @@ | ||
import { | ||
Component, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { DaffCategory } from '@daffodil/category'; | ||
import { DaffCategoryFacade } from '@daffodil/category/state'; | ||
import { DaffProduct } from '@daffodil/product'; | ||
|
||
@Component({ | ||
selector: 'demo-category-view', | ||
templateUrl: './category-view.component.html', | ||
}) | ||
export class CategoryViewComponent implements OnInit { | ||
category$: Observable<DaffCategory>; | ||
loading$: Observable<boolean>; | ||
products$: Observable<DaffProduct[]>; | ||
|
||
constructor( | ||
private facade: DaffCategoryFacade, | ||
) {} | ||
|
||
ngOnInit() { | ||
this.category$ = this.facade.category$; | ||
this.products$ = this.facade.products$; | ||
this.loading$ = this.facade.loading$; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
apps/demo/src/app/category/pages/category-view/category-view.module.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,30 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { DaffCategoryStateModule } from '@daffodil/category/state'; | ||
import { | ||
DaffContainerModule, | ||
DaffLoadingIconModule, | ||
} from '@daffodil/design'; | ||
import { DaffProductStateModule } from '@daffodil/product/state'; | ||
|
||
import { CategoryViewComponent } from './category-view.component'; | ||
import { ProductGridModule } from '../../../product/components/product-grid/product-grid.module'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
DaffLoadingIconModule, | ||
ProductGridModule, | ||
DaffContainerModule, | ||
DaffProductStateModule, | ||
DaffCategoryStateModule, | ||
], | ||
declarations: [ | ||
CategoryViewComponent, | ||
], | ||
exports: [ | ||
CategoryViewComponent, | ||
], | ||
}) | ||
export class CategoryViewModule { } |
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
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
Oops, something went wrong.