mirror of
https://github.com/jlengrand/adyen-web.git
synced 2026-03-10 08:01:22 +00:00
reverts default storedetails default value (#2307)
This commit is contained in:
5
.changeset/long-taxis-drop.md
Normal file
5
.changeset/long-taxis-drop.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@adyen/adyen-web': patch
|
||||
---
|
||||
|
||||
fixes bug where storedetails had state value of true by default without visually showing it
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user