Merge branch 'dev' into remove-async-apis

pull/2464/head
Halil İbrahim Kalkan 6 years ago
commit b6f5fbb9e5

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { ConfigState } from '../states';
import { GetAppConfiguration, PatchRouteByName, AddRoute } from '../actions/config.actions';
import { ABP } from '../models';
@Injectable({
providedIn: 'root',
@ -47,4 +49,16 @@ export class ConfigStateService {
getLocalization(...args: Parameters<typeof ConfigState.getLocalization>) {
return this.store.selectSnapshot(ConfigState.getLocalization(...args));
}
dispatchGetAppConfiguration() {
return this.store.dispatch(new GetAppConfiguration());
}
dispatchPatchRouteByName(...args: ConstructorParameters<typeof PatchRouteByName>) {
return this.store.dispatch(new PatchRouteByName(...args));
}
dispatchAddRoute(...args: ConstructorParameters<typeof AddRoute>) {
return this.store.dispatch(new AddRoute(...args));
}
}

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { ProfileState } from '../states';
import { Profile } from '../models';
import { GetProfile, UpdateProfile, ChangePassword } from '../actions';
@Injectable({
providedIn: 'root',
@ -11,4 +13,16 @@ export class ProfileStateService {
getProfile() {
return this.store.selectSnapshot(ProfileState.getProfile);
}
dispatchGetProfile() {
return this.store.dispatch(new GetProfile());
}
dispatchUpdateProfile(...args: ConstructorParameters<typeof UpdateProfile>) {
return this.store.dispatch(new UpdateProfile(...args));
}
dispatchChangePassword(...args: ConstructorParameters<typeof ChangePassword>) {
return this.store.dispatch(new ChangePassword(...args));
}
}

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { SessionState } from '../states';
import { ABP } from '../models';
import { SetLanguage, SetTenant } from '../actions';
@Injectable({
providedIn: 'root',
@ -15,4 +17,12 @@ export class SessionStateService {
getTenant() {
return this.store.selectSnapshot(SessionState.getTenant);
}
dispatchSetLanguage(...args: ConstructorParameters<typeof SetLanguage>) {
return this.store.dispatch(new SetLanguage(...args));
}
dispatchSetTenant(...args: ConstructorParameters<typeof SetTenant>) {
return this.store.dispatch(new SetTenant(...args));
}
}

@ -3,6 +3,7 @@ import { ConfigStateService } from '../services/config-state.service';
import { ConfigState } from '../states';
import { Store } from '@ngxs/store';
import { Config } from '../models/config';
import * as ConfigActions from '../actions';
const CONFIG_STATE_DATA = {
environment: {
@ -140,4 +141,21 @@ describe('ConfigStateService', () => {
}
});
});
test('should have a dispatch method for every ConfigState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
ConfigStateService.toString()
.match(reg)
.forEach(fnName => {
expect(ConfigActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(ConfigActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new ConfigActions[fnName](...params));
});
});
});

@ -2,6 +2,8 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { ProfileStateService } from '../services/profile-state.service';
import { ProfileState } from '../states/profile.state';
import { Store } from '@ngxs/store';
import * as ProfileActions from '../actions';
describe('ProfileStateService', () => {
let service: ProfileStateService;
let spectator: SpectatorService<ProfileStateService>;
@ -35,4 +37,21 @@ describe('ProfileStateService', () => {
}
});
});
test('should have a dispatch method for every ProfileState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
ProfileStateService.toString()
.match(reg)
.forEach(fnName => {
expect(ProfileActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(ProfileActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new ProfileActions[fnName](...params));
});
});
});

@ -2,6 +2,8 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { SessionStateService } from '../services/session-state.service';
import { SessionState } from '../states/session.state';
import { Store } from '@ngxs/store';
import * as SessionActions from '../actions';
describe('SessionStateService', () => {
let service: SessionStateService;
let spectator: SpectatorService<SessionStateService>;
@ -35,4 +37,21 @@ describe('SessionStateService', () => {
}
});
});
test('should have a dispatch method for every sessionState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
SessionStateService.toString()
.match(reg)
.forEach(fnName => {
expect(SessionActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(SessionActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new SessionActions[fnName](...params));
});
});
});

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { FeatureManagementState } from '../states';
import { FeatureManagement } from '../models';
import { GetFeatures, UpdateFeatures } from '../actions';
@Injectable({
providedIn: 'root',
@ -11,4 +13,12 @@ export class FeatureManagementStateService {
getFeatures() {
return this.store.selectSnapshot(FeatureManagementState.getFeatures);
}
dispatchGetFeatures(...args: ConstructorParameters<typeof GetFeatures>) {
return this.store.dispatch(new GetFeatures(...args));
}
dispatchUpdateFeatures(...args: ConstructorParameters<typeof UpdateFeatures>) {
return this.store.dispatch(new UpdateFeatures(...args));
}
}

@ -2,13 +2,17 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { Store } from '@ngxs/store';
import { FeatureManagementStateService } from '../services/feature-management-state.service';
import { FeatureManagementState } from '../states';
import * as FeatureManagementActions from '../actions';
describe('FeatureManagementStateService', () => {
let service: FeatureManagementStateService;
let spectator: SpectatorService<FeatureManagementStateService>;
let store: SpyObject<Store>;
const createService = createServiceFactory({ service: FeatureManagementStateService, mocks: [Store] });
const createService = createServiceFactory({
service: FeatureManagementStateService,
mocks: [Store],
});
beforeEach(() => {
spectator = createService();
service = spectator.service;
@ -37,4 +41,21 @@ describe('FeatureManagementStateService', () => {
}
});
});
test('should have a dispatch method for every FeatureManagementState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
FeatureManagementStateService.toString()
.match(reg)
.forEach(fnName => {
expect(FeatureManagementActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(FeatureManagementActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new FeatureManagementActions[fnName](...params));
});
});
});

@ -1,5 +1,20 @@
import { ABP } from '@abp/ng.core';
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import {
CreateRole,
CreateUser,
DeleteRole,
DeleteUser,
GetRoleById,
GetRoles,
GetUserById,
GetUsers,
UpdateRole,
UpdateUser,
GetUserRoles,
} from '../actions/identity.actions';
import { Identity } from '../models/identity';
import { IdentityState } from '../states/identity.state';
@Injectable({
@ -20,4 +35,48 @@ export class IdentityStateService {
getUsersTotalCount() {
return this.store.selectSnapshot(IdentityState.getUsersTotalCount);
}
dispatchGetRoles(...args: ConstructorParameters<typeof GetRoles>) {
return this.store.dispatch(new GetRoles(...args));
}
dispatchGetRoleById(...args: ConstructorParameters<typeof GetRoleById>) {
return this.store.dispatch(new GetRoleById(...args));
}
dispatchDeleteRole(...args: ConstructorParameters<typeof DeleteRole>) {
return this.store.dispatch(new DeleteRole(...args));
}
dispatchCreateRole(...args: ConstructorParameters<typeof CreateRole>) {
return this.store.dispatch(new CreateRole(...args));
}
dispatchUpdateRole(...args: ConstructorParameters<typeof UpdateRole>) {
return this.store.dispatch(new UpdateRole(...args));
}
dispatchGetUsers(...args: ConstructorParameters<typeof GetUsers>) {
return this.store.dispatch(new GetUsers(...args));
}
dispatchGetUserById(...args: ConstructorParameters<typeof GetUserById>) {
return this.store.dispatch(new GetUserById(...args));
}
dispatchDeleteUser(...args: ConstructorParameters<typeof DeleteUser>) {
return this.store.dispatch(new DeleteUser(...args));
}
dispatchCreateUser(...args: ConstructorParameters<typeof CreateUser>) {
return this.store.dispatch(new CreateUser(...args));
}
dispatchUpdateUser(...args: ConstructorParameters<typeof UpdateUser>) {
return this.store.dispatch(new UpdateUser(...args));
}
dispatchGetUserRoles(...args: ConstructorParameters<typeof GetUserRoles>) {
return this.store.dispatch(new GetUserRoles(...args));
}
}

@ -2,6 +2,8 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { IdentityStateService } from '../services/identity-state.service';
import { IdentityState } from '../states/identity.state';
import { Store } from '@ngxs/store';
import * as IdentityActions from '../actions/identity.actions';
describe('IdentityStateService', () => {
let service: IdentityStateService;
let spectator: SpectatorService<IdentityStateService>;
@ -36,4 +38,21 @@ describe('IdentityStateService', () => {
}
});
});
test('should have a dispatch method for every IdentityState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
IdentityStateService.toString()
.match(reg)
.forEach(fnName => {
expect(IdentityActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(IdentityActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new IdentityActions[fnName](...params));
});
});
});

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { PermissionManagementState } from '../states/permission-management.state';
import { PermissionManagement } from '../models';
import { GetPermissions, UpdatePermissions } from '../actions';
@Injectable({
providedIn: 'root',
@ -14,4 +16,12 @@ export class PermissionManagementStateService {
getEntityDisplayName() {
return this.store.selectSnapshot(PermissionManagementState.getEntityDisplayName);
}
dispatchGetPermissions(...args: ConstructorParameters<typeof GetPermissions>) {
return this.store.dispatch(new GetPermissions(...args));
}
dispatchUpdatePermissions(...args: ConstructorParameters<typeof UpdatePermissions>) {
return this.store.dispatch(new UpdatePermissions(...args));
}
}

@ -2,13 +2,17 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { PermissionManagementStateService } from '../services/permission-management-state.service';
import { PermissionManagementState } from '../states/permission-management.state';
import { Store } from '@ngxs/store';
import * as PermissionManagementActions from '../actions';
describe('PermissionManagementStateService', () => {
let service: PermissionManagementStateService;
let spectator: SpectatorService<PermissionManagementStateService>;
let store: SpyObject<Store>;
const createService = createServiceFactory({ service: PermissionManagementStateService, mocks: [Store] });
const createService = createServiceFactory({
service: PermissionManagementStateService,
mocks: [Store],
});
beforeEach(() => {
spectator = createService();
service = spectator.service;
@ -36,4 +40,21 @@ describe('PermissionManagementStateService', () => {
}
});
});
test('should have a dispatch method for every PermissionManagementState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
PermissionManagementStateService.toString()
.match(reg)
.forEach(fnName => {
expect(PermissionManagementActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(PermissionManagementActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new PermissionManagementActions[fnName](...params));
});
});
});

@ -1,6 +1,9 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { TenantManagementState } from '../states/tenant-management.state';
import { ABP } from '@abp/ng.core';
import { GetTenants, GetTenantById, CreateTenant, UpdateTenant, DeleteTenant } from '../actions';
import { TenantManagement } from '../models';
@Injectable({
providedIn: 'root',
@ -15,4 +18,24 @@ export class TenantManagementStateService {
getTenantsTotalCount() {
return this.store.selectSnapshot(TenantManagementState.getTenantsTotalCount);
}
dispatchGetTenants(...args: ConstructorParameters<typeof GetTenants>) {
return this.store.dispatch(new GetTenants(...args));
}
dispatchGetTenantById(...args: ConstructorParameters<typeof GetTenantById>) {
return this.store.dispatch(new GetTenantById(...args));
}
dispatchCreateTenant(...args: ConstructorParameters<typeof CreateTenant>) {
return this.store.dispatch(new CreateTenant(...args));
}
dispatchUpdateTenant(...args: ConstructorParameters<typeof UpdateTenant>) {
return this.store.dispatch(new UpdateTenant(...args));
}
dispatchDeleteTenant(...args: ConstructorParameters<typeof DeleteTenant>) {
return this.store.dispatch(new DeleteTenant(...args));
}
}

@ -1,15 +1,15 @@
import { ABP } from '@abp/ng.core';
import { Action, Selector, State, StateContext } from '@ngxs/store';
import { switchMap, tap } from 'rxjs/operators';
import { tap } from 'rxjs/operators';
import {
CreateTenant,
DeleteTenant,
GetTenants,
GetTenantById,
GetTenants,
UpdateTenant,
} from '../actions/tenant-management.actions';
import { TenantManagement } from '../models/tenant-management';
import { TenantManagementService } from '../services/tenant-management.service';
import { ABP } from '@abp/ng.core';
@State<TenantManagement.State>({
name: 'TenantManagementState',

@ -2,12 +2,17 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { TenantManagementStateService } from '../services/tenant-management-state.service';
import { TenantManagementState } from '../states/tenant-management.state';
import { Store } from '@ngxs/store';
import * as TenantManagementActions from '../actions';
describe('TenantManagementStateService', () => {
let service: TenantManagementStateService;
let spectator: SpectatorService<TenantManagementStateService>;
let store: SpyObject<Store>;
const createService = createServiceFactory({ service: TenantManagementStateService, mocks: [Store] });
const createService = createServiceFactory({
service: TenantManagementStateService,
mocks: [Store],
});
beforeEach(() => {
spectator = createService();
service = spectator.service;
@ -36,4 +41,21 @@ describe('TenantManagementStateService', () => {
}
});
});
test('should have a dispatch method for every TenantManagementState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
TenantManagementStateService.toString()
.match(reg)
.forEach(fnName => {
expect(TenantManagementActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(TenantManagementActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new TenantManagementActions[fnName](...params));
});
});
});

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { LayoutState } from '../states/layout.state';
import { AddNavigationElement, RemoveNavigationElementByName } from '../actions';
import { Layout } from '../models/layout';
@Injectable()
export class LayoutStateService {
@ -9,4 +11,14 @@ export class LayoutStateService {
getNavigationElements() {
return this.store.selectSnapshot(LayoutState.getNavigationElements);
}
dispatchAddNavigationElement(...args: ConstructorParameters<typeof AddNavigationElement>) {
return this.store.dispatch(new AddNavigationElement(...args));
}
dispatchRemoveNavigationElementByName(
...args: ConstructorParameters<typeof RemoveNavigationElementByName>
) {
return this.store.dispatch(new RemoveNavigationElementByName(...args));
}
}

@ -1,8 +1,7 @@
import { State, Action, StateContext, Selector } from '@ngxs/store';
import { Action, Selector, State, StateContext } from '@ngxs/store';
import snq from 'snq';
import { AddNavigationElement, RemoveNavigationElementByName } from '../actions/layout.actions';
import { Layout } from '../models/layout';
import { TemplateRef } from '@angular/core';
import snq from 'snq';
@State<Layout.State>({
name: 'LayoutState',
@ -15,7 +14,10 @@ export class LayoutState {
}
@Action(AddNavigationElement)
layoutAddAction({ getState, patchState }: StateContext<Layout.State>, { payload = [] }: AddNavigationElement) {
layoutAddAction(
{ getState, patchState }: StateContext<Layout.State>,
{ payload = [] }: AddNavigationElement,
) {
let { navigationElements } = getState();
if (!Array.isArray(payload)) {
@ -44,7 +46,10 @@ export class LayoutState {
}
@Action(RemoveNavigationElementByName)
layoutRemoveAction({ getState, patchState }: StateContext<Layout.State>, { name }: RemoveNavigationElementByName) {
layoutRemoveAction(
{ getState, patchState }: StateContext<Layout.State>,
{ name }: RemoveNavigationElementByName,
) {
let { navigationElements } = getState();
const index = navigationElements.findIndex(element => element.name === name);

@ -1,7 +1,8 @@
import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store';
import * as LayoutActions from '../actions';
import { LayoutStateService } from '../services/layout-state.service';
import { LayoutState } from '../states/layout.state';
import { Store } from '@ngxs/store';
describe('LayoutStateService', () => {
let service: LayoutStateService;
let spectator: SpectatorService<LayoutStateService>;
@ -36,4 +37,21 @@ describe('LayoutStateService', () => {
}
});
});
test('should have a dispatch method for every LayoutState action', () => {
const reg = /(?<=dispatch)(\w+)(?=\()/gm;
LayoutStateService.toString()
.match(reg)
.forEach(fnName => {
expect(LayoutActions[fnName]).toBeTruthy();
const spy = jest.spyOn(store, 'dispatch');
spy.mockClear();
const params = Array.from(new Array(LayoutActions[fnName].length));
service[`dispatch${fnName}`](...params);
expect(spy).toHaveBeenCalledWith(new LayoutActions[fnName](...params));
});
});
});

Loading…
Cancel
Save