Skip to content
Snippets Groups Projects
Select Git revision
  • OZG-8168-replace-remaining-mat-icon
  • OZG-7983-Statistik-Land-kann-Anfrage-an-Mandanten-veröffentlichen
  • main default protected
  • release-info
  • release-administration
  • release
  • OZG-8086-Datenanfrage-E2E
  • OZG-8086-Admin-Datenanfrage-erstellen
  • OZG-8086-Datenanfrage-Umbenennung
  • OZG-6220-Bescheid-speichern-ohne-Postfach
  • OZG-6123-Vorgänge-aus-Suche-E2E
  • OZG-7983-OZG-8244-Statistik-Datenanfrage-veröffentlichen
  • OZG-7985-Statistik-Datenfreigabe
  • OZG-7922-KeycloakOperatorExceptions
  • OZG-8142-poc-cards
  • OZG-8086-E2E
  • OZG-8086-E2E2
  • OZG-8142-ProjectionStuff
  • OZG-8086-Statistik-Datenanfrage-erstellen
  • OZG-7856_schadcode_scanner
  • 1.10.0-info
  • 1.10.0-administration
  • 2.25.0-alfa
  • 1.9.0-info
  • 1.9.0-administration
  • 2.24.0-alfa
  • 1.8.0-info
  • 1.8.0-administration
  • 2.23.0-alfa
  • 1.7.0-info
  • 1.7.0-administration
  • 2.22.0-alfa
  • 1.6.0-info
  • 1.6.0-administration
  • 2.21.0-alfa
  • 1.5.0-info
  • 1.5.0-administration
  • 2.20.0-alfa
  • 2.19.2-alfa
  • 2.19.1-alfa
40 results

tech.validation.util.spec.ts

Blame
  • tech.validation.util.spec.ts 4.88 KiB
    /*
     * Copyright (C) 2022 Das Land Schleswig-Holstein vertreten durch den
     * Ministerpräsidenten des Landes Schleswig-Holstein
     * Staatskanzlei
     * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung
     *
     * Lizenziert unter der EUPL, Version 1.2 oder - sobald
     * diese von der Europäischen Kommission genehmigt wurden -
     * Folgeversionen der EUPL ("Lizenz");
     * Sie dürfen dieses Werk ausschließlich gemäß
     * dieser Lizenz nutzen.
     * Eine Kopie der Lizenz finden Sie hier:
     *
     * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
     *
     * Sofern nicht durch anwendbare Rechtsvorschriften
     * gefordert oder in schriftlicher Form vereinbart, wird
     * die unter der Lizenz verbreitete Software "so wie sie
     * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN -
     * ausdrücklich oder stillschweigend - verbreitet.
     * Die sprachspezifischen Genehmigungen und Beschränkungen
     * unter der Lizenz sind dem Lizenztext zu entnehmen.
     */
    import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
    import { createIssue } from '../../../test/error';
    import { Issue } from '../tech.model';
    import {
      getControlForIssue,
      getMessageForInvalidParamsItem,
      getMessageForIssue,
      setValidationError,
    } from './tech.validation.util';
    import { ValidationMessageCode } from './tech.validation.messages';
    import { InvalidParamsItem } from '../../../../admin-settings/src/lib/error/error.model';
    
    describe('ValidationUtils', () => {
      describe('setValidationError', () => {
        const baseField1Control = new UntypedFormControl();
        const baseField2Control = new UntypedFormControl();
        const subGroupFieldControl = new UntypedFormControl();
    
        const form = new UntypedFormGroup({
          baseField1: baseField1Control,
          baseField2: baseField2Control,
          subGroup: new UntypedFormGroup({
            subGroupField1: subGroupFieldControl,
          }),
        });
    
        describe('get control for issue', () => {
          it('should return base field control', () => {
            const issue: Issue = { ...createIssue(), field: 'baseField1' };
    
            const control = getControlForIssue(form, issue);
    
            expect(control).toBe(baseField1Control);
          });
    
          it('should reeturn sub group field', () => {
            const issue: Issue = { ...createIssue(), field: 'subGroup.subGroupField1' };
    
            const control = getControlForIssue(form, issue);
    
            expect(control).toBe(subGroupFieldControl);
          });
    
          it('should ignore path prefix', () => {
            const issue: Issue = { ...createIssue(), field: 'command.wiedervorlage.baseField1' };
    
            const control = getControlForIssue(form, issue, 'command.wiedervorlage');
    
            expect(control).toBe(baseField1Control);
          });
        });
    
        describe('in base field', () => {
          const issue: Issue = { ...createIssue(), field: 'baseField1' };
    
          it('should set error in control', () => {
            setValidationError(form, issue);
    
            expect(baseField1Control.errors).not.toBeNull();
          });
    
          it('should set message code in control', () => {
            setValidationError(form, issue);
    
            expect(baseField1Control.hasError(issue.messageCode)).toBe(true);
          });
    
          it('should set control touched', () => {
            setValidationError(form, issue);
    
            expect(baseField1Control.touched).toBe(true);
          });
    
          it('should not set error in other control', () => {
            setValidationError(form, issue);
    
            expect(baseField2Control.errors).toBeNull();
          });
        });
    
        describe('in subGroup Field', () => {
          const issue: Issue = { ...createIssue(), field: 'subGroup.subGroupField1' };
    
          it('should set error in control', () => {
            setValidationError(form, issue);
    
            expect(subGroupFieldControl.errors).not.toBeNull();
          });
        });
      });
    
      describe('get message for issue', () => {
        const fieldLabel = 'Field Label';
    
        it('should return message', () => {
          const msg = getMessageForIssue(fieldLabel, {
            ...createIssue(),
            messageCode: 'validation_field_size',
          });
    
          expect(msg).toContain('muss mindestens');
        });
    
        it('should set field label', () => {
          const msg = getMessageForIssue(fieldLabel, {
            ...createIssue(),
            messageCode: 'validation_field_size',
          });
    
          expect(msg).toContain(fieldLabel);
        });
    
        it('should replace min param', () => {
          const msg = getMessageForIssue(fieldLabel, {
            ...createIssue(),
            messageCode: 'validation_field_size',
            parameters: [{ name: 'min', value: '3' }],
          });
    
          expect(msg).toContain('3');
        });
      });
    
      describe('get message for invalid-params-item', () => {
        const item: InvalidParamsItem = {
          name: 'name-of-field',
          reason: ValidationMessageCode.VALIDATION_FIELD_EMPTY,
        };
    
        it('should return message', () => {
          const msg = getMessageForInvalidParamsItem(item);
    
          expect(msg).toEqual(`Bitte ${item.name} ausfüllen`);
        });
      });
    });