|
- import * as React from 'react';
- import {
- render,
- screen
- } from '@testing-library/react';
- import '@testing-library/jest-dom';
- import userEvent from '@testing-library/user-event';
- import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol';
- import { vi } from 'vitest';
- import { RadioTickBox } from '.';
-
- vi.mock('@tesseract-design/web-base-checkcontrol');
-
- describe('RadioTickBox', () => {
- it('renders a radio button', () => {
- render(
- <RadioTickBox />
- );
- const checkbox = screen.getByRole('radio');
- expect(checkbox).toBeInTheDocument();
- });
-
- it('renders a compact tick box', () => {
- render(
- <RadioTickBox
- compact
- />
- );
-
- expect(CheckControlBase.CheckIndicatorArea).toBeCalledWith(expect.objectContaining({
- compact: true,
- }));
- });
-
- it('renders a block tick box', () => {
- render(
- <RadioTickBox
- block
- />
- );
-
- expect(CheckControlBase.ClickAreaWrapper).toBeCalledWith(expect.objectContaining({
- block: true,
- }));
- });
-
- it('renders a subtext', () => {
- render(
- <RadioTickBox
- subtext="subtext"
- />
- );
- const subtext: HTMLElement = screen.getByTestId('subtext');
- expect(subtext).toBeInTheDocument();
- });
-
- it('handles click events', () => {
- const onClick = vi.fn().mockImplementationOnce((e) => { e.preventDefault(); })
- render(
- <RadioTickBox
- onClick={onClick}
- />
- );
- const radio: HTMLInputElement = screen.getByRole('radio');
- userEvent.click(radio);
- expect(onClick).toBeCalled();
- });
-
- it('handles change events', () => {
- const onChange = vi.fn().mockImplementationOnce((e) => { e.preventDefault(); })
- render(
- <RadioTickBox
- onChange={onChange}
- />
- );
- const radio: HTMLInputElement = screen.getByRole('radio');
- userEvent.click(radio);
- expect(onChange).toBeCalled();
- });
- });
|