Compare commits
10 Commits
77d2433d63
...
2161951cbb
Author | SHA1 | Date | |
---|---|---|---|
|
2161951cbb | ||
66e492d2f8 | |||
e944064053 | |||
a1a4fc14ab | |||
122563a0bd | |||
33f322424e | |||
519b81d1fd | |||
b7c80dfdd8 | |||
d89670f669 | |||
d025e2e3f6 |
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { AppMenuComponent } from './app-menu.component';
|
|
||||||
|
|
||||||
describe('AppMenuComponent', () => {
|
|
||||||
let component: AppMenuComponent;
|
|
||||||
let fixture: ComponentFixture<AppMenuComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ AppMenuComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(AppMenuComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { AvatarComponent } from './avatar.component';
|
|
||||||
|
|
||||||
describe('AvatarComponent', () => {
|
|
||||||
let component: AvatarComponent;
|
|
||||||
let fixture: ComponentFixture<AvatarComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ AvatarComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(AvatarComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { EditImageModalComponent } from './edit-image-modal.component';
|
|
||||||
|
|
||||||
describe('EditImageModalComponent', () => {
|
|
||||||
let component: EditImageModalComponent;
|
|
||||||
let fixture: ComponentFixture<EditImageModalComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ EditImageModalComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(EditImageModalComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { GradientSelectComponent } from './gradient-select.component';
|
|
||||||
|
|
||||||
describe('GradientSelectComponent', () => {
|
|
||||||
let component: GradientSelectComponent;
|
|
||||||
let fixture: ComponentFixture<GradientSelectComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ GradientSelectComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(GradientSelectComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { GradientComponent } from './gradient.component';
|
|
||||||
|
|
||||||
describe('GradientComponent', () => {
|
|
||||||
let component: GradientComponent;
|
|
||||||
let fixture: ComponentFixture<GradientComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ GradientComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(GradientComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,61 +1,61 @@
|
|||||||
import { Directive, ViewContainerRef,TemplateRef,OnInit,Input,OnDestroy } from '@angular/core';
|
import {AfterViewInit, Directive, Input, OnDestroy, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||||
import { Store} from '@ngrx/store';
|
import {Subscription} from 'rxjs';
|
||||||
import * as appCommonReducer from '../../reducers/app-common.reducer'
|
import {PackageService} from '../../services/package.service';
|
||||||
import { IPackages } from '../../models/package';
|
import * as appCommonReducer from '../../reducers/app-common.reducer';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import {Store} from '@ngrx/store';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[fmHasPackage]',
|
selector: '[fmHasPackage]',
|
||||||
})
|
})
|
||||||
export class HasPackageDirective implements OnDestroy{
|
export class HasPackageDirective implements OnDestroy, AfterViewInit {
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set fmHasPackage(packageIdentifier:string) {
|
set fmHasPackage(packageIdentifier: string) {
|
||||||
this.packageIdentifier$ = packageIdentifier;
|
this.packageIdentifier = packageIdentifier;
|
||||||
this.updateView();
|
this.updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set fmHasPackageThen(thenTemplate:TemplateRef<any>) {
|
set fmHasPackageThen(thenTemplate: TemplateRef<any>) {
|
||||||
this.thenTemplate$ = thenTemplate;
|
this.thenTemplate = thenTemplate;
|
||||||
this.updateView();
|
this.updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set fmHasPackageElse(thenTemplate:TemplateRef<any>) {
|
set fmHasPackageElse(thenTemplate: TemplateRef<any>) {
|
||||||
this.elseTemplate$ = thenTemplate;
|
this.elseTemplate = thenTemplate;
|
||||||
this.updateView();
|
this.updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private packageIdentifier$:string;
|
private packageIdentifier: string;
|
||||||
private thenTemplate$:TemplateRef<any>;
|
private thenTemplate: TemplateRef<any>;
|
||||||
private elseTemplate$:TemplateRef<any>;
|
private elseTemplate: TemplateRef<any>;
|
||||||
private packages$:any = {};
|
private packSub: Subscription;
|
||||||
private packagesObservable$:Observable<IPackages> = this.store$.select(appCommonReducer.SelectGetUserPackages);
|
|
||||||
private packSub:Subscription;
|
|
||||||
|
|
||||||
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) {
|
constructor(private hostTemplateRef: TemplateRef<any>, private viewContainerRef: ViewContainerRef,
|
||||||
this.thenTemplate$=templateRef$;
|
private store: Store<appCommonReducer.State>, private packageService: PackageService) {
|
||||||
this.packSub = this.store$.select(appCommonReducer.SelectGetUserPackages).subscribe((packages) => {
|
this.thenTemplate = hostTemplateRef;
|
||||||
this.packages$ = packages;
|
this.packSub = this.store.select(appCommonReducer.SelectGetValidUserPackages).subscribe((_) => {
|
||||||
this.updateView();
|
this.updateView();
|
||||||
});
|
});
|
||||||
this.updateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit() {
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
|
||||||
updateView() {
|
updateView() {
|
||||||
this.viewContainerRef$.clear();
|
this.viewContainerRef.clear();
|
||||||
const today = new Date(new Date(Date.now()).toUTCString()).setHours(0, 0, 0, 0);
|
if (this.packageService.hasPackage(this.packageIdentifier)) {
|
||||||
if (this.packages$[this.packageIdentifier$] &&
|
this.viewContainerRef.createEmbeddedView(this.thenTemplate);
|
||||||
(this.packages$[this.packageIdentifier$].dataDate && new Date(this.packages$[this.packageIdentifier$].dataDate).setHours(0, 0, 0, 0) <= today) &&
|
} else if (this.elseTemplate) {
|
||||||
(this.packages$[this.packageIdentifier$].dataEndDate == null || new Date(this.packages$[this.packageIdentifier$].dataEndDate).setHours(0, 0, 0, 0) >= today)) {
|
this.viewContainerRef.createEmbeddedView(this.elseTemplate);
|
||||||
this.viewContainerRef$.createEmbeddedView(this.thenTemplate$);
|
|
||||||
} else if (this.elseTemplate$) {
|
|
||||||
this.viewContainerRef$.createEmbeddedView(this.elseTemplate$);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
if(this.packSub) this.packSub.unsubscribe();
|
if (this.packSub) {
|
||||||
|
this.packSub.unsubscribe();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { HelpMenuComponent } from './help-menu.component';
|
|
||||||
|
|
||||||
describe('HelpMenuComponent', () => {
|
|
||||||
let component: HelpMenuComponent;
|
|
||||||
let fixture: ComponentFixture<HelpMenuComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ HelpMenuComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(HelpMenuComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { NotificationMenuComponent } from './notification-menu.component';
|
|
||||||
|
|
||||||
describe('NotificationMenuComponent', () => {
|
|
||||||
let component: NotificationMenuComponent;
|
|
||||||
let fixture: ComponentFixture<NotificationMenuComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ NotificationMenuComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(NotificationMenuComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { UserMenuComponent } from './user-menu.component';
|
|
||||||
|
|
||||||
describe('UserMenuComponent', () => {
|
|
||||||
let component: UserMenuComponent;
|
|
||||||
let fixture: ComponentFixture<UserMenuComponent>;
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
declarations: [ UserMenuComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(UserMenuComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -7,5 +7,5 @@ export interface IPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IPackages {
|
export interface IPackages {
|
||||||
[id: string]: IPackage;
|
[id: string]: IPackage[];
|
||||||
}
|
}
|
122
projects/common/src/fm/services/package.service.spec.ts
Normal file
122
projects/common/src/fm/services/package.service.spec.ts
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
import {getValidPackages, isValidPackage, PackageService} from './package.service';
|
||||||
|
import {MockStore, provideMockStore} from '@ngrx/store/testing';
|
||||||
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
import * as appCommonReducer from '../reducers/app-common.reducer';
|
||||||
|
import {reducer, State} from '../reducers/app-common.reducer';
|
||||||
|
import * as appCommonActions from '../actions/app-common.actions';
|
||||||
|
import {IItem} from '../models/item';
|
||||||
|
import {IPackage} from '../models/package';
|
||||||
|
|
||||||
|
describe('PackageService', () => {
|
||||||
|
const initialState = {userPackages: {}} as State;
|
||||||
|
let serviceUnderTest: PackageService;
|
||||||
|
let items;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
provideMockStore({
|
||||||
|
initialState,
|
||||||
|
selectors: [
|
||||||
|
{
|
||||||
|
selector: appCommonReducer.SelectGetValidUserPackages,
|
||||||
|
value: {
|
||||||
|
'vnd.farmmaps.package.zoning': {
|
||||||
|
id: 'vnd.farmmaps.package.zoning',
|
||||||
|
name: 'zoning package',
|
||||||
|
dataDate: '2022-01-25T00:00:00.000000Z'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const store = TestBed.inject(MockStore);
|
||||||
|
serviceUnderTest = new PackageService(store, null, null);
|
||||||
|
|
||||||
|
items = [
|
||||||
|
{
|
||||||
|
code: '123132',
|
||||||
|
dataDate: '2021-01-25T00:00:00Z',
|
||||||
|
dataEndDate: '2021-05-25T00:00:00Z',
|
||||||
|
data: {
|
||||||
|
id: 'vnd.farmmaps.package.zoning'
|
||||||
|
}
|
||||||
|
} as IItem,
|
||||||
|
{
|
||||||
|
code: '1231325',
|
||||||
|
dataDate: '2021-01-25T00:00:00Z',
|
||||||
|
dataEndDate: null,
|
||||||
|
data: {
|
||||||
|
id: 'vnd.farmmaps.package.zoning'
|
||||||
|
}
|
||||||
|
} as IItem,
|
||||||
|
{
|
||||||
|
code: '1231325',
|
||||||
|
dataDate: '2022-01-25T00:00:00Z',
|
||||||
|
dataEndDate: '2022-05-25T00:00:00Z',
|
||||||
|
data: {
|
||||||
|
id: 'vnd.farmmaps.package.tipstar'
|
||||||
|
}
|
||||||
|
} as IItem,
|
||||||
|
{
|
||||||
|
code: '1231325',
|
||||||
|
dataDate: '2022-01-25T00:00:00Z',
|
||||||
|
dataEndDate: null,
|
||||||
|
data: {
|
||||||
|
id: 'vnd.farmmaps.package.weather'
|
||||||
|
}
|
||||||
|
} as IItem
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Does not have a tipstar package', () => {
|
||||||
|
const hasPackage = serviceUnderTest.hasPackage('vnd.farmmaps.package.tipstar');
|
||||||
|
expect(hasPackage).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Does have a zoning package', () => {
|
||||||
|
const hasPackage = serviceUnderTest.hasPackage('vnd.farmmaps.package.zoning');
|
||||||
|
expect(hasPackage).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reducer.INITUSERPACKAGESSUCCESS alter state correctly', () => {
|
||||||
|
const action = new appCommonActions.InitUserPackagesSuccess(items);
|
||||||
|
|
||||||
|
expect(Object.keys(initialState.userPackages).length).toBe(0);
|
||||||
|
const state = reducer(initialState, action);
|
||||||
|
expect(Object.keys(state.userPackages).length).toBe(3);
|
||||||
|
expect(state.userPackages['vnd.farmmaps.package.zoning'].length).toBe(2);
|
||||||
|
expect(state.userPackages['vnd.farmmaps.package.tipstar'].length).toBe(1);
|
||||||
|
expect(state.userPackages['vnd.farmmaps.package.weather'].length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('to validatePackage', () => {
|
||||||
|
const action = new appCommonActions.InitUserPackagesSuccess(items);
|
||||||
|
const state = reducer(initialState, action);
|
||||||
|
|
||||||
|
expect(isValidPackage(null)).toBe(false);
|
||||||
|
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.tipstar'][0])).toBe(true);
|
||||||
|
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][0])).toBe(false);
|
||||||
|
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][1])).toBe(true);
|
||||||
|
expect(isValidPackage(state.userPackages['vnd.farmmaps.package.weather'][0])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('to getValidPackages', () => {
|
||||||
|
const action = new appCommonActions.InitUserPackagesSuccess(items);
|
||||||
|
const state = reducer(initialState, action);
|
||||||
|
|
||||||
|
const validPackages = getValidPackages(state.userPackages);
|
||||||
|
|
||||||
|
expect(Object.keys(validPackages).length).toBe(3);
|
||||||
|
|
||||||
|
// today is 27-01-2022, so the below package is not valid
|
||||||
|
expect(validPackages['vnd.farmmaps.package.zoning']).not.toEqual({
|
||||||
|
id: 'vnd.farmmaps.package.zoning',
|
||||||
|
dataDate: '2021-01-25T00:00:00Z',
|
||||||
|
dataEndDate: '2021-05-25T00:00:00Z'
|
||||||
|
} as unknown as IPackage);
|
||||||
|
});
|
||||||
|
});
|
@ -1,37 +1,57 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import { Store} from '@ngrx/store';
|
import {Store} from '@ngrx/store';
|
||||||
import * as appCommonReducer from '../reducers/app-common.reducer'
|
import * as appCommonReducer from '../reducers/app-common.reducer';
|
||||||
import { IPackages } from '../models/package';
|
import {IPackage, IPackages} from '../models/package';
|
||||||
|
|
||||||
import { IItem } from '../models/item';
|
import {IItem} from '../models/item';
|
||||||
import { IItemTask } from '../models/itemTask';
|
import {IItemTask} from '../models/itemTask';
|
||||||
import { HttpClient } from "@angular/common/http";
|
import {HttpClient} from '@angular/common/http';
|
||||||
import { AppConfig } from "../shared/app.config";
|
import {AppConfig} from '../shared/app.config';
|
||||||
import { Observable } from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
|
|
||||||
export class PackageService {
|
export class PackageService {
|
||||||
private packages$:IPackages = {};
|
private packages: { [key: string]: IPackage } = {};
|
||||||
|
|
||||||
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||||
store$.select(appCommonReducer.SelectGetUserPackages).subscribe((packages) => {
|
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
|
||||||
this.packages$ = packages;
|
this.packages = packages;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiEndpoint() {
|
ApiEndpoint() {
|
||||||
return this.appConfig.getConfig("apiEndPoint");
|
return this.appConfig.getConfig('apiEndPoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
hasPackage(id:string):boolean {
|
hasPackage(id: string): boolean {
|
||||||
if(!this.packages$[id]) return false;
|
return id in this.packages;
|
||||||
return this.packages$[id].enabled ? this.packages$[id].enabled == true : true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
||||||
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task);
|
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getValidPackages(packageMap: IPackages): {[key: string]: IPackage} {
|
||||||
|
const keys = Object.keys(packageMap);
|
||||||
|
return keys.filter(k => {
|
||||||
|
const packages = packageMap[k]
|
||||||
|
.filter((p) => isValidPackage(p));
|
||||||
|
|
||||||
|
return packages.length > 0;
|
||||||
|
}).reduce((map, key) => {
|
||||||
|
const packages = packageMap[key];
|
||||||
|
const newMap = {...map};
|
||||||
|
newMap[key] = packages.find(p => isValidPackage(p));
|
||||||
|
return newMap;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isValidPackage(pack: IPackage): boolean {
|
||||||
|
const today = new Date(new Date(Date.now()).toUTCString()).setHours(0, 0, 0, 0);
|
||||||
|
return pack !== null && new Date(pack.dataDate).getTime() <= today
|
||||||
|
&& (!pack.dataEndDate || new Date(pack.dataEndDate).getTime() >= today);
|
||||||
}
|
}
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { TestComponent } from './landingpage.component';
|
|
||||||
|
|
||||||
describe('TestComponent', () => {
|
|
||||||
let component: TestComponent;
|
|
||||||
let fixture: ComponentFixture<TestComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ TestComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(TestComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { MenuComponent } from './menu.component';
|
|
||||||
|
|
||||||
describe('MenuComponent', () => {
|
|
||||||
let component: MenuComponent;
|
|
||||||
let fixture: ComponentFixture<MenuComponent>;
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
declarations: [ MenuComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(MenuComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,25 +0,0 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { TestComponent } from './test.component';
|
|
||||||
|
|
||||||
describe('TestComponent', () => {
|
|
||||||
let component: TestComponent;
|
|
||||||
let fixture: ComponentFixture<TestComponent>;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await TestBed.configureTestingModule({
|
|
||||||
declarations: [ TestComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(TestComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user