puerto 0.23.0

Puerto — Rust full-stack DDD framework CLI. Scaffolds Clean Architecture projects with auto-wired DI, SQLx support, and zero manual wiring. Formerly puerto-framework.
import { describe, expect, test } from "bun:test";
import { fireEvent, screen } from "@testing-library/react";
import { apiFalsa } from "../../../pruebas/api-falsa";
{% if access.create_roles -%}
import { MadreUsuarioActual } from "../../../pruebas/auth";
{% endif -%}
import { coleccion{{ pascal }}, Madre{{ pascal }} } from "../../../pruebas/{{ kebab }}";
import { renderizarPantalla } from "../../../pruebas/renderizar";
import { ContenedorLista{{ pascal }} } from "./lista-{{ kebab }}";

describe("ContenedorLista{{ pascal }}", () => {
  test("debería mostrar una fila por cada {{ words }}", async () => {
    // Preparar
    const semilla = [Madre{{ pascal }}.aleatorio(), Madre{{ pascal }}.aleatorio()];
    const api = apiFalsa([coleccion{{ pascal }}(semilla)]);

    // Actuar
    renderizarPantalla(<ContenedorLista{{ pascal }} />, { api });

    // Comprobar
    expect(await screen.findAllByText("Ver")).toHaveLength(2);
  });

  test("debería mostrar la página siguiente cuando se pulsa Siguiente", async () => {
    // Preparar
    const semilla = Array.from({ length: 25 }, () => Madre{{ pascal }}.aleatorio());
    const api = apiFalsa([coleccion{{ pascal }}(semilla)]);
    renderizarPantalla(<ContenedorLista{{ pascal }} />, { api });
    expect(await screen.findAllByText("Ver")).toHaveLength(20);

    // Actuar
    fireEvent.click(screen.getByRole("button", { name: "Siguiente" }));

    // Comprobar
    expect(await screen.findByText("21–25 de 25")).toBeTruthy();
    expect(screen.getAllByText("Ver")).toHaveLength(5);
  });

  test("debería abrir la página que nombra la URL", async () => {
    // Preparar
    const semilla = Array.from({ length: 25 }, () => Madre{{ pascal }}.aleatorio());
    const api = apiFalsa([coleccion{{ pascal }}(semilla)]);
    const ruta = "/{{ plural }}?pagina=2";

    // Actuar
    renderizarPantalla(<ContenedorLista{{ pascal }} />, { api }, ruta);

    // Comprobar
    expect(await screen.findByText("21–25 de 25")).toBeTruthy();
  });

  test("debería decirlo cuando no hay {{ words_plural }}", async () => {
    // Preparar
    const api = apiFalsa([coleccion{{ pascal }}()]);

    // Actuar
    renderizarPantalla(<ContenedorLista{{ pascal }} />, { api });

    // Comprobar
    expect(await screen.findByText("Todavía no hay {{ words_plural }}.")).toBeTruthy();
  });

  test("debería mostrar el código del error cuando la API no da la lista", async () => {
    // Preparar
    const fallos = { "GET /{{ plural }}": "{{ snake }}.repositorio" };
    const api = apiFalsa([coleccion{{ pascal }}()], fallos);

    // Actuar
    renderizarPantalla(<ContenedorLista{{ pascal }} />, { api });

    // Comprobar
    expect((await screen.findByRole("alert")).textContent).toBe("{{ snake }}.repositorio");
  });
{%- if access.create_roles %}

  test("no debería ofrecer Crear a quien no tiene su rol", async () => {
    // Preparar
    const api = apiFalsa([coleccion{{ pascal }}([Madre{{ pascal }}.aleatorio()])]);
    const usuario = MadreUsuarioActual.aleatorio();

    // Actuar
    renderizarPantalla(<ContenedorLista{{ pascal }} />, { api }, "/", { usuario });

    // Comprobar
    expect(await screen.findByText("Ver")).toBeTruthy();
    expect(screen.queryByText("Crear {{ words }}")).toBeNull();
  });
{%- endif %}
});