Design system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

86 lines
1.6 KiB

  1. import * as React from 'react';
  2. import {
  3. render,
  4. screen,
  5. cleanup,
  6. } from '@testing-library/react';
  7. import userEvent from '@testing-library/user-event';
  8. import {
  9. vi,
  10. describe,
  11. it,
  12. expect,
  13. afterEach,
  14. } from 'vitest';
  15. import matchers from '@testing-library/jest-dom/matchers';
  16. import {
  17. FileSelectBox,
  18. FileSelectBoxDerivedElement,
  19. } from '.';
  20. expect.extend(matchers);
  21. describe('FileSelectBox', () => {
  22. afterEach(() => {
  23. cleanup();
  24. });
  25. it('renders a file input', () => {
  26. render(
  27. <FileSelectBox />,
  28. );
  29. const input = screen.getByTestId('input');
  30. expect(input).toBeInTheDocument();
  31. });
  32. it('renders a border', () => {
  33. render(
  34. <FileSelectBox
  35. border
  36. />,
  37. );
  38. const border = screen.getByTestId('border');
  39. expect(border).toBeInTheDocument();
  40. });
  41. it('renders a label', () => {
  42. render(
  43. <FileSelectBox
  44. label="foo"
  45. />,
  46. );
  47. const textbox = screen.getByLabelText('foo');
  48. expect(textbox).toBeInTheDocument();
  49. const label = screen.getByTestId('label');
  50. expect(label).toHaveTextContent('foo');
  51. });
  52. it('renders a hidden label', () => {
  53. render(
  54. <FileSelectBox
  55. label="foo"
  56. hiddenLabel
  57. />,
  58. );
  59. const textbox = screen.getByLabelText('foo');
  60. expect(textbox).toBeInTheDocument();
  61. const label = screen.queryByTestId('label');
  62. expect(label).toBeInTheDocument();
  63. expect(label).toHaveClass('sr-only');
  64. });
  65. describe('enhanced', () => {
  66. it('renders a hint', () => {
  67. render(
  68. <FileSelectBox
  69. enhanced
  70. hint="foo"
  71. />,
  72. );
  73. const hint = screen.getByTestId('hint');
  74. expect(hint).toBeInTheDocument();
  75. });
  76. });
  77. });