From f2d53cde2acb1eae5ecaa7bab070cf48d5d5be53 Mon Sep 17 00:00:00 2001 From: Jannik Pulfer Date: Wed, 22 Jan 2025 15:47:35 +0100 Subject: [PATCH] Allow white spaces at start and end of number and write e2e tests to see if error message is shown --- frontend/cypress/e2e/check-in.cy.ts | 22 +++++++++++++++++++ .../check-in-form-metric.component.spec.ts | 8 +++++-- .../check-in-form-metric.component.ts | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/frontend/cypress/e2e/check-in.cy.ts b/frontend/cypress/e2e/check-in.cy.ts index f5505ccdef..cfc90eb06b 100644 --- a/frontend/cypress/e2e/check-in.cy.ts +++ b/frontend/cypress/e2e/check-in.cy.ts @@ -44,6 +44,28 @@ describe('okr check-in', () => { cy.contains('- A new action on the action-plan'); }); + it('should show an error message when new check-in value is not numeric', () => { + overviewPage + .addKeyResult() + .fillKeyResultTitle('This key-result will have errors') + .withMetricValues(Unit.NUMBER, '21', '51') + .submit(); + + const detailPage = keyResultDetailPage + .visit('Very important keyresult') + .createCheckIn() + .fillMetricCheckInValue('asdf'); + cy.contains('Neuer Wert muss eine Zahl sein.'); + + detailPage.fillMetricCheckInValue('21. 2'); + cy.contains('Neuer Wert muss eine Zahl sein.'); + + detailPage.fillMetricCheckInValue('123'); + cy.contains('Neuer Wert muss eine Zahl sein.') + .should('not.exist'); + }); + + it('should create check-in metric and assert correct owner', () => { overviewPage .addKeyResult() diff --git a/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.spec.ts b/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.spec.ts index a9d65aed69..953c7dd9c6 100644 --- a/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.spec.ts +++ b/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.spec.ts @@ -96,10 +96,14 @@ describe('CheckInFormComponent', () => { true], [-100.3, true], - ['123', + [' 123 ', true], - ['-123.4', + [' -123.4 ', true], + ['12 .3', + false], + ['1 2', + false], ['', false], ['asdf', diff --git a/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.ts b/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.ts index cdffb73982..763c5ad750 100644 --- a/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.ts +++ b/frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.ts @@ -30,7 +30,7 @@ export class CheckInFormMetricComponent implements OnInit { ngOnInit() { this.dialogForm.controls['value'].setValidators([Validators.required, - Validators.pattern('^-?\\d+\\.?\\d*$')]); + Validators.pattern('^\\s*-?\\d+\\.?\\d*\\s*$')]); } generateUnitLabel(): string {