Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

[BpkStarRating] Replace snapshot tests with explicit assertions - #4670

Merged
Faye (Faye-Xiao) merged 1 commit into
xiaogliu/star-rating-to-tsfrom
xiaogliu/star-rating-explicit-assertions
Jun 5, 2026
Merged

Faye (Faye-Xiao) merged 1 commit into
xiaogliu/star-rating-to-tsfrom
xiaogliu/star-rating-explicit-assertions

Conversation

@xiaogliu

Copy link
Copy Markdown
Contributor

Summary

Stacked on top of #4523 — replaces all 30 `toMatchSnapshot()` calls across the 5 test files in `bpk-component-star-rating` with explicit assertions that name the behaviour each test is checking, addressing #4523 (comment).

The five rewritten files now assert on:

  • `BpkStar`: presence/absence of the star modifier classes (`bpk-star`, `bpk-star--filled`, `bpk-star__container--half-star`, `bpk-star--large`) per type and size, plus `className` passthrough.
  • `BpkInteractiveStar`: `role=button`, `aria-label`, `aria-pressed`, and the inner star fill state per `type`/`selected` combo.
  • `BpkStarRating`: `role=img`, `aria-label`, and the count of full/half/empty stars per rating, including `maxRating` and rounding.
  • `BpkInteractiveStarRating`: rendered button count, fill count per `rating` / `maxRating` / `hoverRating`, and that `onRatingHover` / `onRatingSelect` get called with the correct star number and event.
  • `withInteractiveStarRatingState`: initial state (5 unselected stars), that click selects (`aria-pressed=true`), and that hover only previews (`aria-pressed` stays `false`).

The `snapshots/*.snap` files are deleted. `getTypeByRating` unit tests are kept as-is — they were already explicit.

No production code changes.

Test plan

  • `npm run jest -- packages/backpack-web/src/bpk-component-star-rating` — 7 suites, 42 tests, 0 snapshots, all pass.
  • `npx tsc --noEmit` — no errors in `bpk-component-star-rating`.
  • `npx eslint packages/backpack-web/src/bpk-component-star-rating` — no errors, no warnings.

🤖 Generated with Claude Code

The 30 toMatchSnapshot() calls across the 5 test files in
bpk-component-star-rating verified rendered HTML by full-DOM diff,
which obscures intent and tends to pass silently after an accidental
--updateSnapshot. Replace them with assertions that name the behaviour
each test is checking:

- BpkStar: assert presence/absence of star modifier classes per type
  and size, plus className passthrough.
- BpkInteractiveStar: assert the role=button, aria-label, aria-pressed,
  and the inner star fill state per type/selected combo.
- BpkStarRating: assert the role=img, aria-label, and the count of
  full/half/empty stars per rating, including maxRating and rounding
  behaviour.
- BpkInteractiveStarRating: assert the rendered button count, fill
  count per rating/maxRating/hoverRating, and that onRatingHover /
  onRatingSelect get called with the correct star number.
- withInteractiveStarRatingState: assert the initial state, that
  click selects (aria-pressed=true) and that hover only previews
  (aria-pressed stays false).

Also delete the now-orphaned __snapshots__/*.snap files. No production
code changes; jest now reports 0 snapshots for this package.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@Faye-Xiao
Faye (Faye-Xiao) merged commit cd48530 into xiaogliu/star-rating-to-ts Jun 5, 2026
5 checks passed
@Faye-Xiao
Faye (Faye-Xiao) deleted the xiaogliu/star-rating-explicit-assertions branch June 5, 2026 10:42
Vincent Liu (xiaogliu) added a commit that referenced this pull request Jun 8, 2026
* [BpkStarRating] Migrate JS to TypeScript

Convert the bpk-component-star-rating package from JavaScript/Flow to
TypeScript. Replace prop-types and Flow types with typed Props exports
and rename all source/test/snapshot files (.js -> .ts/.tsx). No
business-logic, JSX, or rendering changes - existing snapshots remain
valid.

- Rename index.js -> index.ts and re-export per-component *Props types
- Rename BpkStar/BpkStarRating/BpkInteractiveStar/BpkInteractiveStarRating
  to .tsx with typed Props exports; keep className?: string | null and
  destructuring defaults in place of defaultProps
- Convert STAR_TYPES to as const and derive a StarType union
- Migrate withInteractiveStarRatingState to .tsx with a generic class
  component and a public static displayName field
- Rename themeAttributes/accessibility/themeAttributes-test files
- Rename snapshot files to *-test.tsx.snap so Jest finds them under the
  new test filenames
- Drop the now-unused @ts-expect-error suppressions on the index/component
  imports in the stories file

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* [BpkStarRating] Drop now-unused @ts-expect-error on consumers

After typing the star-rating package, the @ts-expect-error suppressions
on its imports in BpkRating.stories and BpkCardV2.stories became unused
directives, breaking `tsc --noEmit`. Remove them.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* [BpkStarRating] Address review feedback

- BpkStar: fix half-star className being a comma-separated string at
  runtime. Pre-existing bug from JS code that the TS migration's
  `as unknown as string` cast was hiding. Use `.join(' ')` so the half
  star gets a valid space-separated class list. Updates 4 half-star
  snapshots accordingly.
- withInteractiveStarRatingState: drop the `event.persist()` call and
  its `as SyntheticEvent` cast — `persist()` has been a no-op since
  React 17.
- withInteractiveStarRatingState: destructure HOC-owned `onRatingSelect`
  out of `this.props` before spreading, so only `P` props are forwarded
  to the wrapped component.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* [BpkStarRating] Replace snapshot tests with explicit assertions (#4670)

The 30 toMatchSnapshot() calls across the 5 test files in
bpk-component-star-rating verified rendered HTML by full-DOM diff,
which obscures intent and tends to pass silently after an accidental
--updateSnapshot. Replace them with assertions that name the behaviour
each test is checking:

- BpkStar: assert presence/absence of star modifier classes per type
  and size, plus className passthrough.
- BpkInteractiveStar: assert the role=button, aria-label, aria-pressed,
  and the inner star fill state per type/selected combo.
- BpkStarRating: assert the role=img, aria-label, and the count of
  full/half/empty stars per rating, including maxRating and rounding
  behaviour.
- BpkInteractiveStarRating: assert the rendered button count, fill
  count per rating/maxRating/hoverRating, and that onRatingHover /
  onRatingSelect get called with the correct star number.
- withInteractiveStarRatingState: assert the initial state, that
  click selects (aria-pressed=true) and that hover only previews
  (aria-pressed stays false).

Also delete the now-orphaned __snapshots__/*.snap files. No production
code changes; jest now reports 0 snapshots for this package.

Co-authored-by: Vincent Liu <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Vincent Liu <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>
Co-authored-by: Faye <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants