puerto 0.29.0

Puerto: la CLI de un framework full-stack DDD en Rust. Genera proyectos con Clean Architecture, la inyección de dependencias cableada sola y soporte de SQLx, sin cablear nada a mano. Antes, puerto-framework.
import { describe, expect, test } from "bun:test";
import { fireEvent, screen } from "@testing-library/react";
import { apiFalsa{% if owner_camel %}, coleccion{% endif %} } from "../../../pruebas/api-falsa";
{% if access.create_roles -%}
import { MadreUsuarioActual } from "../../../pruebas/auth";
{% endif -%}
{% for t in targets | filter(attribute="is_self", value=false) -%}
import { coleccion{{ t.pascal }}, Madre{{ t.pascal }} } from "../../../pruebas/{{ t.kebab }}";
{% endfor -%}
import { coleccion{{ pascal }}, Madre{{ pascal }} } from "../../../pruebas/{{ kebab }}";
import { renderizarPantalla } from "../../../pruebas/renderizar";
import { ContenedorLista{{ pascal }} } from "./lista-{{ kebab }}";

describe("ContenedorLista{{ pascal }}", () => {
{%- if owner_camel %}
  test("debería mostrar solo las propias cuando se le pide", async () => {
    // Preparar: `GET /mis_{{ plural }}` responde las de quien llama; la lista entera, otras
    const otras = coleccion{{ pascal }}([Madre{{ pascal }}.aleatorio(), Madre{{ pascal }}.aleatorio()]);
    const propias = coleccion("/mis_{{ plural }}", "{{ snake }}", [Madre{{ pascal }}.aleatorio()]);
    const api = apiFalsa([otras, propias]);

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

    // Comprobar
    expect(await screen.findByText("Mis {{ words_plural }}")).toBeTruthy();
    expect(await screen.findAllByText("Ver")).toHaveLength(1);
  });

{%- endif %}
  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 %}
{%- for r in references %}

  test("debería nombrar {{ r.label }} por su etiqueta", async () => {
    // Preparar
{%- if r.is_set %}
    const objetivo = Madre{{ r.target_pascal }}.aleatorio();
{%- if r.target_inline %}
    const sembrado = Madre{{ pascal }}.aleatorio({ {{ r.camel }}: [objetivo.id] });
{%- else %}
    const sembrado = Madre{{ pascal }}.aleatorio({
      {{ r.camel }}: [objetivo.id],
    });
{%- endif %}
{%- if r.is_self %}
    const api = apiFalsa([coleccion{{ pascal }}([sembrado, objetivo])]);
{%- elif r.api_inline %}
    const api = apiFalsa([coleccion{{ pascal }}([sembrado]), coleccion{{ r.target_pascal }}([objetivo])]);
{%- else %}
    const api = apiFalsa([
      coleccion{{ pascal }}([sembrado]),
      coleccion{{ r.target_pascal }}([objetivo]),
    ]);
{%- endif %}
{%- elif r.is_self %}
    const objetivo = Madre{{ pascal }}.aleatorio();
{%- if r.target_inline %}
    const sembrado = Madre{{ pascal }}.aleatorio({ {{ r.camel }}: objetivo.id });
{%- else %}
    const sembrado = Madre{{ pascal }}.aleatorio({
      {{ r.camel }}: objetivo.id,
    });
{%- endif %}
    const api = apiFalsa([coleccion{{ pascal }}([sembrado, objetivo])]);
{%- else %}
    const sembrado = Madre{{ pascal }}.aleatorio();
{%- if r.target_inline %}
    const objetivo = Madre{{ r.target_pascal }}.aleatorio({ id: sembrado.{{ r.camel }}{% if not r.required %} ?? crypto.randomUUID(){% endif %} });
{%- else %}
    const objetivo = Madre{{ r.target_pascal }}.aleatorio({
      id: sembrado.{{ r.camel }}{% if not r.required %} ?? crypto.randomUUID(){% endif %},
    });
{%- endif %}
{%- if r.api_inline %}
    const api = apiFalsa([coleccion{{ pascal }}([sembrado]), coleccion{{ r.target_pascal }}([objetivo])]);
{%- else %}
    const api = apiFalsa([
      coleccion{{ pascal }}([sembrado]),
      coleccion{{ r.target_pascal }}([objetivo]),
    ]);
{%- endif %}
{%- endif %}

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

{%- if r.ref_path %}
    // Comprobar: por su href; dos referencias al mismo objetivo pueden tener la misma etiqueta.
    const selector = `a[href="{{ r.ref_path }}/${% if r.is_set %}{objetivo.id}{% else %}{sembrado.{{ r.camel }}}{% endif %}"]`;
{%- else %}
    // Comprobar: sin enlace, un usuario no tiene página.
    const selector = "span";
{%- endif %}
    expect(await screen.findByText({{ r.target_label_of }}, { selector })).toBeTruthy();
  });
{%- endfor %}
{%- for r in references | filter(attribute="is_self", value=false) | filter(attribute="is_set", value=false) %}{% if loop.first %}

  test("debería nombrar {{ r.label }} por su id cuando no se puede cargar", async () => {
    // Preparar: sin {{ r.target_pascal }} en la API falsa, su lista responde un 404.
    const sembrado = Madre{{ pascal }}.aleatorio();
    const api = apiFalsa([coleccion{{ pascal }}([sembrado])]);

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

    // Comprobar
{%- if r.ref_path %}
    const selector = `a[href="{{ r.ref_path }}/${sembrado.{{ r.camel }}}"]`;
{%- else %}
    const selector = "span";
{%- endif %}
    expect(await screen.findByText(`${sembrado.{{ r.camel }}}`, { selector })).toBeTruthy();
  });
{%- endif %}{% endfor %}
});