mirror of https://github.com/abpframework/abp.git
committed by
GitHub
13 changed files with 90 additions and 56 deletions
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json", |
||||
|
"dest": "../../dist/core/testing", |
||||
|
"lib": { |
||||
|
"entryFile": "src/public-api.ts" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
import { |
||||
|
ABP, |
||||
|
BaseCoreModule, |
||||
|
coreOptionsFactory, |
||||
|
CORE_OPTIONS, |
||||
|
LocalizationPipe, |
||||
|
} from '@abp/ng.core'; |
||||
|
import { APP_BASE_HREF } from '@angular/common'; |
||||
|
import { ModuleWithProviders, NgModule } from '@angular/core'; |
||||
|
import { provideRoutes } from '@angular/router'; |
||||
|
import { RouterTestingModule } from '@angular/router/testing'; |
||||
|
import { MockLocalizationPipe } from './pipes/mock-localization.pipe'; |
||||
|
|
||||
|
/** |
||||
|
* CoreTestingModule is the module that will be used in tests |
||||
|
* and it provides mock alternatives |
||||
|
*/ |
||||
|
@NgModule({ |
||||
|
exports: [RouterTestingModule, BaseCoreModule, MockLocalizationPipe], |
||||
|
imports: [RouterTestingModule, BaseCoreModule], |
||||
|
declarations: [MockLocalizationPipe], |
||||
|
}) |
||||
|
export class CoreTestingModule { |
||||
|
static forTest( |
||||
|
{ baseHref = '/', routes = [], ...options } = {} as ABP.Test, |
||||
|
): ModuleWithProviders<CoreTestingModule> { |
||||
|
return { |
||||
|
ngModule: CoreTestingModule, |
||||
|
providers: [ |
||||
|
{ provide: APP_BASE_HREF, useValue: baseHref }, |
||||
|
{ |
||||
|
provide: 'CORE_OPTIONS', |
||||
|
useValue: options, |
||||
|
}, |
||||
|
{ |
||||
|
provide: CORE_OPTIONS, |
||||
|
useFactory: coreOptionsFactory, |
||||
|
deps: ['CORE_OPTIONS'], |
||||
|
}, |
||||
|
{ |
||||
|
provide: LocalizationPipe, |
||||
|
useClass: MockLocalizationPipe, |
||||
|
}, |
||||
|
provideRoutes(routes), |
||||
|
], |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
export * from './mock-localization.pipe'; |
||||
@ -0,0 +1,12 @@ |
|||||
|
import { Config } from '@abp/ng.core'; |
||||
|
import { Injectable, Pipe, PipeTransform } from '@angular/core'; |
||||
|
|
||||
|
@Injectable() |
||||
|
@Pipe({ |
||||
|
name: 'abpLocalization', |
||||
|
}) |
||||
|
export class MockLocalizationPipe implements PipeTransform { |
||||
|
transform(value: string | Config.LocalizationWithDefault = '', ..._: string[]) { |
||||
|
return typeof value === 'string' ? value : value.defaultValue; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,2 @@ |
|||||
|
export * from './lib/core-testing.module'; |
||||
|
export * from './lib/pipes'; |
||||
Loading…
Reference in new issue