multiple: fix selectable card onChange
The `onChange` event for the selectable cards needed to be placed inside the `selectableActions` of the `CardHeader`. Since the `onChange` action was not implemented we were getting warnings in the test output for that a component was changing an uncontrolled input to controlled.
This commit is contained in:
parent
bac647ded6
commit
c2998306cf
3 changed files with 15 additions and 3 deletions
|
|
@ -48,6 +48,7 @@ const BlueprintCard = ({ blueprint }: blueprintProps) => {
|
||||||
name: blueprint.id,
|
name: blueprint.id,
|
||||||
selectableActionId: blueprint.id,
|
selectableActionId: blueprint.id,
|
||||||
selectableActionAriaLabel: blueprint.id,
|
selectableActionAriaLabel: blueprint.id,
|
||||||
|
onChange: () => dispatch(setBlueprintId(blueprint.id)),
|
||||||
isHidden: true, // hide the card's checkbox
|
isHidden: true, // hide the card's checkbox
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ type TargetEnvironmentCardProps = {
|
||||||
isSelected: boolean;
|
isSelected: boolean;
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
testId: string;
|
testId: string;
|
||||||
handleOnClick: MouseEventHandler<HTMLElement>;
|
handleOnClick: () => void;
|
||||||
onMouseEnter?: MouseEventHandler<HTMLElement>;
|
onMouseEnter?: MouseEventHandler<HTMLElement>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -59,8 +59,8 @@ const TargetEnvironmentCard = ({
|
||||||
<Card
|
<Card
|
||||||
data-testid={testId}
|
data-testid={testId}
|
||||||
style={{ textAlign: 'center' } as React.CSSProperties}
|
style={{ textAlign: 'center' } as React.CSSProperties}
|
||||||
onClick={handleOnClick}
|
|
||||||
onMouseUp={onMouseEnter}
|
onMouseUp={onMouseEnter}
|
||||||
|
onClick={handleOnClick}
|
||||||
isSelected={isSelected}
|
isSelected={isSelected}
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
isSelectable
|
isSelectable
|
||||||
|
|
@ -71,6 +71,13 @@ const TargetEnvironmentCard = ({
|
||||||
name: title,
|
name: title,
|
||||||
selectableActionId: title.toLowerCase(),
|
selectableActionId: title.toLowerCase(),
|
||||||
selectableActionAriaLabel: title.toLowerCase(),
|
selectableActionAriaLabel: title.toLowerCase(),
|
||||||
|
// we need to give the `selectableActions` an
|
||||||
|
// onChange handler since the card actions use
|
||||||
|
// checkboxes to handle selectable cards.
|
||||||
|
// This workaround reduces noise in the test
|
||||||
|
// output
|
||||||
|
onChange: () => {},
|
||||||
|
isChecked: isSelected,
|
||||||
isHidden: true, // hide the card's checkbox
|
isHidden: true, // hide the card's checkbox
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -177,16 +177,20 @@ describe('Step Image output', () => {
|
||||||
|
|
||||||
const awsTile = await screen.findByTestId('upload-aws');
|
const awsTile = await screen.findByTestId('upload-aws');
|
||||||
user.click(awsTile); // select
|
user.click(awsTile); // select
|
||||||
|
await waitFor(() => expect(nextButton).toBeEnabled());
|
||||||
user.click(awsTile); // deselect
|
user.click(awsTile); // deselect
|
||||||
|
await waitFor(() => expect(nextButton).toBeDisabled());
|
||||||
|
|
||||||
const googleTile = await screen.findByTestId('upload-google');
|
const googleTile = await screen.findByTestId('upload-google');
|
||||||
user.click(googleTile); // select
|
user.click(googleTile); // select
|
||||||
|
await waitFor(() => expect(nextButton).toBeEnabled());
|
||||||
user.click(googleTile); // deselect
|
user.click(googleTile); // deselect
|
||||||
|
await waitFor(() => expect(nextButton).toBeDisabled());
|
||||||
|
|
||||||
const azureTile = await screen.findByTestId('upload-azure');
|
const azureTile = await screen.findByTestId('upload-azure');
|
||||||
user.click(azureTile); // select
|
user.click(azureTile); // select
|
||||||
|
await waitFor(() => expect(nextButton).toBeEnabled());
|
||||||
user.click(azureTile); // deselect
|
user.click(azureTile); // deselect
|
||||||
|
|
||||||
await waitFor(() => expect(nextButton).toBeDisabled());
|
await waitFor(() => expect(nextButton).toBeDisabled());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue