fix: change item price tiers toggle text and UX, adjust unit tests#842
fix: change item price tiers toggle text and UX, adjust unit tests#842
Conversation
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughItemPriceTiers invertes its enabled semantics: checkbox visual state is negated, Formik store swaps null ↔ 0 for tier availability, label always shows "N/A", and tests updated to match the new semantics. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User (UI)
participant Component as ItemPriceTiers Component
participant Formik as Formik State
participant Submit as Submit Handler
rect rgba(200,200,255,0.5)
User->>Component: clicks checkbox (visually toggles)
Component->>Component: compute !isEnabled, call handleToggle(checked)
Component->>Formik: setFieldValue(tier, checked ? null : 0)
end
rect rgba(200,255,200,0.5)
User->>Submit: clicks Submit
Submit->>Formik: read form values
Submit->>Submit: include early_bird_rate as null or 0 per Formik value
Submit->>Server: send payload
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/components/mui/__tests__/item-price-tiers.test.js (1)
83-95: Keep one assertion on the rendered N/A state.These checks validate the submitted value, but they no longer verify the user-visible part of the UX change. Adding one assertion for the disabled
price_tiers.not_availablefield would catch a rendering regression that still passes on payload alone.🧪 Suggested test addition
await act(async () => { await userEvent.click(checkboxes[0]); await userEvent.click(screen.getByText("submit")); }); + expect(screen.getByDisplayValue("price_tiers.not_available")).toBeDisabled(); + expect(onSubmit).toHaveBeenCalledWith( expect.objectContaining({ early_bird_rate: null }), expect.anything() );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/mui/__tests__/item-price-tiers.test.js` around lines 83 - 95, The test should also assert the user-visible N/A state instead of only inspecting the submitted payload: after the existing clicks in the "should set the field value to null when marked as N/A" test (which uses renderComponent, ALL_ENABLED, and userEvent), add a single assertion that the UI shows the disabled/marked-N/A state for the price_tiers.not_available field (e.g. check that the control or label for "price_tiers.not_available" is present and disabled or displays "N/A") so rendering regressions are caught in addition to payload checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/mui/formik-inputs/item-price-tiers.js`:
- Around line 50-57: The Checkbox currently uses a single hard-coded label via
T.translate("price_tiers.not_available") so all tier toggles are announced
identically; update the Checkbox to include a tier-specific accessible name
(e.g. via inputProps={{ 'aria-label': ... }} or aria-label) that incorporates
the tier identifier from the current field (use field.name or the tier title you
render) and keep the existing onChange/checked/disabled props; for example build
a localized string using T.translate with the tier (or concatenate the tier
label) and pass it as inputProps={{ 'aria-label': tierAccessibleName }} on the
Checkbox so assistive tech can distinguish Early Bird / Standard / Onsite
toggles while leaving handleToggle, field, and readOnly logic unchanged.
---
Nitpick comments:
In `@src/components/mui/__tests__/item-price-tiers.test.js`:
- Around line 83-95: The test should also assert the user-visible N/A state
instead of only inspecting the submitted payload: after the existing clicks in
the "should set the field value to null when marked as N/A" test (which uses
renderComponent, ALL_ENABLED, and userEvent), add a single assertion that the UI
shows the disabled/marked-N/A state for the price_tiers.not_available field
(e.g. check that the control or label for "price_tiers.not_available" is present
and disabled or displays "N/A") so rendering regressions are caught in addition
to payload checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c93755e5-ce1b-4652-b57d-17ac9fcf8e71
📒 Files selected for processing (3)
src/components/mui/__tests__/item-price-tiers.test.jssrc/components/mui/formik-inputs/item-price-tiers.jssrc/i18n/en.json
💤 Files with no reviewable changes (1)
- src/i18n/en.json
| <Checkbox | ||
| checked={isEnabled} | ||
| checked={!isEnabled} | ||
| onChange={(ev) => handleToggle(field, ev.target.checked)} | ||
| size="small" | ||
| disabled={readOnly} | ||
| /> | ||
| } | ||
| label={T.translate( | ||
| isEnabled | ||
| ? "price_tiers.available" | ||
| : "price_tiers.not_available" | ||
| )} | ||
| label={T.translate("price_tiers.not_available")} |
There was a problem hiding this comment.
Give each checkbox a tier-specific accessible name.
With the label now hard-coded to price_tiers.not_available, all three checkboxes expose the same name. That makes the Early Bird / Standard / Onsite toggles indistinguishable for assistive tech users.
♿ Suggested fix
control={
<Checkbox
checked={!isEnabled}
onChange={(ev) => handleToggle(field, ev.target.checked)}
size="small"
disabled={readOnly}
+ inputProps={{
+ "aria-label": `${T.translate(label)} ${T.translate(
+ "price_tiers.not_available"
+ )}`
+ }}
/>
}
label={T.translate("price_tiers.not_available")}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/components/mui/formik-inputs/item-price-tiers.js` around lines 50 - 57,
The Checkbox currently uses a single hard-coded label via
T.translate("price_tiers.not_available") so all tier toggles are announced
identically; update the Checkbox to include a tier-specific accessible name
(e.g. via inputProps={{ 'aria-label': ... }} or aria-label) that incorporates
the tier identifier from the current field (use field.name or the tier title you
render) and keep the existing onChange/checked/disabled props; for example build
a localized string using T.translate with the tier (or concatenate the tier
label) and pass it as inputProps={{ 'aria-label': tierAccessibleName }} on the
Checkbox so assistive tech can distinguish Early Bird / Standard / Onsite
toggles while leaving handleToggle, field, and readOnly logic unchanged.
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
ref: https://app.clickup.com/t/86b92rh1a
Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com
Summary by CodeRabbit
Bug Fixes
Tests
Accessibility
Chores