Skip to content

test(bulletin): add unit test for getPageItems pagination - #348

Merged
andrecamerino merged 1 commit into
ci/wire-up-test-workflowfrom
test/182-first-unit-test
Sep 4, 2026
Merged

test(bulletin): add unit test for getPageItems pagination#348
andrecamerino merged 1 commit into
ci/wire-up-test-workflowfrom
test/182-first-unit-test

Conversation

@andrecamerino

@andrecamerino andrecamerino commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds this repo's first real unit test, proving the Vitest/RTL setup from #347 actually works end to end. This is PR 3 of a 4-part stack (base: ci/wire-up-test-workflow):

  1. chore(testing): set up vitest and react testing library #347 - Vitest + RTL tooling
  2. chore(ci): wire pnpm test into CI and split into parallel jobs #352 - CI wiring
  3. This PR - unit test example
  4. Integration test example (Payload + Mongo round-trip)

Target: getPageItems (src/components/bulletin/AllArticles.tsx) - the pagination-window algorithm that turns (totalPages, currentPage) into the list of page numbers/ellipses the pager renders. It's a plain function (no rendering, no DB), so this is a pure "unit test" - deterministic and isolated, deliberately picked over a trivial formatter since it has real branching logic worth locking down (short vs. long page lists, ellipsis placement on either/both sides).

Changes:

  • Added export to getPageItems and the ELLIPSIS const it returns - previously module-private, no behavior change.
  • New src/components/bulletin/AllArticles.test.tsx, colocated with the component it covers, with a comment noting that convention (test file next to source, *.test.ts(x)) for future contributors. Covers: all-pages-shown for small totals, single-page, windowing with ellipsis on both/one/neither side.

Part of #182 (satisfies the "sample test file exists" AC item)

Note

Because #352 (CI wiring) now sits below this PR in the stack, this PR's own CI run actually exercises the test job against these tests - not just local pnpm test output.

Decisions

  • Colocated rather than placed under tests/ - this test is tied to one specific file, so it lives next to it. tests/ is reserved for cross-cutting concerns (setup helpers, things that don't belong to a single source file).

AI Usage

  • AI was used to generate this PR
  • I personally reviewed and understood the code if generated by AI (you should be able to explain every changed line in review)

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Manual testing — screenshots or a short video must be attached below for any UI change
  • npm run lint and npm run build pass locally

pnpm test (5/5 passing), pnpm lint, and pnpm format:check were run locally and pass clean. pnpm build was not run locally in this session (no local DB/env configured) - CI's Build job will verify it.

@andrecamerino
andrecamerino force-pushed the test/182-first-unit-test branch from eed9a59 to 897b5ea Compare September 2, 2026 13:47
@andrecamerino
andrecamerino changed the base branch from test/182-set-up-vitest to ci/wire-up-test-workflow September 2, 2026 13:48
@andrecamerino
andrecamerino force-pushed the test/182-first-unit-test branch from 897b5ea to 6823f28 Compare September 2, 2026 14:23
@andrecamerino
andrecamerino force-pushed the test/182-first-unit-test branch from 6823f28 to 27541cd Compare September 2, 2026 14:30
@andrecamerino
andrecamerino force-pushed the test/182-first-unit-test branch from 27541cd to 96eea47 Compare September 3, 2026 14:35
@andrecamerino
andrecamerino marked this pull request as ready for review September 3, 2026 14:49
@andrecamerino andrecamerino added the testing refactors, cleanup label Sep 4, 2026

@evanautianle evanautianle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yurrrrpppp looks good great work andre

@andrecamerino
andrecamerino merged commit aca015f into main Sep 4, 2026
10 of 14 checks passed
@andrecamerino
andrecamerino deleted the test/182-first-unit-test branch September 4, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing refactors, cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants