Skip to content

feat: estimated reading time badge on articles (REST, GraphQL, frontend) - #233

Open
devin-ai-integration[bot] wants to merge 2 commits into
devin/1791491209-modernization-integrationfrom
devin/1791549881-feature-dev-reading-time
Open

devin-ai-integration[bot] wants to merge 2 commits into
devin/1791491209-modernization-integrationfrom
devin/1791549881-feature-dev-reading-time

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Adds an estimated reading time to every article, built on the #232 modernization branch (Java 21 / Boot 3.5 / DGS 10 / Next 15).

It's computed on the server from the article body, so REST and GraphQL always return the same number. There's no DB column and no migration:

ReadingTimeCalculator.minutesFor(body) = max(1, ceil(countWords(body) / 200))
countWords: strip HTML tags, keep link/image text but drop the URLs, then count runs of Unicode letters/digits (apostrophes kept)
  • REST: ArticleData.getReadingTimeMinutes() is a read-only derived getter, so readingTimeMinutes now shows up in GET/POST /articles/{slug} and /articles list entries.
  • GraphQL: new Article.readingTimeMinutes: Int!, set in ArticleDatafetcher.buildArticleResult. The schema snapshot tests (SchemaContractTest, GraphqlContractTest) are updated; this new field is the only contract change.
  • Frontend: new ReadingTimeBadge component shows "N min read" (.reading-time-badge) in ArticleMeta (article page) and ArticlePreview (feeds). It shows nothing if the field is missing or less than 1.

Tests

  • Unit: ReadingTimeCalculatorTest covers null/blank input, the 200/201/1000-word boundaries, markdown/link/image stripping, HTML, contractions and accented letters.
  • API: ArticlesApiTest (450 words → 3), ArticlesContractTest (650 words → 4 on POST, GET and in the list), ArticleQueryTest (GraphQL), JsonSerializationTest.
  • Vitest: __tests__/components/readingTime.test.tsx covers the badge, the preview, the article meta, and the case where the field is missing.
  • Selenium: ReadingTimeBadgeTest (added to testng-smoke.xml) registers a user, publishes a 650-word article, and checks for "4 min read" in the home feed preview and on the article page.

Local results: backend 391 tests pass, plus spotless and the JaCoCo gate (94.2% instruction / 84.7% branch). Frontend 158 Vitest tests pass, plus lint, typecheck and build. Selenium 6/6 pass.

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/375491084ef84a0da00047c334354739
Open in Devin Desktop: https://partner-workshops.devinenterprise.com/desktop/session/375491084ef84a0da00047c334354739?variant=devin
Requested by: @mbatchelor81

@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

Reading-time check in the running app

Tested in Chrome against the running app (Spring Boot backend + Next.js frontend), logged in as a freshly registered user.

  • Pass: published a 650-word article. It shows 4 min read in the Global Feed and in the article banner. REST and GraphQL both return readingTimeMinutes: 4.
  • Pass: edited the article down to 150 words. Both badges changed to 1 min read, matching REST.
  • Pass: a one-sentence article, a markdown link with a 1,000-segment URL, and a seeded article all show 1 min read, so link URLs don't add to the count.
  • No defects found. Tested in desktop Chrome only.
Feed preview (650 words) Article banner (650 words)
Feed badge Article badge
Edited to 150 words Long markdown URL not counted
Updated badge URL exclusion
JUnit report Selenium readingTimeBadge
JUnit Selenium

Written by Devin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant