From bdd5d9ab232ba3068b5318b47efbb5e413d689fc Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 15 Oct 2019 08:35:01 +0300 Subject: [PATCH 1/3] test(core): config.state.spec --- .../core/src/lib/states/config.state.ts | 8 +- .../core/src/lib/tests/config.state.spec.ts | 88 +++++++++++++++++-- 2 files changed, 83 insertions(+), 13 deletions(-) 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 1dfb454fff..affa63892d 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 @@ -278,18 +278,16 @@ function patchRouteDeep( routes: ABP.FullRoute[], name: string, newValue: Partial, - parentUrl: string = null, + parentUrl: string = '', ): ABP.FullRoute[] { routes = routes.map(route => { if (route.name === name) { - if (newValue.path) { - newValue.url = `${parentUrl}/${newValue.path}`; - } + newValue.url = `${parentUrl}/${(!newValue.path && newValue.path === '' ? route.path : newValue.path) || ''}`; if (newValue.children && newValue.children.length) { newValue.children = newValue.children.map(child => ({ ...child, - url: `${parentUrl}/${route.path}/${child.path}`, + url: `${newValue.url}/${child.path}`.replace('//', '/'), })); } diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index dc354db731..2d4bd69c49 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -1,11 +1,10 @@ -import { Router } from '@angular/router'; import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; -import { Store, NgxsModule } from '@ngxs/store'; -import { Observable, of } from 'rxjs'; -import { ConfigService, ApplicationConfigurationService, RestService } from '../services'; -import { ConfigState } from '../states'; -import { HttpClient } from '@angular/common/http'; +import { Store } from '@ngxs/store'; +import { ReplaySubject, timer, Subject, of } from 'rxjs'; import { Config } from '../models/config'; +import { ApplicationConfigurationService, ConfigService } from '../services'; +import { ConfigState } from '../states'; +import { SetLanguage, PatchRouteByName } from '../actions'; export const CONFIG_STATE_DATA = { environment: { @@ -115,6 +114,7 @@ describe('ConfigService', () => { let store: SpyObject; let service: ConfigService; let state: ConfigState; + let appConfigService: SpyObject; const createService = createServiceFactory({ service: ConfigService, @@ -125,6 +125,7 @@ describe('ConfigService', () => { spectator = createService(); store = spectator.get(Store); service = spectator.service; + appConfigService = spectator.get(ApplicationConfigurationService); state = new ConfigState(spectator.get(ApplicationConfigurationService), store); }); @@ -223,8 +224,79 @@ describe('ConfigService', () => { }); describe('#GetAppConfiguration', () => { - it('should call the getConfiguration of ApplicationConfigurationService and patch the state', () => { - // state.addData() + it('should call the getConfiguration of ApplicationConfigurationService and patch the state', done => { + let patchStateArg; + let dispatchArg; + + const configuration = { + setting: { values: { 'Abp.Localization.DefaultLanguage': 'tr;TR' } }, + }; + + const res$ = new ReplaySubject(1); + res$.next(configuration); + + const patchState = jest.fn(s => (patchStateArg = s)); + const dispatch = jest.fn(a => { + dispatchArg = a; + return of(a); + }); + appConfigService.getConfiguration.andReturn(res$); + + state.addData({ patchState, dispatch } as any).subscribe(); + + timer(0).subscribe(() => { + expect(patchStateArg).toEqual(configuration); + expect(dispatchArg instanceof SetLanguage).toBeTruthy(); + expect(dispatchArg).toEqual({ payload: 'tr' }); + done(); + }); + }); + }); + + describe('#PatchRouteByName', () => { + it('should should patch the route', () => { + let patchStateArg; + + const patchState = jest.fn(s => (patchStateArg = s)); + const getState = jest.fn(() => CONFIG_STATE_DATA); + + state.patchRoute( + { patchState, getState } as any, + new PatchRouteByName('::Menu:Home', { + name: 'Home', + path: 'home', + children: [{ path: 'dashboard', name: 'Dashboard' }], + }), + ); + + expect(patchStateArg.routes[0]).toEqual({ + name: 'Home', + path: 'home', + url: '/home', + children: [{ path: 'dashboard', name: 'Dashboard', url: '/home/dashboard' }], + }); + }); + + it('should should patch the route without path', () => { + let patchStateArg; + + const patchState = jest.fn(s => (patchStateArg = s)); + const getState = jest.fn(() => CONFIG_STATE_DATA); + + state.patchRoute( + { patchState, getState } as any, + new PatchRouteByName('::Menu:Home', { + name: 'Main', + children: [{ path: 'dashboard', name: 'Dashboard' }], + }), + ); + + expect(patchStateArg.routes[0]).toEqual({ + name: 'Main', + path: '', + url: '/', + children: [{ path: 'dashboard', name: 'Dashboard', url: '/dashboard' }], + }); }); }); }); From f8a48bf4d2a6fd0282651566c62086194ecaa8af Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 15 Oct 2019 10:19:28 +0300 Subject: [PATCH 2/3] Update HomeController.cs --- .../Controllers/HomeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs index 71c6127f9e..8806e20e35 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs @@ -9,7 +9,7 @@ namespace MyCompanyName.MyProjectName.Controllers { //TODO: Enabled once Swagger supports ASP.NET Core 3.x //return Redirect("/swagger"); - return Content("OK: MyCompanyName.MyProjectName.HttpApi.HostWithIds is running..."); + return Content("OK: Acme.BookStore.HttpApi.Host is running..."); } } } From e07765c7be1f7d2491e2a669dbd5249ac67de104 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 15 Oct 2019 10:23:25 +0300 Subject: [PATCH 3/3] Update HomeController.cs --- .../Controllers/HomeController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs index 8806e20e35..0db5c96aee 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/Controllers/HomeController.cs @@ -9,7 +9,7 @@ namespace MyCompanyName.MyProjectName.Controllers { //TODO: Enabled once Swagger supports ASP.NET Core 3.x //return Redirect("/swagger"); - return Content("OK: Acme.BookStore.HttpApi.Host is running..."); + return Content("OK: MyCompanyName.MyProjectName.HttpApi.Host is running..."); } } }