Browse Source

pass validation options to theme shared testing

pull/6966/head
Arman Ozak 6 years ago
parent
commit
efad3b7b2e
  1. 27
      npm/ng-packs/packages/theme-shared/testing/src/lib/theme-shared-testing.module.ts

27
npm/ng-packs/packages/theme-shared/testing/src/lib/theme-shared-testing.module.ts

@ -1,11 +1,19 @@
import { import {
BaseThemeSharedModule, BaseThemeSharedModule,
DateParserFormatter, DateParserFormatter,
DEFAULT_VALIDATION_BLUEPRINTS,
THEME_SHARED_ROUTE_PROVIDERS, THEME_SHARED_ROUTE_PROVIDERS,
} from '@abp/ng.theme.shared'; } from '@abp/ng.theme.shared';
import { ModuleWithProviders, NgModule } from '@angular/core'; import { ModuleWithProviders, NgModule } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap'; import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap';
import {
defaultMapErrorsFn,
VALIDATION_BLUEPRINTS,
VALIDATION_MAP_ERRORS_FN,
VALIDATION_VALIDATE_ON_SUBMIT,
} from '@ngx-validate/core';
import { Config } from './models/config';
/** /**
* ThemeSharedTestingModule is the module that will be used in tests * ThemeSharedTestingModule is the module that will be used in tests
@ -15,12 +23,29 @@ import { NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap';
imports: [RouterTestingModule, BaseThemeSharedModule], imports: [RouterTestingModule, BaseThemeSharedModule],
}) })
export class ThemeSharedTestingModule { export class ThemeSharedTestingModule {
static withConfig(): ModuleWithProviders<ThemeSharedTestingModule> { static withConfig(
{ validation = {} } = {} as Config,
): ModuleWithProviders<ThemeSharedTestingModule> {
return { return {
ngModule: ThemeSharedTestingModule, ngModule: ThemeSharedTestingModule,
providers: [ providers: [
THEME_SHARED_ROUTE_PROVIDERS, THEME_SHARED_ROUTE_PROVIDERS,
{ provide: NgbDateParserFormatter, useClass: DateParserFormatter }, { provide: NgbDateParserFormatter, useClass: DateParserFormatter },
{
provide: VALIDATION_BLUEPRINTS,
useValue: {
...DEFAULT_VALIDATION_BLUEPRINTS,
...(validation.blueprints || {}),
},
},
{
provide: VALIDATION_MAP_ERRORS_FN,
useValue: validation.mapErrorsFn || defaultMapErrorsFn,
},
{
provide: VALIDATION_VALIDATE_ON_SUBMIT,
useValue: validation.validateOnSubmit,
},
], ],
}; };
} }

Loading…
Cancel
Save