Skip to content

Commit

Permalink
reverts default storedetails default value
Browse files Browse the repository at this point in the history
  • Loading branch information
m1aw committed Aug 22, 2023
1 parent 3c8af08 commit 402c9eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-taxis-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': patch
---

fixes bug where storedetails had state value of true by default without visually showing it
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,42 @@ import StoreDetails from './StoreDetails';

test('StoredDetails defaults to false, toggles to true', async () => {
const user = userEvent.setup();
let value;

const onChangeMock = jest.fn();
const onChangeMock = jest.fn(event => (value = event));
render(<StoreDetails onChange={onChangeMock} />);
const checkbox = await screen.findByRole('checkbox');
// check for the checked status in the DOM
expect(checkbox).not.toBeChecked();
// also check for the emitted value from onChange
expect(value).toBe(false);

await user.click(checkbox);
expect(checkbox).toBeChecked();
expect(value).toBe(true);
});

test('StoredDetails storeDetails prop true does nothing LEGACY TEST', async () => {
// I wanted to capture this buggy feature,
const user = userEvent.setup();
let value;

const onChangeMock = jest.fn();
const onChangeMock = jest.fn(event => (value = event));
render(<StoreDetails storeDetails={true} onChange={onChangeMock} />);
const checkbox = await screen.findByRole('checkbox');
// buggy behaviour should be fixed, but we improve test coverage before that
// the checkbox will not be visibly "checked"
expect(checkbox).not.toBeChecked();
// correct behaviour
expect(value).toBe(true);

await user.click(checkbox);
expect(checkbox).toBeChecked();
// it will emit "true" again because it will start reading the DOM
expect(value).toBe(true);

await user.click(checkbox);
// now it's all correct
expect(checkbox).not.toBeChecked();
expect(value).toBe(false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Checkbox from '../FormFields/Checkbox';
/**
* "Store details" generic checkbox
*/
function StoreDetails({ storeDetails = true, ...props }) {
function StoreDetails({ storeDetails = false, ...props }) {
const { i18n } = useCoreContext();
const [value, setValue] = useState(storeDetails);

Expand Down

0 comments on commit 402c9eb

Please sign in to comment.