All files / form si-form-validation-error.provider.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                            1x   18x     6x    
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Provider } from '@angular/core';
import { TranslatableString } from '@siemens/element-translate-ng/translate';
 
import { SiFormValidationErrorMapper } from './si-form-validation-error.model';
import { buildDefaults, SiFormValidationErrorService } from './si-form-validation-error.service';
 
/**
 * The error mapper is used to resolve an angular validation error to a {@link TranslatableString}.
 * It will be merged with already existing error mappers.
 */
export const provideFormValidationErrorMapper = (
  mapper: SiFormValidationErrorMapper
): Provider => ({
  provide: SiFormValidationErrorService,
  // defaults must always be provided in case this is called in app.config
  useFactory: () => new SiFormValidationErrorService({ ...buildDefaults(), ...mapper })
});