import { describe, expect, test } from "bun:test";
import { screen } from "@testing-library/react";
{%- if roles %}
import { MadreUsuarioActual } from "../../../pruebas/auth";
{%- endif %}
import { renderizarPantalla } from "../../../pruebas/renderizar";
import { EnlaceCrear{{ pascal }} } from "./enlace-crear-{{ kebab }}";
describe("EnlaceCrear{{ pascal }}", () => {
test("debería llevar al formulario con lo que referencia ya elegido", async () => {
// Preparar
const id = crypto.randomUUID();
{{ seed_line }}
// Actuar
renderizarPantalla(pantalla, {});
// Comprobar
const ruta = `/{{ plural }}/nuevo?{{ first }}=${id}`;
expect((await screen.findByText("{{ label }}")).getAttribute("href")).toBe(ruta);
});
{%- if roles %}
test("no debería ofrecerlo a quien tiene sesión y no tiene su rol", async () => {
// Preparar
const usuario = MadreUsuarioActual.aleatorio();
const pantalla = (
<div>
<p>Al lado</p>
{{ other_line }}
</div>
);
// Actuar
renderizarPantalla(pantalla, {}, "/", { usuario });
// Comprobar
expect(await screen.findByText("Al lado")).toBeTruthy();
expect(screen.queryByText("{{ label }}")).toBeNull();
});
{%- endif %}
});