From a601a10d9abadfcb7264784554184788d71f962c Mon Sep 17 00:00:00 2001 From: TheDiaval Date: Thu, 13 Feb 2020 14:27:00 +0300 Subject: [PATCH 1/3] feat(core): add set environment action to config state --- .../core/src/lib/actions/config.actions.ts | 6 ++++++ .../packages/core/src/lib/states/config.state.ts | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/actions/config.actions.ts b/npm/ng-packs/packages/core/src/lib/actions/config.actions.ts index 56d0874ebde..8fd11bd2cb8 100644 --- a/npm/ng-packs/packages/core/src/lib/actions/config.actions.ts +++ b/npm/ng-packs/packages/core/src/lib/actions/config.actions.ts @@ -1,4 +1,5 @@ import { ABP } from '../models/common'; +import { Config } from '../models/config'; export class PatchRouteByName { static readonly type = '[Config] Patch Route By Name'; @@ -16,3 +17,8 @@ export class AddRoute { static readonly type = '[Config] Add Route'; constructor(public payload: Omit) {} } + +export class SetEnvironment { + static readonly type = '[Config] Set Environment'; + constructor(public environment: Config.Environment) {} +} diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index debbc9b8a07..ff964cfe926 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -2,7 +2,12 @@ import { Action, createSelector, Selector, State, StateContext, Store } from '@n import { of } from 'rxjs'; import { switchMap, tap } from 'rxjs/operators'; import snq from 'snq'; -import { GetAppConfiguration, PatchRouteByName, AddRoute } from '../actions/config.actions'; +import { + GetAppConfiguration, + PatchRouteByName, + AddRoute, + SetEnvironment, +} from '../actions/config.actions'; import { SetLanguage } from '../actions/session.actions'; import { ABP } from '../models/common'; import { Config } from '../models/config'; @@ -291,6 +296,13 @@ export class ConfigState { flattedRoutes, }); } + + @Action(SetEnvironment) + setEnvironment({ patchState }: StateContext, environment: Config.Environment) { + return patchState({ + environment, + }); + } } function patchRouteDeep( From 586047682b7e562a7c932537d8dec74d13656112 Mon Sep 17 00:00:00 2001 From: TheDiaval Date: Thu, 13 Feb 2020 14:27:28 +0300 Subject: [PATCH 2/3] feat(core): add dispatch function for set environment action --- .../core/src/lib/services/config-state.service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts index 506b278634a..cf97e42b0f3 100644 --- a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts @@ -1,8 +1,12 @@ import { Injectable } from '@angular/core'; import { Store } from '@ngxs/store'; +import { + AddRoute, + GetAppConfiguration, + PatchRouteByName, + SetEnvironment, +} from '../actions/config.actions'; import { ConfigState } from '../states'; -import { GetAppConfiguration, PatchRouteByName, AddRoute } from '../actions/config.actions'; -import { ABP } from '../models'; @Injectable({ providedIn: 'root', @@ -61,4 +65,8 @@ export class ConfigStateService { dispatchAddRoute(...args: ConstructorParameters) { return this.store.dispatch(new AddRoute(...args)); } + + dispatchSetEnvironment(...args: ConstructorParameters) { + return this.store.dispatch(new SetEnvironment(...args)); + } } From 4eb57ba270cd9b22fce284b9f8ee0a4a360a6721 Mon Sep 17 00:00:00 2001 From: TheDiaval Date: Thu, 13 Feb 2020 14:46:16 +0300 Subject: [PATCH 3/3] test(theme-shared): correct directive test --- .../src/lib/tests/table-sort.directive.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/table-sort.directive.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/table-sort.directive.spec.ts index f3595180994..231f627fa1d 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/table-sort.directive.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/table-sort.directive.spec.ts @@ -1,16 +1,20 @@ import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator/jest'; import { TableSortDirective } from '../directives/table-sort.directive'; +import { TableComponent } from '../components/table/table.component'; +import { DummyLocalizationPipe } from './table.component.spec'; +import { PaginationComponent } from '../components'; describe('TableSortDirective', () => { let spectator: SpectatorDirective; let directive: TableSortDirective; const createDirective = createDirectiveFactory({ directive: TableSortDirective, + declarations: [TableComponent, DummyLocalizationPipe, PaginationComponent], }); beforeEach(() => { spectator = createDirective( - ``, + ``, ); directive = spectator.directive; }); @@ -21,7 +25,7 @@ describe('TableSortDirective', () => { test('should change table value', () => { expect(directive.value).toEqual([1, 4, 2]); - const table = spectator.query(Table); + const table = spectator.query(TableComponent); expect(table.value).toEqual([1, 2, 4]); }); });