diff --git a/package.json b/package.json index b1eb116..05f5bbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "farmmaps-lib-app", - "version": "1.1.9", + "version": "1.1.10", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/projects/common/src/fm/components/app-menu/app-menu.component.spec.ts b/projects/common/src/fm/components/app-menu/app-menu.component.spec.ts deleted file mode 100644 index bc5b5eb..0000000 --- a/projects/common/src/fm/components/app-menu/app-menu.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ AppMenuComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(AppMenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/avatar/avatar.component.spec.ts b/projects/common/src/fm/components/avatar/avatar.component.spec.ts deleted file mode 100644 index 7c3ee67..0000000 --- a/projects/common/src/fm/components/avatar/avatar.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { AvatarComponent } from './avatar.component'; - -describe('AvatarComponent', () => { - let component: AvatarComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ AvatarComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(AvatarComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/edit-image-modal/edit-image-modal.component.spec.ts b/projects/common/src/fm/components/edit-image-modal/edit-image-modal.component.spec.ts deleted file mode 100644 index 7395ec0..0000000 --- a/projects/common/src/fm/components/edit-image-modal/edit-image-modal.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ EditImageModalComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(EditImageModalComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/gradient-select/gradient-select.component.spec.ts b/projects/common/src/fm/components/gradient-select/gradient-select.component.spec.ts deleted file mode 100644 index 3fc1cb5..0000000 --- a/projects/common/src/fm/components/gradient-select/gradient-select.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ GradientSelectComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(GradientSelectComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/gradient/gradient.component.spec.ts b/projects/common/src/fm/components/gradient/gradient.component.spec.ts deleted file mode 100644 index 63f5330..0000000 --- a/projects/common/src/fm/components/gradient/gradient.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { GradientComponent } from './gradient.component'; - -describe('GradientComponent', () => { - let component: GradientComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ GradientComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(GradientComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/has-package/has-package.directive.ts b/projects/common/src/fm/components/has-package/has-package.directive.ts index 86fc207..02b5823 100644 --- a/projects/common/src/fm/components/has-package/has-package.directive.ts +++ b/projects/common/src/fm/components/has-package/has-package.directive.ts @@ -1,11 +1,13 @@ -import {Directive, Input, OnDestroy, TemplateRef, ViewContainerRef} from '@angular/core'; +import {AfterViewInit, Directive, Input, OnDestroy, TemplateRef, ViewContainerRef} from '@angular/core'; import {Subscription} from 'rxjs'; import {PackageService} from '../../services/package.service'; +import * as appCommonReducer from '../../reducers/app-common.reducer'; +import {Store} from '@ngrx/store'; @Directive({ selector: '[fmHasPackage]', }) -export class HasPackageDirective implements OnDestroy { +export class HasPackageDirective implements OnDestroy, AfterViewInit { @Input() set fmHasPackage(packageIdentifier: string) { @@ -31,8 +33,14 @@ export class HasPackageDirective implements OnDestroy { private packSub: Subscription; constructor(private hostTemplateRef: TemplateRef, private viewContainerRef: ViewContainerRef, - private packageService: PackageService) { + private store: Store, private packageService: PackageService) { this.thenTemplate = hostTemplateRef; + this.packSub = this.store.select(appCommonReducer.SelectGetUserPackages).subscribe((_) => { + this.updateView(); + }); + } + + ngAfterViewInit() { this.updateView(); } diff --git a/projects/common/src/fm/components/help-menu/help-menu.component.spec.ts b/projects/common/src/fm/components/help-menu/help-menu.component.spec.ts deleted file mode 100644 index f475164..0000000 --- a/projects/common/src/fm/components/help-menu/help-menu.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ HelpMenuComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(HelpMenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/notification-menu/notification-menu.component.spec.ts b/projects/common/src/fm/components/notification-menu/notification-menu.component.spec.ts deleted file mode 100644 index b12d608..0000000 --- a/projects/common/src/fm/components/notification-menu/notification-menu.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ NotificationMenuComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(NotificationMenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/components/user-menu/user-menu.component.spec.ts b/projects/common/src/fm/components/user-menu/user-menu.component.spec.ts deleted file mode 100644 index f270ab8..0000000 --- a/projects/common/src/fm/components/user-menu/user-menu.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ UserMenuComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(UserMenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/common/src/fm/reducers/app-common.reducer.ts b/projects/common/src/fm/reducers/app-common.reducer.ts index 7ed3a20..33f8dde 100644 --- a/projects/common/src/fm/reducers/app-common.reducer.ts +++ b/projects/common/src/fm/reducers/app-common.reducer.ts @@ -8,7 +8,7 @@ import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/s import { MODULE_NAME } from '../module-name'; import { IItem } from '../models/item'; -import {isValidPackage} from '../services/package.service'; +import {getValidPackages, isValidPackage} from '../services/package.service'; export interface State { openedModalName: string, @@ -208,19 +208,7 @@ export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuV export const SelectGetUser = createSelector(selectAppCommonState,getUser); export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages); export const SelectGetValidUserPackages = createSelector(SelectGetUserPackages, (packageMap) => { - 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]; - return { - ...map, - key: packages[0] - }; - }, {}); + return getValidPackages(packageMap); }); export const SelectGetUserSettingsRoot = createSelector(selectAppCommonState,getUserSettingsRoot); export const SelectGetAccountMenuVisible = createSelector(selectAppCommonState,getAccountMenuVisible); @@ -232,3 +220,4 @@ export const SelectgetUnreadNotifications = createSelector(selectAppCommonState, export const SelectGetIsOnline = createSelector(selectAppCommonState,getIsOnline); export const SelectGetIsPageMode = createSelector(selectAppCommonState,getIsPageMode); + diff --git a/projects/common/src/fm/services/package.service.spec.ts b/projects/common/src/fm/services/package.service.spec.ts new file mode 100644 index 0000000..1838e0f --- /dev/null +++ b/projects/common/src/fm/services/package.service.spec.ts @@ -0,0 +1,87 @@ +import {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'; + +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: '2022-01-25T00:00:00.000000Z', + data: { + id: 'vnd.farmmaps.package.zoning' + } + } as IItem, + { + code: '1231325', + dataDate: '2021-01-25T00:00:00.000000Z', + data: { + id: 'vnd.farmmaps.package.zoning' + } + } as IItem, + { + code: '1231325', + dataDate: '2022-01-25T00:00:00.000000Z', + dataEndDate: '2022-05-25T00:00:00.000000Z', + data: { + id: 'vnd.farmmaps.package.tipstar' + } + } 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(2); + expect(state.userPackages['vnd.farmmaps.package.zoning'].length).toBe(2); + expect(state.userPackages['vnd.farmmaps.package.tipstar'].length).toBe(1); + + expect(isValidPackage(state.userPackages['vnd.farmmaps.package.tipstar'][0])).toBe(true); + expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][0])).toBe(true); + expect(isValidPackage(state.userPackages['vnd.farmmaps.package.zoning'][1])).toBe(true); + }); +}); diff --git a/projects/common/src/fm/services/package.service.ts b/projects/common/src/fm/services/package.service.ts index 7afd1c9..43fe85d 100644 --- a/projects/common/src/fm/services/package.service.ts +++ b/projects/common/src/fm/services/package.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import {Store} from '@ngrx/store'; import * as appCommonReducer from '../reducers/app-common.reducer'; -import {IPackage} from '../models/package'; +import {IPackage, IPackages} from '../models/package'; import {IItem} from '../models/item'; import {IItemTask} from '../models/itemTask'; @@ -35,6 +35,22 @@ export class PackageService { } } +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]; + return { + ...map, + key: packages[0] + }; + }, {}); +} + 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 diff --git a/src/app/landingpage/landingpage.component.spec.ts b/src/app/landingpage/landingpage.component.spec.ts deleted file mode 100644 index fb77e15..0000000 --- a/src/app/landingpage/landingpage.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { TestComponent } from './landingpage.component'; - -describe('TestComponent', () => { - let component: TestComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ TestComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(TestComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/menu/menu.component.spec.ts b/src/app/menu/menu.component.spec.ts deleted file mode 100644 index beb2d9b..0000000 --- a/src/app/menu/menu.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ MenuComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(MenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/test/test.component.spec.ts b/src/app/test/test.component.spec.ts deleted file mode 100644 index e0f9bcc..0000000 --- a/src/app/test/test.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { TestComponent } from './test.component'; - -describe('TestComponent', () => { - let component: TestComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [ TestComponent ] - }) - .compileComponents(); - }); - - beforeEach(() => { - fixture = TestBed.createComponent(TestComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -});