Skip to content

♻️ refactor(line-items): refactor child components and add 100% coverage tests#777

Merged
acasazza merged 4 commits into
v5.0.0from
feat/line-items-child-refactor
May 28, 2026
Merged

♻️ refactor(line-items): refactor child components and add 100% coverage tests#777
acasazza merged 4 commits into
v5.0.0from
feat/line-items-child-refactor

Conversation

@acasazza
Copy link
Copy Markdown
Member

@acasazza acasazza commented May 27, 2026

Summary

  • Replace synchronous useState+useEffect patterns with useMemo in LineItemAmount, LineItemsCount, LineItemsEmpty
  • Fix as anyElementType typing in LineItemOption and LineItemOptions
  • LineItemOptions: use sku_option.id static SDK attribute instead of dynamic skuOption() accessor
  • LineItemRemoveLink: replace <a href="#"> with <button type="button"> (a11y fix)
  • LineItemsContainer (deprecated): fix noExplicitAny, import sorting, useEffect dependency
  • Add exhaustive specs for all line item child components with shared test helpers
  • All 70 tests passing at 100% coverage

Verification

cd packages/react-components && node_modules/.bin/vitest run specs/line_items

Notes

  • LineItemsContainer.tsx is deprecated (marked @deprecated) — minimal fixes only
  • Test helpers use proper SDK types (Partial<LineItem>, Partial<LineItemOption>) — no any
  • All Biome lint/format checks pass (0 errors, 0 warnings) on the line_items folder

Alessandro Casazza and others added 2 commits May 27, 2026 16:51
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@acasazza acasazza added enhancement New feature or request components Components package refactor labels May 27, 2026
@acasazza acasazza self-assigned this May 27, 2026
- Fix import sorting across all spec files (auto-fixed)
- Replace `any` types in helpers.tsx with proper SDK types (Partial<LineItem>, Partial<LineItemOption>)
- Fix LineItem.spec.tsx: alias SDK LineItem as LineItemResource to avoid name collision
- Fix LineItemImage.spec.tsx: use ChildrenFunction<TLineItemImage> instead of `as any` cast; remove `undefined as any`
- Fix LineItemOptions.tsx: use `o.sku_option?.id` (static SDK attribute) instead of `(o as any).skuOption?.()`; use `o.id` as map key to avoid noArrayIndexKey warning
- Fix helpers.tsx: replace `skuOption()` method mock with `sku_option` static attribute to match SDK type
- All 70 tests passing, no Biome errors

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 27, 2026

npm i https://pkg.pr.new/@commercelayer/react-components@777

commit: b0f51a7

- Fix import sorting in LineItemCode, LineItemField, LineItemName, LineItemQuantity, LineItemRemoveLink, LineItemsContainer
- Fix LineItems.tsx formatter (line break in ternary)
- LineItemRemoveLink: change <a href="#"> to <button type="button"> (a11y: useValidAnchor)
- LineItemsContainer: Record<string, any> → Record<string, unknown>
- LineItemsContainer: add addResourceToInclude to useEffect deps

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@acasazza acasazza requested review from gciotola and pfferrari May 27, 2026 15:44
@acasazza acasazza merged commit 3a96c74 into v5.0.0 May 28, 2026
2 checks passed
@acasazza acasazza deleted the feat/line-items-child-refactor branch May 28, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

components Components package enhancement New feature or request refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants