Skip to content

fix: change item price tiers toggle text and UX, adjust unit tests#842

Open
tomrndom wants to merge 2 commits intomasterfrom
fix/item-price-toggle-ux
Open

fix: change item price tiers toggle text and UX, adjust unit tests#842
tomrndom wants to merge 2 commits intomasterfrom
fix/item-price-toggle-ux

Conversation

@tomrndom
Copy link

@tomrndom tomrndom commented Mar 26, 2026

ref: https://app.clickup.com/t/86b92rh1a

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Bug Fixes

    • Updated price-tier checkbox behavior and early-bird value handling so UI state and submitted values align.
  • Tests

    • Revised tests to match the new checkbox states, interactions, and submit payload expectations.
  • Accessibility

    • Added clearer ARIA labeling for price-tier controls.
  • Chores

    • Removed an unused translation entry from language files.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet March 26, 2026 16:32
@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7e066c6f-55f6-44b2-8f7b-80c275080a83

📥 Commits

Reviewing files that changed from the base of the PR and between 303083a and 9253671.

📒 Files selected for processing (1)
  • src/components/mui/formik-inputs/item-price-tiers.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/mui/formik-inputs/item-price-tiers.js

📝 Walkthrough

Walkthrough

ItemPriceTiers 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

Cohort / File(s) Summary
Component Logic Inversion
src/components/mui/formik-inputs/item-price-tiers.js
Checkbox checked state flipped to !isEnabled; handleToggle now writes null when selecting and 0 when unselecting; label simplified to always use price_tiers.not_available; added inputProps aria-label.
Test Expectations
src/components/mui/__tests__/item-price-tiers.test.js
All checkbox assertions inverted across scenarios (enabled→unchecked, disabled→checked); removed assertions for N/A input rendering/disabled state; interaction flows and submit payload expectations flipped (early_bird_rate: null0).
Localization
src/i18n/en.json
Removed price_tiers.available translation entry, leaving only price_tiers.not_available ("N/A").

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • smarcet
  • romanetar

Poem

🐰 I flipped the boxes, hopped through the night,
Nulls took the left, zeros took the right.
Labels say N/A with a soft little cheer,
Tests now agree — the logic is clear. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: modifying the item price tiers toggle UX/text and updating corresponding unit tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/item-price-toggle-ux

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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_available field 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

📥 Commits

Reviewing files that changed from the base of the PR and between f80f175 and 303083a.

📒 Files selected for processing (3)
  • src/components/mui/__tests__/item-price-tiers.test.js
  • src/components/mui/formik-inputs/item-price-tiers.js
  • src/i18n/en.json
💤 Files with no reviewable changes (1)
  • src/i18n/en.json

Comment on lines 50 to +57
<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")}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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>
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