fix: initialize bool parameter state from config - #92
Conversation
553911c to
1b36b86
Compare
There was a problem hiding this comment.
Pull request overview
Fixes boolean gadget parameter UI state restoration by initializing the checkbox’s initial checked state from persisted config, aligning behavior with other parameter components and adding a regression test for the remount scenario (Issue #91).
Changes:
- Initialize
Checkboxstate fromconfig.get()viadefaultCheckedinsrc/gadgets/params/bool.tsx. - Add unit test coverage validating that
config.get()returning"true"renders the checkbox checked.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/gadgets/params/bool.tsx | Initializes checkbox initial state from config.get() to preserve persisted checked state across remounts. |
| src/gadgets/params/bool.test.tsx | Adds a regression test verifying the checkbox is initially checked when config.get() returns "true". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { vi } from 'vitest'; | ||
| import React from 'react'; | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; |
There was a problem hiding this comment.
This test imports @testing-library/jest-dom, which is the Jest entrypoint. Since this repo uses Vitest (and doesn’t have Jest/@types/jest in the lockfile), prefer the Vitest-specific entry (@testing-library/jest-dom/vitest) or move it into the shared Vitest setup to ensure matcher runtime + TypeScript typings work reliably under npm run tsc/CI.
| import '@testing-library/jest-dom'; | |
| import '@testing-library/jest-dom/vitest'; |
b3bb549 to
ccf887f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <Box display="flex" flexDirection="row" gap={2}> | ||
| <FormControlLabel | ||
| control={<Checkbox onChange={handleChange} />} | ||
| control={<Checkbox defaultChecked={config.get?.() === 'true'} onChange={handleChange} />} |
There was a problem hiding this comment.
defaultChecked makes this an uncontrolled checkbox that only reads config.get() on initial mount; if the config value changes while the component stays mounted (e.g., external reset / param sync), the UI won’t update. If config is intended to be the source of truth, consider switching to a controlled checked prop backed by component state initialized from config.get() (and updated in onChange).
| @@ -0,0 +1,56 @@ | |||
| /// <reference types="vitest" /> | |||
| import '@testing-library/jest-dom/vitest'; | |||
| import { fireEvent,render, screen } from '@testing-library/react'; | |||
There was a problem hiding this comment.
Prefer @testing-library/user-event over fireEvent for user interactions (clicking checkboxes), since it more closely matches real browser behavior and reduces false positives. If you keep fireEvent, at least ensure the import formatting is consistent (space after commas) to match typical style.
| test('calls config.set with "true" when checked', () => { | ||
| render(<CheckboxFilter param={mockParam} config={mockConfig} />); | ||
|
|
||
| fireEvent.click(screen.getByRole('checkbox')); |
There was a problem hiding this comment.
Prefer @testing-library/user-event over fireEvent for user interactions (clicking checkboxes), since it more closely matches real browser behavior and reduces false positives. If you keep fireEvent, at least ensure the import formatting is consistent (space after commas) to match typical style.
| fireEvent.click(checkbox); // check | ||
| fireEvent.click(checkbox); // uncheck |
There was a problem hiding this comment.
Prefer @testing-library/user-event over fireEvent for user interactions (clicking checkboxes), since it more closely matches real browser behavior and reduces false positives. If you keep fireEvent, at least ensure the import formatting is consistent (space after commas) to match typical style.
There was a problem hiding this comment.
Hii @beep-boopp should we use @testing-library/user-event as mentioned here
Signed-off-by: Prajwal <percy38621@gmail.com>
ccf887f to
db51dde
Compare
|
All linting, formatting, and Vitest imports resolved. Ready for review |
|
Hey @ashu8912 On tests: holding off on the userEvent swap here to avoid mixed styles across param tests. Will migrate all 7 test files cleanly in #23 instead. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bool.tsxnever calledconfig.get()to restore its initial value,causing pre-checked boolean parameters to always render unchecked after
a re-mount. Fixes #91.
Caught while writing unit tests in #23.
What changed
Switched
bool.tsxto a controlled component — replaceddefaultCheckedwithchecked={checked}backed byuseStateinitialized fromconfig.get?.().State is the source of truth after mount,
handleChangekeeps config in syncvia
config.set. Also bundled pre-existing lint fixes (gadgetGrid.tsxunusedimports,
wasm.jsadded toeslintIgnore) to unblock CI.Testing done
Added a regression test

renders checkbox as checked when config.get returns "true"to
bool.test.tsx. All 4 tests passing locally: