mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Add Unit Test for History State Reducer
This commit is contained in:
69
angular.json
69
angular.json
@@ -27,7 +27,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["libs/ui/tsconfig.lib.json", "libs/ui/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"libs/ui/tsconfig.lib.json",
|
||||
"libs/ui/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -141,14 +144,24 @@
|
||||
"tsConfig": "apps/sales/tsconfig.spec.json",
|
||||
"karmaConfig": "apps/sales/karma.conf.js",
|
||||
"styles": ["apps/sales/src/styles.scss"],
|
||||
"stylePreprocessorOptions": {
|
||||
"includePaths": ["apps/sales/src/scss"]
|
||||
},
|
||||
"scripts": [],
|
||||
"assets": ["apps/sales/src/favicon.ico", "apps/sales/src/assets", "apps/sales/src/manifest.webmanifest"]
|
||||
"assets": [
|
||||
"apps/sales/src/favicon.ico",
|
||||
"apps/sales/src/assets",
|
||||
"apps/sales/src/manifest.webmanifest"
|
||||
]
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/sales/tsconfig.app.json", "apps/sales/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/sales/tsconfig.app.json",
|
||||
"apps/sales/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -207,7 +220,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["libs/sso/tsconfig.lib.json", "libs/sso/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"libs/sso/tsconfig.lib.json",
|
||||
"libs/sso/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -237,7 +253,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/availability/tsconfig.lib.json", "apps/swagger/availability/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/availability/tsconfig.lib.json",
|
||||
"apps/swagger/availability/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -267,7 +286,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/checkout/tsconfig.lib.json", "apps/swagger/checkout/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/checkout/tsconfig.lib.json",
|
||||
"apps/swagger/checkout/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -297,7 +319,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/crm/tsconfig.lib.json", "apps/swagger/crm/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/crm/tsconfig.lib.json",
|
||||
"apps/swagger/crm/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -327,7 +352,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/isa/tsconfig.lib.json", "apps/swagger/isa/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/isa/tsconfig.lib.json",
|
||||
"apps/swagger/isa/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -357,7 +385,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/oms/tsconfig.lib.json", "apps/swagger/oms/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/oms/tsconfig.lib.json",
|
||||
"apps/swagger/oms/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -387,7 +418,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/print/tsconfig.lib.json", "apps/swagger/print/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/print/tsconfig.lib.json",
|
||||
"apps/swagger/print/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -417,7 +451,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/cat/tsconfig.lib.json", "apps/swagger/cat/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/cat/tsconfig.lib.json",
|
||||
"apps/swagger/cat/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -447,7 +484,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/swagger/eis/tsconfig.lib.json", "apps/swagger/eis/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/swagger/eis/tsconfig.lib.json",
|
||||
"apps/swagger/eis/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
@@ -477,7 +517,10 @@
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": ["apps/native-container/tsconfig.lib.json", "apps/native-container/tsconfig.spec.json"],
|
||||
"tsConfig": [
|
||||
"apps/native-container/tsconfig.lib.json",
|
||||
"apps/native-container/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": ["**/node_modules/**"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@ import { RootState } from './store/root.state';
|
||||
import { rootReducer } from './store/root.reducer';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
import { SearchEffects } from './store/customer';
|
||||
import { HistoryEffects } from '@shelf-store/history';
|
||||
|
||||
// TODO: In Service Speichern
|
||||
export function storeInLocalStorage(reducer: ActionReducer<any>): ActionReducer<any> {
|
||||
export function storeInLocalStorage(
|
||||
reducer: ActionReducer<any>
|
||||
): ActionReducer<any> {
|
||||
const lsKey = 'ISA_NGRX_STATE';
|
||||
|
||||
return function (state, action) {
|
||||
@@ -25,12 +28,14 @@ export function storeInLocalStorage(reducer: ActionReducer<any>): ActionReducer<
|
||||
};
|
||||
}
|
||||
|
||||
export const metaReducers: MetaReducer<RootState>[] = !environment.production ? [storeFreeze, storeInLocalStorage] : [storeInLocalStorage];
|
||||
export const metaReducers: MetaReducer<RootState>[] = !environment.production
|
||||
? [storeFreeze, storeInLocalStorage]
|
||||
: [storeInLocalStorage];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forRoot(rootReducer, { metaReducers }),
|
||||
EffectsModule.forRoot([SearchEffects]),
|
||||
EffectsModule.forRoot([SearchEffects, HistoryEffects]),
|
||||
StoreDevtoolsModule.instrument({ name: 'ISA Ngrx Store' }),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
VATDTO,
|
||||
SupplierDTO,
|
||||
QueryTokenDTO,
|
||||
AutocompleteTokenDTO,
|
||||
} from '@swagger/oms';
|
||||
import { map, filter } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -120,6 +121,10 @@ export class CollectingShelfService {
|
||||
);
|
||||
}
|
||||
|
||||
searchWarenausgabeAutocomplete(autocompleteTokenDTO: AutocompleteTokenDTO) {
|
||||
return this.omsService.OrderWarenausgabeAutocomplete(autocompleteTokenDTO);
|
||||
}
|
||||
|
||||
getOrderByOrderId(orderId: number): Observable<OrderDTO> {
|
||||
return this.omsService.OrderGetOrder(orderId).pipe(
|
||||
map((response) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { RemissionListFilterComponent } from './remission-list-filter.component';
|
||||
|
||||
fdescribe('RemissionListFilterComponent', () => {
|
||||
describe('RemissionListFilterComponent', () => {
|
||||
let fixture: ComponentFixture<RemissionListFilterComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
<div class="isa-card">
|
||||
<h3 class="heading">{{ group.fullName }}</h3>
|
||||
<ng-container *ngFor="let customer of group.items; let last = last">
|
||||
<div class="isa-mb-12 isa-mt-12">
|
||||
<div class="isa-text-right isa-mb-9">
|
||||
<strong>{{ customer.orderNumber }}</strong>
|
||||
</div>
|
||||
<app-search-result-group-item *ngFor="let item of customer.items; let lastItem = last" [item]="item"
|
||||
[class.group-item-bottom-space]="!lastItem">
|
||||
</app-search-result-group-item>
|
||||
</div>
|
||||
<div class="divider" *ngIf="!last"></div>
|
||||
</ng-container>
|
||||
</div>
|
||||
<h3 class="heading">{{ group.fullName }}</h3>
|
||||
<ng-container *ngFor="let customer of group.items; let last = last">
|
||||
<div class="isa-mb-12 isa-mt-12">
|
||||
<div class="isa-text-right isa-mb-9">
|
||||
<strong>{{ customer.orderNumber }}</strong>
|
||||
</div>
|
||||
<app-search-result-group-item
|
||||
(click)="navigateToDetails(item)"
|
||||
*ngFor="let item of customer.items; let lastItem = last"
|
||||
[item]="item"
|
||||
[class.group-item-bottom-space]="!lastItem"
|
||||
>
|
||||
</app-search-result-group-item>
|
||||
</div>
|
||||
<div class="divider" *ngIf="!last"></div>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { Component, OnInit, ChangeDetectionStrategy, Input } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
OnInit,
|
||||
ChangeDetectionStrategy,
|
||||
Input,
|
||||
} from '@angular/core';
|
||||
import { GroupedByCustomer } from 'apps/sales/src/app/store/customer';
|
||||
import { OrderItemListItemDTO } from '@swagger/oms';
|
||||
import { ShelfNavigationService } from '../../shared/services';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search-result-group',
|
||||
@@ -12,7 +18,11 @@ export class SearchResultGroupComponent implements OnInit {
|
||||
@Input()
|
||||
group: GroupedByCustomer;
|
||||
|
||||
constructor() {}
|
||||
constructor(private navigationFacade: ShelfNavigationService) {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
navigateToDetails(orderItem: OrderItemListItemDTO) {
|
||||
this.navigationFacade.navigateToDetails(orderItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
<div>Order Item Id: {{ orderItemId$ | async }}</div>
|
||||
<pre>{{ history$ | async | json }}</pre>
|
||||
<pre>{{ status$ | async | json }}</pre>
|
||||
|
||||
@@ -14,7 +14,6 @@ import { OrderHistoryStatus } from '@shelf-store/defs';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class ShelfHistoryComponent implements OnInit {
|
||||
orderItemId$: Observable<number>;
|
||||
history$: Observable<HistoryDTO>;
|
||||
status$: Observable<OrderHistoryStatus>;
|
||||
|
||||
@@ -29,8 +28,7 @@ export class ShelfHistoryComponent implements OnInit {
|
||||
}
|
||||
|
||||
getHistory() {
|
||||
this.orderItemId$ = this.getOrderItemId();
|
||||
return this.orderItemId$.pipe(
|
||||
return this.getOrderItemId$().pipe(
|
||||
switchMap((orderItemId) =>
|
||||
this.historyStateFacade.getHistory$(orderItemId)
|
||||
)
|
||||
@@ -38,14 +36,14 @@ export class ShelfHistoryComponent implements OnInit {
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
return this.orderItemId$.pipe(
|
||||
return this.getOrderItemId$().pipe(
|
||||
switchMap((orderItemId) =>
|
||||
this.historyStateFacade.getStatus$(orderItemId)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private getOrderItemId(): Observable<number> {
|
||||
private getOrderItemId$(): Observable<number> {
|
||||
return this.activatedRoute.params.pipe(
|
||||
filter((params) => !isNullOrUndefined(params)),
|
||||
map((params) => Number(params.orderItemId))
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
<div class="result-container" #scroll>
|
||||
<app-search-result-group class="isa-mb-10" *ngFor="let group of grouped$ | async; let i = index" [group]="group">
|
||||
<app-search-result-group
|
||||
class="isa-mb-10"
|
||||
*ngFor="let group of grouped$ | async; let i = index"
|
||||
[group]="group"
|
||||
>
|
||||
</app-search-result-group>
|
||||
<app-loading *ngIf="fetching$ | async" [style.marginTop.px]="60" [style.marginBottom.px]="60" loading="true"
|
||||
text="Inhalte werden geladen"></app-loading>
|
||||
</div>
|
||||
<app-loading
|
||||
*ngIf="fetching$ | async"
|
||||
[style.marginTop.px]="60"
|
||||
[style.marginBottom.px]="60"
|
||||
loading="true"
|
||||
text="Inhalte werden geladen"
|
||||
></app-loading>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { Subject, fromEvent, combineLatest } from 'rxjs';
|
||||
|
||||
import { Component, OnDestroy, OnInit, ChangeDetectorRef, ViewChild, ElementRef } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
ViewChild,
|
||||
ElementRef,
|
||||
} from '@angular/core';
|
||||
import { SearchStateFacade } from 'apps/sales/src/app/store/customer';
|
||||
import { first, takeUntil } from 'rxjs/operators';
|
||||
|
||||
@@ -42,11 +48,20 @@ export class ShelfSearchResultsComponent implements OnInit, OnDestroy {
|
||||
|
||||
reachedBottom() {
|
||||
const scrollContainer: HTMLElement = this.scrollContainer.nativeElement;
|
||||
return scrollContainer.scrollHeight - (scrollContainer.scrollTop + scrollContainer.clientHeight) - 100 <= 0;
|
||||
return (
|
||||
scrollContainer.scrollHeight -
|
||||
(scrollContainer.scrollTop + scrollContainer.clientHeight) -
|
||||
100 <=
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
async fetch(force = false) {
|
||||
const [hits, result, fetching] = await combineLatest([this.searchStateFacade.hits$, this.searchStateFacade.result$, this.fetching$])
|
||||
const [hits, result, fetching] = await combineLatest([
|
||||
this.searchStateFacade.hits$,
|
||||
this.searchStateFacade.result$,
|
||||
this.fetching$,
|
||||
])
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ export class ShelfSearchInputComponent
|
||||
switchMap((queryString: string) => {
|
||||
if (this.isValidQuery(queryString)) {
|
||||
return this.shelfSearchService
|
||||
.search(queryString)
|
||||
.searchForAutocomplete(queryString)
|
||||
.pipe(map((result) => result.result && result.result.slice(0, 5)));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ import { Process } from 'apps/sales/src/app/core/models/process.model';
|
||||
export class ShelfNavigationService {
|
||||
constructor(private store: Store, private router: Router) {}
|
||||
|
||||
// TODO Add Navigation Logic for History Page
|
||||
|
||||
navigateToDetails(order: OrderItemListItemDTO) {
|
||||
this.createTab();
|
||||
const path = this.getDetailsPath(order);
|
||||
@@ -38,6 +36,10 @@ export class ShelfNavigationService {
|
||||
this.navigateToRoute(path, breadcrumb);
|
||||
}
|
||||
|
||||
navigateToHistory() {
|
||||
// TODO Add Navigation Logic for History Page
|
||||
}
|
||||
|
||||
private navigateToRoute(route: string, breadcrumbName: string) {
|
||||
this.store.dispatch(
|
||||
new AddBreadcrumb(
|
||||
|
||||
@@ -5,7 +5,11 @@ import { Observable } from 'rxjs';
|
||||
import { filter, switchMap, map } from 'rxjs/operators';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { CollectingShelfService } from 'apps/sales/src/app/core/services/collecting-shelf.service';
|
||||
import { ListResponseArgsOfOrderItemListItemDTO } from '@swagger/oms/lib';
|
||||
import {
|
||||
ListResponseArgsOfOrderItemListItemDTO,
|
||||
AutocompleteTokenDTO,
|
||||
ResponseArgsOfIEnumerableOfAutocompleteDTO,
|
||||
} from '@swagger/oms/lib';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ShelfSearchFacadeService {
|
||||
@@ -35,6 +39,19 @@ export class ShelfSearchFacadeService {
|
||||
return this.requestSearch(searchParams).pipe(map(this.handleSearchResult));
|
||||
}
|
||||
|
||||
searchForAutocomplete(queryString: string) {
|
||||
const searchParams = queryString.trim();
|
||||
const autoCompleteQuery: AutocompleteTokenDTO = this.generateAutocompleteToken(
|
||||
{ queryString, filter: {}, take: 5 }
|
||||
);
|
||||
|
||||
if (!this.isValidSearchQuery(searchParams)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.requestAutocompleteSearch(autoCompleteQuery);
|
||||
}
|
||||
|
||||
private requestSearch(
|
||||
input: string
|
||||
): Observable<ListResponseArgsOfOrderItemListItemDTO> {
|
||||
@@ -46,6 +63,32 @@ export class ShelfSearchFacadeService {
|
||||
);
|
||||
}
|
||||
|
||||
private generateAutocompleteToken(params: {
|
||||
queryString: string;
|
||||
take?: number;
|
||||
filter?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
}): AutocompleteTokenDTO {
|
||||
return {
|
||||
input: params.queryString,
|
||||
take: params.take || 5,
|
||||
filter: params.filter || {},
|
||||
};
|
||||
}
|
||||
|
||||
private requestAutocompleteSearch(
|
||||
autocompleteToken: AutocompleteTokenDTO
|
||||
): Observable<ResponseArgsOfIEnumerableOfAutocompleteDTO> {
|
||||
return this.currentUserBranchId$.pipe(
|
||||
switchMap(() =>
|
||||
this.collectingShelfService.searchWarenausgabeAutocomplete(
|
||||
autocompleteToken
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private handleSearchResult(result: ListResponseArgsOfOrderItemListItemDTO) {
|
||||
if (!result) {
|
||||
return {
|
||||
|
||||
@@ -7,7 +7,7 @@ describe('CalendarComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CalendarModule]
|
||||
imports: [CalendarModule],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CalendarComponent);
|
||||
@@ -232,18 +232,21 @@ describe('CalendarComponent', () => {
|
||||
{
|
||||
color: 'red',
|
||||
date: new Date(2019, 5, 4),
|
||||
title: 'test 1'
|
||||
title: 'test 1',
|
||||
id: 1,
|
||||
},
|
||||
{
|
||||
color: 'red',
|
||||
date: new Date(2019, 5, 23),
|
||||
title: 'test 4'
|
||||
title: 'test 4',
|
||||
id: 2,
|
||||
},
|
||||
{
|
||||
color: 'white',
|
||||
date: new Date(2019, 5, 23),
|
||||
title: 'test 5'
|
||||
}
|
||||
title: 'test 5',
|
||||
id: 3,
|
||||
},
|
||||
];
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -281,18 +284,21 @@ describe('CalendarComponent', () => {
|
||||
{
|
||||
color: 'red',
|
||||
date: new Date(2019, 5, 4),
|
||||
title: 'test 1'
|
||||
title: 'test 1',
|
||||
id: 1,
|
||||
},
|
||||
{
|
||||
color: 'red',
|
||||
date: new Date(2019, 5, 6),
|
||||
title: 'test 4'
|
||||
title: 'test 4',
|
||||
id: 2,
|
||||
},
|
||||
{
|
||||
color: 'white',
|
||||
date: new Date(2019, 5, 6),
|
||||
title: 'test 5'
|
||||
}
|
||||
title: 'test 5',
|
||||
id: 3,
|
||||
},
|
||||
];
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -2,5 +2,5 @@ import { HistoryDTO } from '@cmf/trade-api';
|
||||
import { OrderHistoryStatus } from './order-history-status';
|
||||
|
||||
export interface OrderHistory extends HistoryDTO {
|
||||
status?: OrderHistoryStatus;
|
||||
status: OrderHistoryStatus;
|
||||
}
|
||||
|
||||
@@ -1,39 +1,38 @@
|
||||
import { OrderHistory, OrderHistoryStatus } from '../defs';
|
||||
import { props, createAction } from '@ngrx/store';
|
||||
import { StrictHttpResponse, ResponseArgs } from '@swagger/oms';
|
||||
import { HistoryDTO } from '@cmf/trade-api';
|
||||
import { StrictHttpResponse, ResponseArgsOfHistoryDTO } from '@swagger/oms';
|
||||
|
||||
const prefix = '[CUSTOMER] [SHELF] [HISTORY]';
|
||||
|
||||
export const initOrderHistory = createAction(
|
||||
`${prefix} Init Order History`,
|
||||
props<{ orderItemId: number }>()
|
||||
props<{ id: number }>()
|
||||
);
|
||||
|
||||
export const addOrderHistory = createAction(
|
||||
`${prefix} Add Order History`,
|
||||
props<{ orderItemId: number; history: OrderHistory }>()
|
||||
props<{ id: number; history: OrderHistory }>()
|
||||
);
|
||||
|
||||
export const setStatus = createAction(
|
||||
`${prefix} Add Order History`,
|
||||
props<{ orderItemId: number; status: OrderHistoryStatus }>()
|
||||
`${prefix} Set Order Status`,
|
||||
props<{ id: number; status: OrderHistoryStatus }>()
|
||||
);
|
||||
|
||||
export const fetchHistory = createAction(
|
||||
`${prefix} Fetch Order History`,
|
||||
props<{ orderItemId: number }>()
|
||||
props<{ id: number }>()
|
||||
);
|
||||
|
||||
export const fetchHistoryDone = createAction(
|
||||
`${prefix} Fetch Order History Done`,
|
||||
props<{
|
||||
orderItemId: number;
|
||||
response: StrictHttpResponse<ResponseArgs & { result: HistoryDTO }>;
|
||||
id: number;
|
||||
response: StrictHttpResponse<ResponseArgsOfHistoryDTO>;
|
||||
}>()
|
||||
);
|
||||
|
||||
export const updateOrderHistory = createAction(
|
||||
`${prefix} Update Order History`,
|
||||
props<{ orderItemId: number; history: Partial<OrderHistory> }>()
|
||||
props<{ id: number; history: Partial<OrderHistory> }>()
|
||||
);
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
||||
import * as actions from './history.actions';
|
||||
import { switchMap, map, catchError, flatMap } from 'rxjs/operators';
|
||||
import { OrderService, StrictHttpResponse, ResponseArgs } from '@swagger/oms';
|
||||
import {
|
||||
OrderService,
|
||||
StrictHttpResponse,
|
||||
ResponseArgs,
|
||||
ResponseArgsOfHistoryDTO,
|
||||
} from '@swagger/oms';
|
||||
import { HistoryDTO } from '@cmf/trade-api';
|
||||
import { of, NEVER } from 'rxjs';
|
||||
import { OrderHistoryStatus } from '../defs';
|
||||
@@ -12,26 +16,28 @@ import { OrderHistoryStatus } from '../defs';
|
||||
export class HistoryEffects {
|
||||
constructor(private actions$: Actions, private orderService: OrderService) {}
|
||||
|
||||
initHistory$ = createEffect(() =>
|
||||
this.actions$.pipe(
|
||||
ofType(actions.initOrderHistory),
|
||||
map((action) => actions.fetchHistory({ id: action.id }))
|
||||
)
|
||||
);
|
||||
|
||||
fetchHistory$ = createEffect(() =>
|
||||
this.actions$.pipe(
|
||||
ofType(actions.fetchHistory),
|
||||
switchMap((action) =>
|
||||
this.orderService
|
||||
.OrderGetOrderItemHistoryResponse({ orderItemId: action.orderItemId })
|
||||
.OrderGetOrderItemHistoryResponse({ orderItemId: action.id })
|
||||
.pipe(
|
||||
catchError((err) =>
|
||||
of<StrictHttpResponse<ResponseArgs & { result: HistoryDTO }>>(err)
|
||||
of<StrictHttpResponse<ResponseArgsOfHistoryDTO>>(err)
|
||||
),
|
||||
map(
|
||||
(
|
||||
response: StrictHttpResponse<
|
||||
ResponseArgs & { result: HistoryDTO }
|
||||
>
|
||||
) =>
|
||||
actions.fetchHistoryDone({
|
||||
orderItemId: action.orderItemId,
|
||||
response,
|
||||
})
|
||||
map((response: StrictHttpResponse<ResponseArgsOfHistoryDTO>) =>
|
||||
actions.fetchHistoryDone({
|
||||
id: action.id,
|
||||
response,
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -43,12 +49,17 @@ export class HistoryEffects {
|
||||
ofType(actions.fetchHistoryDone),
|
||||
flatMap((action) => {
|
||||
if (action.response.ok) {
|
||||
const history = action.response.body.result;
|
||||
actions.addOrderHistory({ orderItemId: action.orderItemId, history });
|
||||
const history = action.response.body.result[0];
|
||||
return [
|
||||
actions.addOrderHistory({
|
||||
id: action.id,
|
||||
history,
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
actions.setStatus({
|
||||
orderItemId: action.orderItemId,
|
||||
id: action.id,
|
||||
status: OrderHistoryStatus.ERROR,
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import { Store } from '@ngrx/store';
|
||||
import { Dictionary } from '@ngrx/entity';
|
||||
import { Observable } from 'rxjs';
|
||||
import * as selectors from './history.selectors';
|
||||
import * as actions from './history.actions';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class HistoryStateFacade {
|
||||
@@ -13,15 +16,17 @@ export class HistoryStateFacade {
|
||||
|
||||
constructor(private store: Store<any>) {}
|
||||
|
||||
private getHistories$(): Observable<Dictionary<OrderHistory>> {
|
||||
return this.store.select(selectors.selectHistories);
|
||||
}
|
||||
|
||||
public getHistory$(orderItemId: number): Observable<OrderHistory> {
|
||||
this.store.dispatch(actions.initOrderHistory({ id: orderItemId }));
|
||||
|
||||
return this.store.select(selectors.selectHistory, orderItemId);
|
||||
}
|
||||
|
||||
public getStatus$(orderItemId: number): Observable<OrderHistoryStatus> {
|
||||
return this.store.select(selectors.selectStatus, orderItemId);
|
||||
}
|
||||
|
||||
private getHistories$(): Observable<Dictionary<OrderHistory>> {
|
||||
return this.store.select(selectors.selectHistories);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
INITIAL_HISTORY_STATE,
|
||||
INITIAL_ORDER_HISTORY,
|
||||
HistoryState,
|
||||
} from './history.state';
|
||||
import { historyReducer } from './history.reducer';
|
||||
import * as actions from './history.actions';
|
||||
import { OrderHistory } from '@shelf-store/defs';
|
||||
|
||||
fdescribe('#HistoryStateReducer', () => {
|
||||
const id = 123;
|
||||
const mockOrderHistory: OrderHistory = {
|
||||
...INITIAL_ORDER_HISTORY,
|
||||
name: 'Fake History',
|
||||
id,
|
||||
values: [],
|
||||
};
|
||||
|
||||
it('should return the initial state if on Init Order action is dispatched', () => {
|
||||
const initialState = INITIAL_HISTORY_STATE;
|
||||
const action = actions.initOrderHistory({ id });
|
||||
|
||||
const state = historyReducer(initialState, action);
|
||||
const entity = state.entities[id];
|
||||
|
||||
expect(entity).toEqual({
|
||||
...initialState.entities[id],
|
||||
...INITIAL_ORDER_HISTORY,
|
||||
id,
|
||||
});
|
||||
});
|
||||
|
||||
it('should add history and set status to available (2)', () => {
|
||||
let state: HistoryState;
|
||||
const initialState = INITIAL_HISTORY_STATE;
|
||||
|
||||
const initAction = actions.initOrderHistory({ id });
|
||||
state = historyReducer(initialState, initAction);
|
||||
|
||||
const action = actions.addOrderHistory({ id, history: mockOrderHistory });
|
||||
state = historyReducer(state, action);
|
||||
|
||||
const entity = state.entities[id];
|
||||
|
||||
expect(entity.status).toBe(2);
|
||||
expect(entity).toEqual({ ...mockOrderHistory, status: 2 });
|
||||
});
|
||||
});
|
||||
@@ -12,24 +12,39 @@ export const _historyReducer = createReducer(
|
||||
INITIAL_HISTORY_STATE,
|
||||
on(actions.initOrderHistory, (s, a) =>
|
||||
historyStateAdapter.addOne(
|
||||
{ id: a.orderItemId, ...INITIAL_ORDER_HISTORY },
|
||||
{
|
||||
...INITIAL_ORDER_HISTORY,
|
||||
id: a.id,
|
||||
},
|
||||
s
|
||||
)
|
||||
),
|
||||
on(actions.updateOrderHistory, (s, a) =>
|
||||
historyStateAdapter.updateOne(
|
||||
{
|
||||
id: a.orderItemId,
|
||||
changes: { ...a.history, status: OrderHistoryStatus.AVAILABLE },
|
||||
id: a.id,
|
||||
changes: {
|
||||
...a.history,
|
||||
status: OrderHistoryStatus.AVAILABLE,
|
||||
},
|
||||
},
|
||||
s
|
||||
)
|
||||
),
|
||||
on(actions.addOrderHistory, (s, a) =>
|
||||
on(actions.addOrderHistory, (s, a) => {
|
||||
return historyStateAdapter.updateOne(
|
||||
{
|
||||
id: a.id,
|
||||
changes: { ...a.history, status: OrderHistoryStatus.AVAILABLE },
|
||||
},
|
||||
s
|
||||
);
|
||||
}),
|
||||
on(actions.setStatus, (s, a) =>
|
||||
historyStateAdapter.updateOne(
|
||||
{
|
||||
id: a.orderItemId,
|
||||
changes: { ...a.history, status: OrderHistoryStatus.AVAILABLE },
|
||||
id: a.id,
|
||||
changes: { status: a.status },
|
||||
},
|
||||
s
|
||||
)
|
||||
|
||||
@@ -25,5 +25,6 @@ export const selectHistory = createSelector(
|
||||
|
||||
export const selectStatus = createSelector(
|
||||
selectEntities,
|
||||
(entities: Dictionary<OrderHistory>, id: number) => entities[id].status
|
||||
(entities: Dictionary<OrderHistory>, id: number) =>
|
||||
entities[id] && entities[id].status
|
||||
);
|
||||
|
||||
@@ -9,6 +9,6 @@ export const INITIAL_HISTORY_STATE: HistoryState = {
|
||||
...historyStateAdapter.getInitialState(),
|
||||
};
|
||||
|
||||
export const INITIAL_ORDER_HISTORY = {
|
||||
export const INITIAL_ORDER_HISTORY: OrderHistory = {
|
||||
status: OrderHistoryStatus.INIT,
|
||||
};
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
import { createReducer, Action, on } from '@ngrx/store';
|
||||
import { INITIAL_SEARCH_STATE, SearchState, searchStateAdapter, INITIAL_SEARCH_PROCESS } from './search.state';
|
||||
import {
|
||||
INITIAL_SEARCH_STATE,
|
||||
SearchState,
|
||||
searchStateAdapter,
|
||||
INITIAL_SEARCH_PROCESS,
|
||||
} from './search.state';
|
||||
import * as actions from './search.actions';
|
||||
|
||||
const _searchReducer = createReducer(
|
||||
INITIAL_SEARCH_STATE,
|
||||
on(actions.addSearchProcess, (s, a) => searchStateAdapter.addOne({ ...INITIAL_SEARCH_PROCESS, id: a.id }, s)),
|
||||
on(actions.removeSearchProcess, (s, a) => searchStateAdapter.removeOne(a.id, s)),
|
||||
on(actions.setInput, (s, a) => searchStateAdapter.updateOne({ id: a.id, changes: { input: a.input } }, s)),
|
||||
on(actions.addSearchProcess, (s, a) =>
|
||||
searchStateAdapter.addOne({ ...INITIAL_SEARCH_PROCESS, id: a.id }, s)
|
||||
),
|
||||
on(actions.removeSearchProcess, (s, a) =>
|
||||
searchStateAdapter.removeOne(a.id, s)
|
||||
),
|
||||
on(actions.setInput, (s, a) =>
|
||||
searchStateAdapter.updateOne({ id: a.id, changes: { input: a.input } }, s)
|
||||
),
|
||||
on(actions.setSelectedFilters, (s, a) =>
|
||||
searchStateAdapter.updateOne(
|
||||
{
|
||||
@@ -32,7 +43,9 @@ const _searchReducer = createReducer(
|
||||
s
|
||||
)
|
||||
),
|
||||
on(actions.clearResults, (s, a) => searchStateAdapter.updateOne({ id: a.id, changes: { result: [] } }, s)),
|
||||
on(actions.clearResults, (s, a) =>
|
||||
searchStateAdapter.updateOne({ id: a.id, changes: { result: [] } }, s)
|
||||
),
|
||||
on(actions.addResult, (s, a) =>
|
||||
searchStateAdapter.updateOne(
|
||||
{
|
||||
@@ -42,10 +55,18 @@ const _searchReducer = createReducer(
|
||||
s
|
||||
)
|
||||
),
|
||||
on(actions.clearHits, (s, a) => searchStateAdapter.updateOne({ id: a.id, changes: { hits: undefined } }, s)),
|
||||
on(actions.setHits, (s, a) => searchStateAdapter.updateOne({ id: a.id, changes: { hits: a.hits } }, s)),
|
||||
on(actions.fetchResult, (s, a) => searchStateAdapter.updateOne({ id: a.id, changes: { fetching: true } }, s)),
|
||||
on(actions.fetchResultDone, (s, a) => searchStateAdapter.updateOne({ id: a.id, changes: { fetching: false } }, s))
|
||||
on(actions.clearHits, (s, a) =>
|
||||
searchStateAdapter.updateOne({ id: a.id, changes: { hits: undefined } }, s)
|
||||
),
|
||||
on(actions.setHits, (s, a) =>
|
||||
searchStateAdapter.updateOne({ id: a.id, changes: { hits: a.hits } }, s)
|
||||
),
|
||||
on(actions.fetchResult, (s, a) =>
|
||||
searchStateAdapter.updateOne({ id: a.id, changes: { fetching: true } }, s)
|
||||
),
|
||||
on(actions.fetchResultDone, (s, a) =>
|
||||
searchStateAdapter.updateOne({ id: a.id, changes: { fetching: false } }, s)
|
||||
)
|
||||
);
|
||||
|
||||
export function searchReducer(state: SearchState, action: Action) {
|
||||
|
||||
@@ -4,8 +4,8 @@ import { searchReducer } from './search';
|
||||
import { historyReducer } from './history';
|
||||
|
||||
const _shelfReducer = combineReducers<ShelfState>({
|
||||
search: searchReducer,
|
||||
history: historyReducer,
|
||||
search: searchReducer,
|
||||
});
|
||||
|
||||
export function shelfReducer(state: ShelfState, action: Action) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
@import 'variables';
|
||||
|
||||
.isa-form-group {
|
||||
font-family: $font-family;
|
||||
font-weight: $font-weight;
|
||||
|
||||
Reference in New Issue
Block a user