Design system.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 lines
1.9 KiB

  1. import * as React from 'react';
  2. import {
  3. render,
  4. screen
  5. } from '@testing-library/react';
  6. import '@testing-library/jest-dom';
  7. import userEvent from '@testing-library/user-event';
  8. import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol';
  9. import { vi } from 'vitest';
  10. import { ToggleSwitch } from '.';
  11. vi.mock('@tesseract-design/web-base-checkcontrol');
  12. describe('ToggleSwitch', () => {
  13. it('renders a checkbox', () => {
  14. render(
  15. <ToggleSwitch />
  16. );
  17. const checkbox = screen.getByRole('checkbox');
  18. expect(checkbox).toBeInTheDocument();
  19. });
  20. it('renders a compact switch', () => {
  21. render(
  22. <ToggleSwitch
  23. compact
  24. />
  25. );
  26. expect(CheckControlBase.CheckIndicatorArea).toBeCalledWith(expect.objectContaining({
  27. compact: true,
  28. }));
  29. });
  30. it('renders a block switch', () => {
  31. render(
  32. <ToggleSwitch
  33. block
  34. />
  35. );
  36. expect(CheckControlBase.ClickAreaWrapper).toBeCalledWith(expect.objectContaining({
  37. block: true,
  38. }));
  39. });
  40. it('renders a subtext', () => {
  41. render(
  42. <ToggleSwitch
  43. subtext="subtext"
  44. />
  45. );
  46. const subtext: HTMLElement = screen.getByTestId('subtext');
  47. expect(subtext).toBeInTheDocument();
  48. });
  49. it('handles click events', () => {
  50. const onClick = vi.fn().mockImplementationOnce((e) => { e.preventDefault(); })
  51. render(
  52. <ToggleSwitch
  53. onClick={onClick}
  54. />
  55. );
  56. const checkbox: HTMLInputElement = screen.getByRole('checkbox');
  57. userEvent.click(checkbox);
  58. expect(onClick).toBeCalled();
  59. });
  60. it('handles change events', () => {
  61. const onChange = vi.fn().mockImplementationOnce((e) => { e.preventDefault(); })
  62. render(
  63. <ToggleSwitch
  64. onChange={onChange}
  65. />
  66. );
  67. const checkbox: HTMLInputElement = screen.getByRole('checkbox');
  68. userEvent.click(checkbox);
  69. expect(onChange).toBeCalled();
  70. });
  71. });