From 9ed8dd90629b5b4402746cfd4bb73f63670c222e Mon Sep 17 00:00:00 2001 From: Martin Maul Date: Wed, 19 Jun 2024 11:55:10 +0200 Subject: [PATCH] feature(policy): #832 fix test --- .../services/policy-mock/policy.model.spec.ts | 3 --- .../services/policy-mock/policy.model.ts | 2 +- .../policy-editor/policy-editor.component.ts | 20 +++++++++++++++++-- .../page/policies/model/policy.model.ts | 9 --------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/mocks/services/policy-mock/policy.model.spec.ts b/frontend/src/app/mocks/services/policy-mock/policy.model.spec.ts index 6a283ea82f..9464ac37c4 100644 --- a/frontend/src/app/mocks/services/policy-mock/policy.model.spec.ts +++ b/frontend/src/app/mocks/services/policy-mock/policy.model.spec.ts @@ -25,7 +25,4 @@ describe('getOperatorTypeSign', () => { expect(getOperatorTypeSign(OperatorType.GTEQ)).toBe('>='); }); - it('should return the string representation of the type for unknown types', () => { - expect(getOperatorTypeSign('UNKNOWN' as OperatorType)).toBe('UNKNOWN'); - }); }); diff --git a/frontend/src/app/mocks/services/policy-mock/policy.model.ts b/frontend/src/app/mocks/services/policy-mock/policy.model.ts index 84e0a8f605..425305a663 100644 --- a/frontend/src/app/mocks/services/policy-mock/policy.model.ts +++ b/frontend/src/app/mocks/services/policy-mock/policy.model.ts @@ -140,7 +140,7 @@ const mockedPolicies = { { leftOperand: 'PURPOSE', operator: { - id: OperatorType.IN, + id: OperatorType.EQ, }, rightOperand: 'BMW', }, diff --git a/frontend/src/app/modules/page/admin/presentation/policy-management/policy-editor/policy-editor.component.ts b/frontend/src/app/modules/page/admin/presentation/policy-management/policy-editor/policy-editor.component.ts index 64a036ab06..729fa6bdab 100644 --- a/frontend/src/app/modules/page/admin/presentation/policy-management/policy-editor/policy-editor.component.ts +++ b/frontend/src/app/modules/page/admin/presentation/policy-management/policy-editor/policy-editor.component.ts @@ -1,5 +1,14 @@ import { Component } from '@angular/core'; -import { FormArray, FormBuilder, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms'; +import { + AbstractControl, + FormArray, + FormBuilder, + FormControl, + FormGroup, + ValidationErrors, + ValidatorFn, + Validators, +} from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { bpnListRegex, bpnRegex } from '@page/admin/presentation/bpn-configuration/bpn-configuration.component'; import { PoliciesFacade } from '@page/admin/presentation/policy-management/policies/policies.facade'; @@ -52,7 +61,7 @@ export class PolicyEditorComponent { this.policyForm = this.fb.group({ - policyName: new FormControl('', [ Validators.required, Validators.minLength(8), Validators.maxLength(40) ]), + policyName: new FormControl('', [ Validators.required, Validators.minLength(8), Validators.maxLength(40), this.noSpacesValidator() ]), validUntil: new FormControl('', [ Validators.required, this.futureDateValidator ]), bpns: new FormControl('', [ Validators.required, this.viewMode === ViewMode.CREATE ? BaseInputHelper.getCustomPatternValidator(bpnRegex, 'bpn') : BaseInputHelper.getCustomPatternValidator(bpnListRegex, 'bpn') ]), accessType: new FormControl(PolicyAction.ACCESS), @@ -317,6 +326,13 @@ export class PolicyEditorComponent { return null; }; + private noSpacesValidator(): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { + const hasSpaces = (control.value || '').includes(' '); + return hasSpaces ? { noSpaces: true } : null; + }; + } + protected readonly ViewMode = ViewMode; protected readonly OperatorTypesAsSelectOptionsList = OperatorTypesAsSelectOptionsList; diff --git a/frontend/src/app/modules/page/policies/model/policy.model.ts b/frontend/src/app/modules/page/policies/model/policy.model.ts index f173ced62b..fe81b16e8c 100644 --- a/frontend/src/app/modules/page/policies/model/policy.model.ts +++ b/frontend/src/app/modules/page/policies/model/policy.model.ts @@ -94,13 +94,6 @@ export enum OperatorType { GT = 'GT', LTEQ = 'LTEQ', GTEQ = 'GTEQ', - IN = 'IN', - ISA = 'ISA', - HASPART = 'HASPART', - ISPARTOF = 'ISPARTOF', - ISONEOF = 'ISONEOF', - ISALLOF = 'ISALLOF', - ISNONEOF = 'ISNONEOF', } const OperatorSignsToTypes: { [key: string]: OperatorType } = { @@ -132,8 +125,6 @@ export function getOperatorTypeSign(type: OperatorType): string { return '<='; case OperatorType.GTEQ: return '>='; - default: - return type.toString(); } }