mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-21 00:21:49 +00:00
test(ui): scope lifecycle assertions with within instead of parentElement
The four .parentElement reads in the new lifecycle tests pushed testing-library/no-node-access to 712 against a 707 budget, failing frontend-lint. The rows now carry data-testid="lifecycle-row" and the test picks a row with within(), which keeps the assertion tied to the specific row rather than the whole panel and takes the count back to 707.
This commit is contained in:
parent
d20469b0dd
commit
8bb496154a
2 changed files with 14 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { renderWithProviders, screen, waitFor } from "../../../../tests/test-utils";
|
||||
import { renderWithProviders, screen, waitFor, within } from "../../../../tests/test-utils";
|
||||
import {
|
||||
GuardrailInformation,
|
||||
makeBedrockResponse,
|
||||
|
|
@ -122,13 +122,19 @@ describe("GuardrailViewer", () => {
|
|||
const ran = makeGuardrailInformation(ranPostCall);
|
||||
renderWithProviders(<GuardrailViewer data={[untimed, ran]} />);
|
||||
|
||||
expect(screen.getByText("Request received").parentElement).toHaveTextContent("T+0ms");
|
||||
expect(screen.getByText(/Post-call guardrail: ran-rail/).parentElement).toHaveTextContent("T+250ms");
|
||||
expect(screen.getByText("Response returned").parentElement).toHaveTextContent("T+251ms");
|
||||
const lifecycleRow = (label: string | RegExp): HTMLElement => {
|
||||
const row = screen.getAllByTestId("lifecycle-row").find((r) => within(r).queryByText(label) !== null);
|
||||
if (row === undefined) throw new Error(`no lifecycle row labelled ${label}`);
|
||||
return row;
|
||||
};
|
||||
|
||||
const untimedRow = screen.getByText(/Pre-call guardrail: conduct/).parentElement;
|
||||
expect(untimedRow).toHaveTextContent("—");
|
||||
expect(untimedRow).not.toHaveTextContent(/T\+/);
|
||||
expect(within(lifecycleRow("Request received")).getByText("T+0ms")).toBeInTheDocument();
|
||||
expect(within(lifecycleRow(/Post-call guardrail: ran-rail/)).getByText("T+250ms")).toBeInTheDocument();
|
||||
expect(within(lifecycleRow("Response returned")).getByText("T+251ms")).toBeInTheDocument();
|
||||
|
||||
const untimedRow = within(lifecycleRow(/Pre-call guardrail: conduct/));
|
||||
expect(untimedRow.getByText("—")).toBeInTheDocument();
|
||||
expect(untimedRow.queryByText(/^T\+/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calculates and displays masked entity totals", async () => {
|
||||
|
|
|
|||
|
|
@ -454,7 +454,7 @@ const RequestLifecycle = ({ entries }: { entries: GuardrailInformation[] }) => {
|
|||
<h4 className="text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4">Request Lifecycle</h4>
|
||||
<div className="relative">
|
||||
{timeline.map((item, idx) => (
|
||||
<div key={idx} className="flex items-start gap-3 relative">
|
||||
<div key={idx} data-testid="lifecycle-row" className="flex items-start gap-3 relative">
|
||||
{/* Vertical line */}
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="shrink-0">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue