All files / src/app/shared/formly-address-forms/configurations address-form-configuration.provider.ts

92.3% Statements 12/13
50% Branches 4/8
100% Functions 4/4
91.66% Lines 11/12

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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 403x   3x       3x             3x   4x                     5x 5x     5x 5x 5x       6x      
import { Inject, Injectable, InjectionToken } from '@angular/core';
 
import { InjectMultiple } from 'ish-core/utils/injection';
 
import { AddressFormConfiguration } from './address-form.configuration';
 
export const ADDRESS_FORM_CONFIGURATION = new InjectionToken<AddressFormConfiguration>('Address Form Factory');
 
/*
 * Service that collects address configurations from the module
 * and provides correctly configured `AddressFormConfiguration` objects
 */
@Injectable()
export class AddressFormConfigurationProvider {
  constructor(
    @Inject(ADDRESS_FORM_CONFIGURATION) private configurations: InjectMultiple<typeof ADDRESS_FORM_CONFIGURATION>
  ) {}
 
  /**
   * gets the appropriate address configuration for the given countryCode and configuration
   */
  getConfiguration(
    countryCode: string = '',
    businessCustomer: boolean = false,
    shortForm: boolean = false
  ): AddressFormConfiguration {
    let configuration = this.findConfiguration(countryCode);
    Iif (!configuration) {
      configuration = this.findConfiguration('');
    }
    configuration.businessCustomer = businessCustomer;
    configuration.shortForm = shortForm;
    return configuration;
  }
 
  private findConfiguration(countryCode: string): AddressFormConfiguration {
    return this.configurations.find(f => f.countryCode === countryCode);
  }
}