Skip to content

Commit

Permalink
test(react): add tests for onclick prop of additional field
Browse files Browse the repository at this point in the history
add tests for adding a callback to the onclick event of a component in the additional field slot

test #2514
  • Loading branch information
lz405 authored and gd2910 committed Nov 25, 2024
1 parent 7663b13 commit 4c3e3c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/react/src/component-tests/IcRadio/IcRadio.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ describe("IcRadio end-to-end tests", () => {
cy.get(TEXT_FIELD_SELECTOR).eq(2).should("be.visible");
});

it("should call onclick function of component in additional-field slot when slotted component is clicked", () => {
mount(<ConditionalDynamic />);
cy.get(RADIO_SELECTOR).eq(0).find(".container").click();
cy.get(TEXT_FIELD_SELECTOR).eq(0).click();
cy.spy(window.console, "log").as("spyWinConsoleLog");
cy.get("@spyWinConsoleLog").should(
HAVE_BEEN_CALLED_WITH,
"Textfield clicked"
);
});

it("should emit icChange and icCheck events when radio option is selected", () => {
mount(<Default />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ export const ConditionalStatic = () => {
};

export const ConditionalDynamic = () => {
const handleTextfieldClicked = () => {
console.log("Textfield clicked");
};
return (
<div style={{ padding: "10px" }}>
<IcRadioGroup
Expand All @@ -329,6 +332,7 @@ export const ConditionalDynamic = () => {
slot="additional-field"
placeholder="Placeholder"
label="What's your favourite type of coffee?"
onClick={handleTextfieldClicked}
/>
</IcRadioOption>
<IcRadioOption
Expand Down

0 comments on commit 4c3e3c6

Please sign in to comment.