Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.8 kB
1
Indexable
Never
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import Recipes from '../../Components/Recipes'; // Importe o componente Recipes
import Meals from '../../Components/Meals';

test('Renderização inicial do componente Recipes', () => {
  render(
    <MemoryRouter>
      <Recipes />
    </MemoryRouter>,
  );
  const titleElement = screen.getByText('RECEITAS');
  expect(titleElement).toBeInTheDocument();
});

test('Teste de botões de filtro', () => {
  const categories = [
    { strCategory: 'Breakfast' },
    { strCategory: 'Goat' },
    // Adicione mais categorias conforme necessário
  ];

  render(
    <MemoryRouter>
      <Meals />
    </MemoryRouter>,
  );

  categories.forEach((category) => {
    const buttonElement = screen.getByTestId(`${category.strCategory}-category-filter`);
    setTimeout(() => {
      expect(buttonElement).toBeInTheDocument();
    }, 2000);
  });
});

test('Teste de cards de receita', () => {
  const recipes = [
    { strMeal: 'Receita1', strMealThumb: 'imagem1' },
    { strDrink: 'Receita2', strDrinkThumb: 'imagem2' },
    // Adicione mais receitas conforme necessário
  ];

  render(
    <MemoryRouter>
      <Meals />
    </MemoryRouter>,
  );

  recipes.forEach((recipe, index) => {
    const cardNameElement = screen.getByTestId(`${index}-card-name`);
    const cardImgElement = screen.getByTestId(`${index}-card-img`);

    expect(cardNameElement).toBeInTheDocument();
    expect(cardNameElement.textContent).toBe(recipe.strMeal || recipe.strDrink);
    expect(cardImgElement).toBeInTheDocument();
    expect(cardImgElement).toHaveAttribute('src', recipe.strMealThumb || recipe.strDrinkThumb);
  });
});

// Você pode adicionar mais testes conforme necessário