MetaInfoText.test.tsx 1.1 KB

123456789101112131415161718192021222324252627
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { MetaInfoText, MetaItemProps } from './MetaInfoText';
  4. describe('MetaInfoText', () => {
  5. it('should render component and items', () => {
  6. const items: MetaItemProps[] = [
  7. { label: 'label', value: 'value' },
  8. { label: 'label2', value: 'value2' },
  9. ];
  10. render(<MetaInfoText metaItems={items} />);
  11. expect(screen.getAllByTestId('meta-info-text')).toHaveLength(1);
  12. expect(screen.getAllByTestId('meta-info-text-item')).toHaveLength(2);
  13. expect(screen.getByText('label:')).toBeInTheDocument();
  14. expect(screen.getByText('label2:')).toBeInTheDocument();
  15. expect(screen.getByText(/^value$/)).toBeInTheDocument();
  16. expect(screen.getByText(/^value2$/)).toBeInTheDocument();
  17. });
  18. it('should render component with no items when the array is empty', () => {
  19. const items: MetaItemProps[] = [];
  20. render(<MetaInfoText metaItems={items} />);
  21. expect(screen.getAllByTestId('meta-info-text')).toHaveLength(1);
  22. expect(screen.queryByTestId('meta-info-text-item')).toBeNull();
  23. });
  24. });