diff --git a/frontend/cypress/e2e/check-in.cy.ts b/frontend/cypress/e2e/check-in.cy.ts index d84a31d487..e526bdef7b 100644 --- a/frontend/cypress/e2e/check-in.cy.ts +++ b/frontend/cypress/e2e/check-in.cy.ts @@ -156,7 +156,7 @@ describe('okr check-in', () => { .setCheckInConfidence(5) .submit(); - cy.contains('5%'); + cy.contains('Aktuell: 5%'); cy.contains('!'); cy.contains('5/10'); cy.contains('Letztes Check-in (' + getCurrentDate() + ')'); diff --git a/frontend/cypress/e2e/scoring.cy.ts b/frontend/cypress/e2e/scoring.cy.ts index 84330c3078..3e2a75deb2 100644 --- a/frontend/cypress/e2e/scoring.cy.ts +++ b/frontend/cypress/e2e/scoring.cy.ts @@ -42,6 +42,20 @@ describe('okr scoring', () => { 70, 100, 100 + ], + [ + 0, + -30, + -70, + -100, + -70 + ], + [ + 0, + -30, + -70, + -100, + -29.9 ] ].forEach(([ baseline, diff --git a/frontend/cypress/support/helper/scoringSupport.ts b/frontend/cypress/support/helper/scoringSupport.ts index b8bcba4a16..6fdaec5e62 100644 --- a/frontend/cypress/support/helper/scoringSupport.ts +++ b/frontend/cypress/support/helper/scoringSupport.ts @@ -158,37 +158,42 @@ function scoringValueFromPercentageOrdinal(percentage: number): ScoringValue { } function colorFromPercentageMetric(keyResult: CheckInValue) { - if (keyResult.lastCheckIn < keyResult.commitValue) { + const compare = createComparator(keyResult); + + if (compare(keyResult.lastCheckIn, keyResult.commitValue)) { return 'rgb(186, 56, 56)'; - } else if (keyResult.lastCheckIn < keyResult.targetValue) { + } else if (compare(keyResult.lastCheckIn, keyResult.targetValue)) { return 'rgb(255, 214, 0)'; - } else if (keyResult.lastCheckIn < keyResult.stretchGoal) { + } else if (compare(keyResult.lastCheckIn, keyResult.stretchGoal)) { return 'rgb(30, 138, 41)'; - } else if (keyResult.lastCheckIn >= keyResult.stretchGoal) { + } else { return 'rgba(0, 0, 0, 0)'; } } -function scoringValueFromPercentageMetric(keyResult: CheckInValue, percentage: number): ScoringValue { - if (keyResult.lastCheckIn < keyResult.commitValue) { +function scoringValueFromPercentageMetric(keyResult: CheckInValue, + percentage: number): ScoringValue { + const compare = createComparator(keyResult); + + if (compare(keyResult.lastCheckIn, keyResult.commitValue)) { return { failPercent: percentage * (100 / 30), commitPercent: -1, targetPercent: -1 }; - } else if (keyResult.lastCheckIn < keyResult.targetValue) { + } else if (compare(keyResult.lastCheckIn, keyResult.targetValue)) { return { failPercent: 100, commitPercent: (percentage - 30) * (100 / 40), targetPercent: -1 }; - } else if (keyResult.lastCheckIn < keyResult.stretchGoal) { + } else if (compare(keyResult.lastCheckIn, keyResult.stretchGoal)) { return { failPercent: 100, commitPercent: 100, targetPercent: (percentage - 70) * (100 / 30) }; - } else if (keyResult.lastCheckIn >= keyResult.stretchGoal) { + } else { return { failPercent: 0, commitPercent: 0, @@ -196,3 +201,13 @@ function scoringValueFromPercentageMetric(keyResult: CheckInValue, percentage: n }; } } + +function createComparator(keyResult: CheckInValue) { + const increasing = keyResult.baseline <= keyResult.stretchGoal; + return (a: number, b: number) => { + if (increasing) { + return a < b; + } + return a > b; + }; +} diff --git a/frontend/src/app/shared/custom/scoring/scoring.component.ts b/frontend/src/app/shared/custom/scoring/scoring.component.ts index 38422caa35..c51935b81a 100644 --- a/frontend/src/app/shared/custom/scoring/scoring.component.ts +++ b/frontend/src/app/shared/custom/scoring/scoring.component.ts @@ -105,19 +105,31 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { const keyResult = this.keyResult as KeyResultMetricMin; const lastCheckIn = keyResult.lastCheckIn?.value!; - if (lastCheckIn < keyResult.commitValue) { + // Decide comparison direction based on goal orientation + const increasing = keyResult.baseline <= keyResult.stretchGoal; + const compare = (a: number, b: number) => { + return increasing ? a < b : a > b; + }; + + if (compare(lastCheckIn, keyResult.commitValue)) { this.stretched = false; - this.failPercent = (lastCheckIn - keyResult.baseline) / (keyResult.commitValue - keyResult.baseline) * 100; - } else if (lastCheckIn < keyResult.targetValue) { + this.failPercent = + (lastCheckIn - keyResult.baseline) / + (keyResult.commitValue - keyResult.baseline) * 100; + } else if (compare(lastCheckIn, keyResult.targetValue)) { this.stretched = false; this.failPercent = 100; - this.commitPercent = (lastCheckIn - keyResult.commitValue) / (keyResult.targetValue - keyResult.commitValue) * 100; - } else if (lastCheckIn < keyResult.stretchGoal) { + this.commitPercent = + (lastCheckIn - keyResult.commitValue) / + (keyResult.targetValue - keyResult.commitValue) * 100; + } else if (compare(lastCheckIn, keyResult.stretchGoal)) { this.stretched = false; this.failPercent = 100; this.commitPercent = 100; - this.targetPercent = (lastCheckIn - keyResult.targetValue) / (keyResult.stretchGoal - keyResult.targetValue) * 100; - } else if (lastCheckIn >= keyResult.stretchGoal) { + this.targetPercent = + (lastCheckIn - keyResult.targetValue) / + (keyResult.stretchGoal - keyResult.targetValue) * 100; + } else { this.stretched = true; } }