From 55ae3f8f7a1ea8b41422f88a2c88651a74892963 Mon Sep 17 00:00:00 2001 From: Prokop Simek Date: Thu, 28 Nov 2019 14:53:03 +0100 Subject: [PATCH] fix(practices): unify impact and defaultImpact to impact and overridenImpact --- src/model.ts | 1 - src/reporters/CLIReporter.spec.ts | 10 +++++----- src/reporters/CLIReporter.ts | 12 +++++++----- src/reporters/IReporter.ts | 2 +- src/reporters/ReporterUtils.spec.ts | 2 +- src/scanner/Scanner.ts | 2 +- src/scanner/ScannerUtils.ts | 6 +++--- test/factories/PracticeWithContextFactory.ts | 2 +- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/model.ts b/src/model.ts index b64713c6e..505973724 100644 --- a/src/model.ts +++ b/src/model.ts @@ -92,7 +92,6 @@ export interface DeprecatedProjectComponent { } export interface PracticeMetadata { - defaultImpact?: PracticeImpact; id: string; name: string; suggestion: string; diff --git a/src/reporters/CLIReporter.spec.ts b/src/reporters/CLIReporter.spec.ts index 0f96aa8c9..948080c8c 100644 --- a/src/reporters/CLIReporter.spec.ts +++ b/src/reporters/CLIReporter.spec.ts @@ -24,23 +24,23 @@ describe('CLIReporter', () => { practicingHighImpactPracticeWithCtx, notPracticingHighImpactPracticeWithCtx, practiceWithContextFactory({ - impact: PracticeImpact.medium, + overridenImpact: PracticeImpact.medium, evaluation: PracticeEvaluationResult.notPracticing, }), practiceWithContextFactory({ - impact: PracticeImpact.small, + overridenImpact: PracticeImpact.small, evaluation: PracticeEvaluationResult.notPracticing, }), practiceWithContextFactory({ - impact: PracticeImpact.hint, + overridenImpact: PracticeImpact.hint, evaluation: PracticeEvaluationResult.notPracticing, }), practiceWithContextFactory({ - impact: PracticeImpact.off, + overridenImpact: PracticeImpact.off, evaluation: PracticeEvaluationResult.notPracticing, isOn: false, }), - practiceWithContextFactory({ impact: PracticeImpact.high, evaluation: PracticeEvaluationResult.unknown }), + practiceWithContextFactory({ overridenImpact: PracticeImpact.high, evaluation: PracticeEvaluationResult.unknown }), ]); expect(result).toContain('Improvements with highest impact'); diff --git a/src/reporters/CLIReporter.ts b/src/reporters/CLIReporter.ts index 6cec9c778..198c4cc7a 100644 --- a/src/reporters/CLIReporter.ts +++ b/src/reporters/CLIReporter.ts @@ -81,7 +81,7 @@ export class CLIReporter implements IReporter { const lines: string[] = []; const practices = practicesAndComponents.filter( - (p) => p.impact === impact && p.isOn === true && p.evaluation === PracticeEvaluationResult.notPracticing, + (p) => p.overridenImpact === impact && p.isOn === true && p.evaluation === PracticeEvaluationResult.notPracticing, ); if (practices.length === 0) return undefined; @@ -108,8 +108,8 @@ export class CLIReporter implements IReporter { for (const practiceWithContext of practices) { lines.push(this.linesForPractice(practiceWithContext.practice, color)); - if (practiceWithContext.practice.defaultImpact !== practiceWithContext.practice.impact) { - lines.push(bold(this.changedImpact(practiceWithContext.practice, (color = grey)))); + if (practiceWithContext.practice.impact !== practiceWithContext.overridenImpact) { + lines.push(bold(this.changedImpact(practiceWithContext, (color = grey)))); } } @@ -127,11 +127,13 @@ export class CLIReporter implements IReporter { return practiceLineTexts.join(' '); } - private changedImpact(practice: PracticeMetadata, color: Color) { + private changedImpact(practiceWithContext: PracticeWithContextForReporter, color: Color) { const practiceLineTexts = [ reset( color( - `You changed impact of ${bold(practice.name)} from ${underline(practice.defaultImpact)} to ${underline(practice.impact)}`, + ` You changed impact of ${bold(practiceWithContext.practice.name)} from ${underline( + practiceWithContext.practice.impact, + )} to ${underline(practiceWithContext.overridenImpact)}.`, ), ), ]; diff --git a/src/reporters/IReporter.ts b/src/reporters/IReporter.ts index 163177bfa..7f5313e05 100644 --- a/src/reporters/IReporter.ts +++ b/src/reporters/IReporter.ts @@ -23,7 +23,7 @@ export interface ComponentReport extends ProjectComponent { export interface PracticeWithContextForReporter { component: ProjectComponent; practice: PracticeMetadata; - impact: PracticeImpact; + overridenImpact: PracticeImpact; evaluation: PracticeEvaluationResult; isOn: boolean; } diff --git a/src/reporters/ReporterUtils.spec.ts b/src/reporters/ReporterUtils.spec.ts index 2134fb5c6..7cf963b7b 100644 --- a/src/reporters/ReporterUtils.spec.ts +++ b/src/reporters/ReporterUtils.spec.ts @@ -26,7 +26,7 @@ describe('ReporterUtils', () => { }); it('one practicing practice and one skipped practicing', () => { - notPracticingHighImpactPracticeWithCtx.impact = PracticeImpact.off; + notPracticingHighImpactPracticeWithCtx.overridenImpact = PracticeImpact.off; notPracticingHighImpactPracticeWithCtx.isOn = false; const result = ReporterUtils.computeDXScore([practicingHighImpactPracticeWithCtx, notPracticingHighImpactPracticeWithCtx]); diff --git a/src/scanner/Scanner.ts b/src/scanner/Scanner.ts index c1ba07911..efe87e89e 100644 --- a/src/scanner/Scanner.ts +++ b/src/scanner/Scanner.ts @@ -184,7 +184,7 @@ export class Scanner { component: p.componentContext.projectComponent, practice: p.practice.getMetadata(), evaluation: p.evaluation, - impact: (overridenImpact ? overridenImpact : p.practice.getMetadata().impact), + overridenImpact: (overridenImpact ? overridenImpact : p.practice.getMetadata().impact), isOn: p.isOn, }; }); diff --git a/src/scanner/ScannerUtils.ts b/src/scanner/ScannerUtils.ts index e4ba071ae..45f15c38c 100644 --- a/src/scanner/ScannerUtils.ts +++ b/src/scanner/ScannerUtils.ts @@ -128,9 +128,9 @@ export class ScannerUtils { argumentsProvider: ArgumentsProvider, ) => { return relevantPractices.filter( - (practice) => - practice.evaluation === PracticeEvaluationResult.notPracticing && - (_.includes(ScannerUtils.getImpactFailureLevels(argumentsProvider.fail), practice.impact) || argumentsProvider.fail === 'all'), + (pctx) => + pctx.evaluation === PracticeEvaluationResult.notPracticing && + (_.includes(ScannerUtils.getImpactFailureLevels(argumentsProvider.fail), pctx.overridenImpact) || argumentsProvider.fail === 'all'), ); }; } diff --git a/test/factories/PracticeWithContextFactory.ts b/test/factories/PracticeWithContextFactory.ts index d33ac6546..f89f2e06a 100644 --- a/test/factories/PracticeWithContextFactory.ts +++ b/test/factories/PracticeWithContextFactory.ts @@ -31,7 +31,7 @@ export const practiceWithContextFactory = ( impact: PracticeImpact.high, url: '.', }, - impact: PracticeImpact.high, + overridenImpact: PracticeImpact.high, evaluation: PracticeEvaluationResult.practicing, isOn: true, },