From fe8308da1fa7b48c90721e06d57e7d68b8e380ef Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Thu, 12 Dec 2024 12:00:08 +0100 Subject: [PATCH] feat: productivity email action text (#8966) --- .../ProjectSetupComplete.tsx | 4 +- package.json | 2 +- .../productivity-report-view-model.test.ts | 75 +++++++++++++++++++ .../productivity-report-view-model.ts | 12 +++ src/lib/services/email-service.test.ts | 14 ++-- .../productivity-report.html.mustache | 3 +- yarn.lock | 10 +-- 7 files changed, 104 insertions(+), 16 deletions(-) diff --git a/frontend/src/component/personalDashboard/ProjectSetupComplete.tsx b/frontend/src/component/personalDashboard/ProjectSetupComplete.tsx index db8be8b7ee75..2ac7092fe425 100644 --- a/frontend/src/component/personalDashboard/ProjectSetupComplete.tsx +++ b/frontend/src/component/personalDashboard/ProjectSetupComplete.tsx @@ -100,7 +100,7 @@ const ProjectHealthMessage: FC<{ during the last 4 weeks. - {avgHealthCurrentWindow && avgHealthCurrentWindow >= 70 + {avgHealthCurrentWindow && avgHealthCurrentWindow >= 75 ? keepDoingMessage : improveMessage} @@ -116,7 +116,7 @@ const ProjectHealthMessage: FC<{ {health}%. - {health >= 70 ? keepDoingMessage : improveMessage} + {health >= 75 ? keepDoingMessage : improveMessage} ); diff --git a/package.json b/package.json index e96740ea16a7..638eaf3d6b68 100644 --- a/package.json +++ b/package.json @@ -167,7 +167,7 @@ "stoppable": "^1.1.0", "ts-toolbelt": "^9.6.0", "type-is": "^1.6.18", - "unleash-client": "6.3.0-alpha.0", + "unleash-client": "6.3.0", "uuid": "^9.0.0" }, "devDependencies": { diff --git a/src/lib/features/productivity-report/productivity-report-view-model.test.ts b/src/lib/features/productivity-report/productivity-report-view-model.test.ts index 3828de8fe26d..f0b1e66280cd 100644 --- a/src/lib/features/productivity-report/productivity-report-view-model.test.ts +++ b/src/lib/features/productivity-report/productivity-report-view-model.test.ts @@ -178,4 +178,79 @@ describe('productivityReportViewModel', () => { expect(viewModel.productionUpdatedTrendMessage()).toBe(null); }); }); + + describe('Action text', () => { + it('healthy instance', () => { + const metrics: ProductivityReportMetrics = { + ...mockMetrics, + health: 75, + previousMonth: { + ...mockMetrics.previousMonth, + health: 75, + }, + }; + + const viewModel = productivityReportViewModel({ + ...mockData, + metrics, + }); + + expect(viewModel.actionText()).toBe(null); + }); + + it('health declined', () => { + const metrics: ProductivityReportMetrics = { + ...mockMetrics, + health: 75, + previousMonth: { + ...mockMetrics.previousMonth, + health: 76, + }, + }; + + const viewModel = productivityReportViewModel({ + ...mockData, + metrics, + }); + + expect(viewModel.actionText()).toBe( + 'Remember to archive stale flags to reduce technical debt and keep your project healthy', + ); + }); + + it('health improved but below healthy threshold', () => { + const metrics: ProductivityReportMetrics = { + ...mockMetrics, + health: 74, + previousMonth: { + ...mockMetrics.previousMonth, + health: 73, + }, + }; + + const viewModel = productivityReportViewModel({ + ...mockData, + metrics, + }); + + expect(viewModel.actionText()).toBe( + 'Remember to archive stale flags to reduce technical debt and keep your project healthy', + ); + }); + + it('healthy with no previous month data', () => { + const metrics: ProductivityReportMetrics = { + ...mockMetrics, + health: 75, + previousMonth: null, + }; + + const viewModel = productivityReportViewModel({ + ...mockData, + metrics, + }); + + expect(viewModel.actionText()).toBe(null); + }); + }); }); diff --git a/src/lib/features/productivity-report/productivity-report-view-model.ts b/src/lib/features/productivity-report/productivity-report-view-model.ts index a113459df29b..e267f2db920d 100644 --- a/src/lib/features/productivity-report/productivity-report-view-model.ts +++ b/src/lib/features/productivity-report/productivity-report-view-model.ts @@ -38,6 +38,18 @@ export const productivityReportViewModel = ({ : GREEN; return healthColor; }, + actionText(): string | null { + const improveMessage = + 'Remember to archive stale flags to reduce technical debt and keep your project healthy'; + const previousHealth = this.previousMonth?.health || 0; + if (this.health <= 74) { + return improveMessage; + } + if (this.health < previousHealth) { + return improveMessage; + } + return null; + }, healthTrendMessage() { return this.previousMonthText( '%', diff --git a/src/lib/services/email-service.test.ts b/src/lib/services/email-service.test.ts index 4e72aa3d45a0..c28b2c6be814 100644 --- a/src/lib/services/email-service.test.ts +++ b/src/lib/services/email-service.test.ts @@ -135,14 +135,14 @@ test('Can send productivity report email', async () => { ); expect(content.from).toBe('noreply@getunleash.ai'); expect(content.subject).toBe('Unleash - productivity report'); - expect(content.html.includes(`Productivity Report`)).toBe(true); - expect(content.html.includes(`localhost/insights`)).toBe(true); - expect(content.html.includes(`localhost/profile`)).toBe(true); + expect(content.html.includes('Productivity Report')).toBe(true); + expect(content.html.includes('localhost/insights')).toBe(true); + expect(content.html.includes('localhost/profile')).toBe(true); expect(content.html.includes('#68a611')).toBe(true); - expect(content.html.includes(`10% more than previous month`)).toBe(true); - expect(content.text.includes(`localhost/insights`)).toBe(true); - expect(content.text.includes(`localhost/profile`)).toBe(true); - expect(content.text.includes(`localhost/profile`)).toBe(true); + expect(content.html.includes('10% more than previous month')).toBe(true); + expect(content.text.includes('localhost/insights')).toBe(true); + expect(content.text.includes('localhost/profile')).toBe(true); + expect(content.text.includes('localhost/profile')).toBe(true); }); test('Should add optional headers to productivity email', async () => { diff --git a/src/mailtemplates/productivity-report/productivity-report.html.mustache b/src/mailtemplates/productivity-report/productivity-report.html.mustache index c8a4138666d6..3182ddfdfb73 100644 --- a/src/mailtemplates/productivity-report/productivity-report.html.mustache +++ b/src/mailtemplates/productivity-report/productivity-report.html.mustache @@ -25,11 +25,12 @@
+ style="margin: 0;padding: 24px 8px 24px 8px; background: #f0f0f5;border-width: 3px;border-color: #ffffff;border-style: solid;">
{{health}}%
your instance health
{{{healthTrendMessage}}} +
{{actionText}}
diff --git a/yarn.lock b/yarn.lock index 31be70982354..2afd8e13c824 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9294,9 +9294,9 @@ __metadata: languageName: node linkType: hard -"unleash-client@npm:6.3.0-alpha.0": - version: 6.3.0-alpha.0 - resolution: "unleash-client@npm:6.3.0-alpha.0" +"unleash-client@npm:6.3.0": + version: 6.3.0 + resolution: "unleash-client@npm:6.3.0" dependencies: http-proxy-agent: "npm:^7.0.2" https-proxy-agent: "npm:^7.0.5" @@ -9306,7 +9306,7 @@ __metadata: murmurhash3js: "npm:^3.0.1" proxy-from-env: "npm:^1.1.0" semver: "npm:^7.6.2" - checksum: 10c0/2646cdc0cc2e2e257342aeeeaab3ad973acc8b48fece25c8a36207c4cadfb1bc08e88789839ebdff4191f0b56806207e66e0863e7144bbd9370fb8256626edab + checksum: 10c0/ae2cf8df7f6691fe0c35d873a7abc2c099a10ea520186e7c7dbd70dcc45e6555528b7eda2bd145a9d30b53f009232a485b319354769f67c9505270e50f19e3f3 languageName: node linkType: hard @@ -9421,7 +9421,7 @@ __metadata: tsc-watch: "npm:6.2.1" type-is: "npm:^1.6.18" typescript: "npm:5.4.5" - unleash-client: "npm:6.3.0-alpha.0" + unleash-client: "npm:6.3.0" uuid: "npm:^9.0.0" wait-on: "npm:^7.2.0" languageName: unknown