Files
short-video-viral-replicator/agent-studio-mini/apps/web/tests/monitoring.test.tsx
T

22 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {afterEach,it,expect,vi} from "vitest";
import {cleanup,render,screen,fireEvent} from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import {Monitoring} from "../src/Monitoring.js";
afterEach(()=>{cleanup();vi.unstubAllGlobals();});
it("shows creative evidence separately and preserves failure warnings",async()=>{
vi.stubGlobal("fetch",vi.fn(async()=>({ok:true,json:async()=>({settings:{enabled:false,minSpend:100,minOrders:5,minImpressions:1000,staleHours:12,fatigueCtrDrop:25,fatigueViewDrop:20,fatigueMinClicks:30},rows:[],accounts:[{id:"a",tenant:"t",name:"Test account",count:0,excluded:0,fatigueError:"素材结果被截断"}],fatigueRows:[{key:"k",id:"video-1",campaignId:"c",variant:"ADS_AND_ORGANIC",state:"creative_decline",reason:"疲劳证据不足",suggestions:["人工核实"],handled:false,period:"3日对比7日",account:{id:"a",tenant:"t",name:"Test account"},ctrDrop:50,viewDrop:null,recent:{ctr:.05,impressions:3000,clicks:150,days:3},baseline:{ctr:.1,impressions:7000,clicks:700,days:7}}]})})));
render(<Monitoring onClose={()=>{}}/>);
await screen.findByText("素材 CTR 相对降幅(%");
fireEvent.click(screen.getByRole("button",{name:"素材疲劳预警"}));
expect(screen.getByText(/素材 video-1/)).toBeInTheDocument();
expect(screen.getByText(/素材结果被截断/)).toBeInTheDocument();
expect(screen.getByText(/6秒观看率相对降幅 无有效数据/)).toBeInTheDocument();
});
it("returns to the workspace from the monitoring dialog",()=>{
vi.stubGlobal("fetch",vi.fn(async()=>({ok:true,json:async()=>({settings:{enabled:false,minSpend:100,minOrders:5,minImpressions:1000,staleHours:12,fatigueCtrDrop:25,fatigueViewDrop:20,fatigueMinClicks:30},rows:[],accounts:[],fatigueRows:[],newAlerts:0})})));
const onClose=vi.fn();
render(<Monitoring onClose={onClose}/>);
fireEvent.click(screen.getByRole("button",{name:"返回工作台"}));
expect(onClose).toHaveBeenCalledOnce();
});