diff --git a/src/lib/daily/__tests__/today-overview.test.ts b/src/lib/daily/__tests__/today-overview.test.ts index 7e047203e..db11291ec 100644 --- a/src/lib/daily/__tests__/today-overview.test.ts +++ b/src/lib/daily/__tests__/today-overview.test.ts @@ -149,6 +149,37 @@ describe("firstSubstantiveSentence", () => { ).toBe("Sleep dipped slightly last night."); }); + it("keeps a sentence where the score's digits are part of another figure", () => { + // Score 52, and a sleep duration that happens to end in 52 minutes. + expect( + firstSubstantiveSentence("You slept 7 h 52 min, a solid night.", 52), + ).toBe("You slept 7 h 52 min, a solid night."); + expect( + firstSubstantiveSentence("Your resting heart rate is 52 bpm.", 52), + ).toBe("Your resting heart rate is 52 bpm."); + expect( + firstSubstantiveSentence("You walked 52 minutes more than usual.", 52), + ).toBe("You walked 52 minutes more than usual."); + }); + + it("still skips the score sentence in every shipped language", () => { + for (const sentence of [ + "Your health score is 52.", + "Dein Gesundheitsscore heute liegt bei 52.", + "Tu puntuación de salud hoy es 52.", + "Ton score de santé aujourd'hui est de 52.", + "Il tuo punteggio di salute oggi è 52.", + "오늘 건강 점수는 52점이에요.", + "Twój dzisiejszy wynik zdrowia to 52.", + "You are at 52/100 today.", + ]) { + expect( + firstSubstantiveSentence(`${sentence} Sleep dipped last night.`, 52), + sentence, + ).toBe("Sleep dipped last night."); + } + }); + it("keeps decimals inside one sentence", () => { expect( firstSubstantiveSentence("You slept 7.5 hours, a solid night.", null), diff --git a/src/lib/daily/today-overview.ts b/src/lib/daily/today-overview.ts index df7a78d94..9f12c6731 100644 --- a/src/lib/daily/today-overview.ts +++ b/src/lib/daily/today-overview.ts @@ -221,11 +221,32 @@ export function isGreetingOnly(sentence: string): boolean { return words.length < MIN_CONTENT_WORDS; } +/** + * Words that name the health score in every shipped language, and the + * "out of 100" forms. A sentence repeats the ring only when it talks about + * the score; a figure that merely shares its digits ("7 h 52 min" next to a + * score of 52) is content. + */ +const SCORE_CONTEXT = + /(?