Merge pull request #2822 from abpframework/feat/set-environment-action

feat(core): set environment action
pull/2824/head
Yasin Aydın 6 years ago committed by GitHub
commit cb7c53862d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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<ABP.Route, 'children'>) {}
}
export class SetEnvironment {
static readonly type = '[Config] Set Environment';
constructor(public environment: Config.Environment) {}
}

@ -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<typeof AddRoute>) {
return this.store.dispatch(new AddRoute(...args));
}
dispatchSetEnvironment(...args: ConstructorParameters<typeof SetEnvironment>) {
return this.store.dispatch(new SetEnvironment(...args));
}
}

@ -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<Config.State>, environment: Config.Environment) {
return patchState({
environment,
});
}
}
function patchRouteDeep(

@ -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<TableSortDirective>;
let directive: TableSortDirective;
const createDirective = createDirectiveFactory({
directive: TableSortDirective,
declarations: [TableComponent, DummyLocalizationPipe, PaginationComponent],
});
beforeEach(() => {
spectator = createDirective(
`<p-table [value]="[1,4,2]" [abpTableSort]="{ order: 'asc' }"></p-table>`,
`<abp-table [value]="[1,4,2]" [abpTableSort]="{ order: 'asc' }"></abp-table>`,
);
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]);
});
});

Loading…
Cancel
Save