Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): set environment action #2822

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions npm/ng-packs/packages/core/src/lib/actions/config.actions.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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));
}
}
14 changes: 13 additions & 1 deletion npm/ng-packs/packages/core/src/lib/states/config.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -291,6 +296,13 @@ export class ConfigState {
flattedRoutes,
});
}

@Action(SetEnvironment)
setEnvironment({ patchState }: StateContext<Config.State>, environment: Config.Environment) {
return patchState({
environment,
});
}
}

function patchRouteDeep(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
});
Expand All @@ -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]);
});
});