reverts default storedetails default value (#2307)

This commit is contained in:
António Ferreira
2023-08-22 16:36:48 +02:00
committed by GitHub
parent 043e45d713
commit 25abfacd25
3 changed files with 25 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': patch
---
fixes bug where storedetails had state value of true by default without visually showing it

View File

@@ -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);
});

View File

@@ -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);