Skip to content

Commit

Permalink
test: 토글 컴포넌트 변경된 props에 따른 테스트 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ghdtjgus76 committed May 25, 2024
1 parent 7641049 commit 54c2e07
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/wow-ui/src/components/Switch/Switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,50 @@ describe("disabled", () => {
});
});
});

describe("external control and events", () => {
let rendered: RenderResult;

it("should fire external onClick event", async () => {
rendered = render(<Switch />);
const switchComponent = rendered.getByRole("checkbox");
const onClickHandler = jest.fn();
switchComponent.onclick = onClickHandler;

fireEvent.click(switchComponent);

await waitFor(() => {
expect(onClickHandler).toHaveBeenCalled();
});
});

it("should fire external onKeyDown event", async () => {
rendered = render(<Switch />);
const switchComponent = rendered.getByRole("checkbox");
const onKeyDownHandler = jest.fn();
switchComponent.onkeydown = onKeyDownHandler;

fireEvent.type(switchComponent, "{enter}");

await waitFor(() => {
expect(onKeyDownHandler).toHaveBeenCalled();
});
});

it("should toggle external checked state when onClick event fired", async () => {
let isChecked = false;
const handleChange = () => {
isChecked = !isChecked;
};
const rendered = render(<Switch isChecked={isChecked} />);
const switchComponent = rendered.getByRole("checkbox");
switchComponent.onchange = handleChange;

fireEvent.click(switchComponent);

await waitFor(() => {
expect(switchComponent).toHaveAttribute("aria-checked", "true");
expect(switchComponent).toHaveAttribute("aria-disabled", "false");
});
});
});

0 comments on commit 54c2e07

Please sign in to comment.