From bb7770bc84ee1160dcccae8d31a89ce7b5763b20 Mon Sep 17 00:00:00 2001 From: Lias Kleisa Date: Thu, 30 Nov 2023 10:33:05 +0100 Subject: [PATCH 1/5] Add check for lastCheckIn in scoring component --- .../src/app/shared/custom/scoring/scoring.component.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/shared/custom/scoring/scoring.component.ts b/frontend/src/app/shared/custom/scoring/scoring.component.ts index 3d892121dc..5403dc1005 100644 --- a/frontend/src/app/shared/custom/scoring/scoring.component.ts +++ b/frontend/src/app/shared/custom/scoring/scoring.component.ts @@ -46,10 +46,12 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } ngOnInit() { - if (this.keyResult.keyResultType === 'metric') { - this.calculatePercentageMetric(); - } else { - this.calculatePercentageOrdinal(); + if (this.keyResult.lastCheckIn) { + if (this.keyResult.keyResultType === 'metric') { + this.calculatePercentageMetric(); + } else { + this.calculatePercentageOrdinal(); + } } } From 2dfd11b9cc73cf9cd0ae4088de42da04e317f097 Mon Sep 17 00:00:00 2001 From: Lias Kleisa Date: Mon, 4 Dec 2023 11:15:39 +0100 Subject: [PATCH 2/5] Fix bug with stretch --- .../custom/scoring/scoring.component.ts | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/frontend/src/app/shared/custom/scoring/scoring.component.ts b/frontend/src/app/shared/custom/scoring/scoring.component.ts index 5403dc1005..84ca0999ac 100644 --- a/frontend/src/app/shared/custom/scoring/scoring.component.ts +++ b/frontend/src/app/shared/custom/scoring/scoring.component.ts @@ -46,6 +46,7 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } ngOnInit() { + this.stretched = false; if (this.keyResult.lastCheckIn) { if (this.keyResult.keyResultType === 'metric') { this.calculatePercentageMetric(); @@ -55,6 +56,36 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } } + ngAfterViewInit(): void { + if (this.keyResult.lastCheckIn) { + //Define width of scoring elements + this.failElement!.nativeElement.style.width = this.failPercent + '%'; + this.commitElement!.nativeElement.style.width = this.commitPercent + '%'; + this.targetElement!.nativeElement.style.width = this.targetPercent + '%'; + + if (this.valueLabel != undefined && this.keyResult.keyResultType == 'metric') { + this.labelPercentage.subscribe((value) => { + this.valueLabel!.nativeElement.style.width = value + '%'; + this.changeDetectionRef.detectChanges(); + }); + } + + // Set color of scoring component + let scoringClass = this.getScoringColorClassAndSetBorder(); + if (scoringClass !== null) { + this.targetElement!.nativeElement.classList.add(scoringClass); + this.commitElement!.nativeElement.classList.add(scoringClass); + this.failElement!.nativeElement.classList.add(scoringClass); + } + + //Fill out icon if target percent has reached 100 percent or more + if (this.stretched) { + this.iconPath = 'filled'; + this.changeDetectionRef.detectChanges(); + } + } + } + calculatePercentageOrdinal() { switch (this.keyResult.lastCheckIn?.value) { case Zone.STRETCH: @@ -79,48 +110,45 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } calculatePercentageMetric() { - if (this.keyResult.lastCheckIn !== null) { - let KeyResultMetric: KeyResultMetricMin = this.castToMetric(); - - let percentage = calculateCurrentPercentage(KeyResultMetric); - this.labelPercentage = of(percentage); - switch (true) { - case percentage >= 100: - this.stretched = true; - break; - case percentage > 70: - this.stretched = false; - this.failPercent = 100; - this.commitPercent = 100; - this.targetPercent = (100 / 30) * (percentage - 70); - break; - case percentage > 30: - this.stretched = false; - this.failPercent = 100; - this.commitPercent = (100 / 40) * (percentage - 30); - break; - default: - this.stretched = false; - this.failPercent = (100 / 30) * percentage; - } + let KeyResultMetric: KeyResultMetricMin = this.castToMetric(); + + let percentage = calculateCurrentPercentage(KeyResultMetric); + this.labelPercentage = of(percentage); + switch (true) { + case percentage >= 100: + this.stretched = true; + break; + case percentage > 70: + this.stretched = false; + this.failPercent = 100; + this.commitPercent = 100; + this.targetPercent = (100 / 30) * (percentage - 70); + break; + case percentage > 30: + this.stretched = false; + this.failPercent = 100; + this.commitPercent = (100 / 40) * (percentage - 30); + break; + default: + this.stretched = false; + this.failPercent = (100 / 30) * percentage; } } getScoringColorClassAndSetBorder(): string | null { - switch (true) { - case this.targetPercent > 100: - return 'score-stretch'; - case this.targetPercent > 0: - this.setBorder(this.targetElement!); - return 'score-green'; - case this.commitPercent > 0: - this.setBorder(this.commitElement!); - return 'score-yellow'; - case this.failPercent > 0: - this.setBorder(this.failElement!); - return 'score-red'; - default: - return null; + if (this.targetPercent > 100) { + return 'score-stretch'; + } else if (this.targetPercent > 0) { + this.setBorder(this.targetElement!); + return 'score-green'; + } else if (this.commitPercent > 0) { + this.setBorder(this.commitElement!); + return 'score-yellow'; + } else if (this.failPercent > 0) { + this.setBorder(this.failElement!); + return 'score-red'; + } else { + return null; } } @@ -130,34 +158,6 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } } - ngAfterViewInit(): void { - //Define width of scoring elements - this.failElement!.nativeElement.style.width = this.failPercent + '%'; - this.commitElement!.nativeElement.style.width = this.commitPercent + '%'; - this.targetElement!.nativeElement.style.width = this.targetPercent + '%'; - - if (this.valueLabel != undefined && this.keyResult.keyResultType == 'metric') { - this.labelPercentage.subscribe((value) => { - this.valueLabel!.nativeElement.style.width = value + '%'; - this.changeDetectionRef.detectChanges(); - }); - } - - // Set color of scoring component - let scoringClass = this.getScoringColorClassAndSetBorder(); - if (scoringClass !== null) { - this.targetElement!.nativeElement.classList.add(scoringClass); - this.commitElement!.nativeElement.classList.add(scoringClass); - this.failElement!.nativeElement.classList.add(scoringClass); - } - - //Fill out icon if target percent has reached 100 percent or more - if (this.stretched) { - this.iconPath = 'filled'; - this.changeDetectionRef.detectChanges(); - } - } - ngOnChanges(changes: SimpleChanges): void { if (changes['keyResult']?.currentValue !== undefined || changes['keyResult']?.currentValue !== null) { if (this.commitElement != undefined) { From 3d0ac14ab78aa44ba7fd6484936c186ffd2bedd1 Mon Sep 17 00:00:00 2001 From: Lias Kleisa Date: Mon, 4 Dec 2023 13:06:22 +0100 Subject: [PATCH 3/5] Add e2e test for duplicating scoring objective --- frontend/cypress/e2e/duplicated-scoring.cy.ts | 54 +++++++++++++++++++ .../app/keyresult/keyresult.component.html | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 frontend/cypress/e2e/duplicated-scoring.cy.ts diff --git a/frontend/cypress/e2e/duplicated-scoring.cy.ts b/frontend/cypress/e2e/duplicated-scoring.cy.ts new file mode 100644 index 0000000000..d1152ced59 --- /dev/null +++ b/frontend/cypress/e2e/duplicated-scoring.cy.ts @@ -0,0 +1,54 @@ +import * as users from '../fixtures/users.json'; +import { onlyOn } from '@cypress/skip-test'; + +describe('e2e test for scoring adjustment on objective duplicate', () => { + beforeEach(() => { + cy.loginAsUser(users.gl); + onlyOn('chrome'); + cy.visit('/?quarter=2'); + }); + + it('Create ordinal checkin and validate value of scoring component', () => { + cy.createOrdinalKeyresult('stretch keyresult for testing', null); + cy.getByTestId('keyresult').get(':contains("stretch keyresult for testing")').last().click(); + cy.getByTestId('add-check-in').click(); + cy.getByTestId(`stretch-radio`).click(); + cy.getByTestId('confidence-slider').click(); + cy.realPress('{rightarrow}').realPress('{rightarrow}').realPress('{rightarrow}'); + cy.getByTestId('changeInfo').click().type('Testveränderungen'); + cy.getByTestId('initiatives').click().type('Testmassnahmen'); + cy.getByTestId('submit-check-in').click(); + cy.getByTestId('close-drawer').click({ force: true }); + + cy.get('.objective').first().getByTestId('three-dot-menu').click(); + cy.get('.mat-mdc-menu-content').contains('Objective duplizieren').click(); + cy.fillOutObjective('A duplicated Objective for this tool', 'safe', '3'); + cy.visit('/?quarter=3'); + + let scoringBlock1 = cy + .getByTestId('objective') + .first() + .getByTestId('key-result') + .first() + .getByTestId('scoring-component') + .first(); + + scoringBlock1.getByTestId('fail').first().should('not.have.css', 'score-red'); + scoringBlock1.getByTestId('fail').first().should('not.have.css', 'score-yellow'); + scoringBlock1.getByTestId('fail').first().should('not.have.css', 'score-green'); + scoringBlock1.getByTestId('fail').first().should('not.have.css', 'score-stretch'); + + let scoringBlock2 = cy + .getByTestId('objective') + .first() + .getByTestId('key-result') + .last() + .getByTestId('scoring-component') + .last(); + + scoringBlock2.getByTestId('fail').first().should('not.have.css', 'score-red'); + scoringBlock2.getByTestId('fail').first().should('not.have.css', 'score-yellow'); + scoringBlock2.getByTestId('fail').first().should('not.have.css', 'score-green'); + scoringBlock2.getByTestId('fail').first().should('not.have.css', 'score-stretch'); + }); +}); diff --git a/frontend/src/app/keyresult/keyresult.component.html b/frontend/src/app/keyresult/keyresult.component.html index a52e9097f3..74a2991bbb 100644 --- a/frontend/src/app/keyresult/keyresult.component.html +++ b/frontend/src/app/keyresult/keyresult.component.html @@ -6,7 +6,7 @@ tabindex="0" >
{{ keyResult.title }}
- +
From a985fdb4905ba881bc033e577517042bc4091277 Mon Sep 17 00:00:00 2001 From: Kleser <68543649+lkleisa@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:23:40 +0100 Subject: [PATCH 4/5] Update scoring.component.ts --- .../custom/scoring/scoring.component.ts | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/frontend/src/app/shared/custom/scoring/scoring.component.ts b/frontend/src/app/shared/custom/scoring/scoring.component.ts index 84ca0999ac..49cec78624 100644 --- a/frontend/src/app/shared/custom/scoring/scoring.component.ts +++ b/frontend/src/app/shared/custom/scoring/scoring.component.ts @@ -110,28 +110,30 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } calculatePercentageMetric() { - let KeyResultMetric: KeyResultMetricMin = this.castToMetric(); - - let percentage = calculateCurrentPercentage(KeyResultMetric); - this.labelPercentage = of(percentage); - switch (true) { - case percentage >= 100: - this.stretched = true; - break; - case percentage > 70: - this.stretched = false; - this.failPercent = 100; - this.commitPercent = 100; - this.targetPercent = (100 / 30) * (percentage - 70); - break; - case percentage > 30: - this.stretched = false; - this.failPercent = 100; - this.commitPercent = (100 / 40) * (percentage - 30); - break; - default: - this.stretched = false; - this.failPercent = (100 / 30) * percentage; + if (this.keyResult.lastCheckIn !== null) { + let keyResultMetric: KeyResultMetricMin = this.castToMetric(); + + let percentage = calculateCurrentPercentage(keyResultMetric); + this.labelPercentage = of(percentage); + switch (true) { + case percentage >= 100: + this.stretched = true; + break; + case percentage > 70: + this.stretched = false; + this.failPercent = 100; + this.commitPercent = 100; + this.targetPercent = (100 / 30) * (percentage - 70); + break; + case percentage > 30: + this.stretched = false; + this.failPercent = 100; + this.commitPercent = (100 / 40) * (percentage - 30); + break; + default: + this.stretched = false; + this.failPercent = (100 / 30) * percentage; + } } } From 2829e06a21a34515f00535fcf174e73f2fccce8f Mon Sep 17 00:00:00 2001 From: Lias Kleisa Date: Mon, 4 Dec 2023 13:41:11 +0100 Subject: [PATCH 5/5] Remove unused check --- .../custom/scoring/scoring.component.ts | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/shared/custom/scoring/scoring.component.ts b/frontend/src/app/shared/custom/scoring/scoring.component.ts index 49cec78624..d7464e4ce7 100644 --- a/frontend/src/app/shared/custom/scoring/scoring.component.ts +++ b/frontend/src/app/shared/custom/scoring/scoring.component.ts @@ -57,32 +57,30 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges { } ngAfterViewInit(): void { - if (this.keyResult.lastCheckIn) { - //Define width of scoring elements - this.failElement!.nativeElement.style.width = this.failPercent + '%'; - this.commitElement!.nativeElement.style.width = this.commitPercent + '%'; - this.targetElement!.nativeElement.style.width = this.targetPercent + '%'; - - if (this.valueLabel != undefined && this.keyResult.keyResultType == 'metric') { - this.labelPercentage.subscribe((value) => { - this.valueLabel!.nativeElement.style.width = value + '%'; - this.changeDetectionRef.detectChanges(); - }); - } + //Define width of scoring elements + this.failElement!.nativeElement.style.width = this.failPercent + '%'; + this.commitElement!.nativeElement.style.width = this.commitPercent + '%'; + this.targetElement!.nativeElement.style.width = this.targetPercent + '%'; + + if (this.valueLabel != undefined && this.keyResult.keyResultType == 'metric') { + this.labelPercentage.subscribe((value) => { + this.valueLabel!.nativeElement.style.width = value + '%'; + this.changeDetectionRef.detectChanges(); + }); + } - // Set color of scoring component - let scoringClass = this.getScoringColorClassAndSetBorder(); - if (scoringClass !== null) { - this.targetElement!.nativeElement.classList.add(scoringClass); - this.commitElement!.nativeElement.classList.add(scoringClass); - this.failElement!.nativeElement.classList.add(scoringClass); - } + // Set color of scoring component + let scoringClass = this.getScoringColorClassAndSetBorder(); + if (scoringClass !== null) { + this.targetElement!.nativeElement.classList.add(scoringClass); + this.commitElement!.nativeElement.classList.add(scoringClass); + this.failElement!.nativeElement.classList.add(scoringClass); + } - //Fill out icon if target percent has reached 100 percent or more - if (this.stretched) { - this.iconPath = 'filled'; - this.changeDetectionRef.detectChanges(); - } + //Fill out icon if target percent has reached 100 percent or more + if (this.stretched) { + this.iconPath = 'filled'; + this.changeDetectionRef.detectChanges(); } }