|
| 1 | +/** |
| 2 | + * 分组表「口径说明」的数据源必须与后端实际读的表一致。 |
| 3 | + * |
| 4 | + * 回归:凭证分组已改读 `usage_hourly_dim`(全维度小时汇总,永久保留), |
| 5 | + * 说明文案却还写「取自逐请求明细(仅保留 45 天)」,用户会把「永久可查」 |
| 6 | + * 读成「45 天后消失」,运维排障时误判数据缺失。 |
| 7 | + */ |
| 8 | +import { render, screen } from "@testing-library/react"; |
| 9 | +import { describe, expect, it } from "vitest"; |
| 10 | +import { userEvent } from "@/test-utils"; |
| 11 | +import { GroupStatsPanel } from "../GroupStatsPanel"; |
| 12 | +import { |
| 13 | + GROUP_DIMENSIONS, |
| 14 | + type GroupDimension, |
| 15 | + type GroupRow, |
| 16 | + type StatsSortState, |
| 17 | +} from "../constants"; |
| 18 | + |
| 19 | +const GROUP_SORT: StatsSortState = { |
| 20 | + sort: "requests", |
| 21 | + order: "desc", |
| 22 | + toggle: () => {}, |
| 23 | +}; |
| 24 | + |
| 25 | +function dimension(value: string): GroupDimension { |
| 26 | + const found = GROUP_DIMENSIONS.find((item) => item.value === value); |
| 27 | + if (!found) throw new Error(`未知分组维度: ${value}`); |
| 28 | + return found; |
| 29 | +} |
| 30 | + |
| 31 | +function renderPanel(value: string, rows: GroupRow[] = []) { |
| 32 | + const group = dimension(value); |
| 33 | + return render( |
| 34 | + <GroupStatsPanel |
| 35 | + groupDimension={group.value} |
| 36 | + groupDimensions={GROUP_DIMENSIONS} |
| 37 | + onGroupDimensionChange={() => {}} |
| 38 | + percentile="p95" |
| 39 | + onPercentileChange={() => {}} |
| 40 | + groupSort={GROUP_SORT} |
| 41 | + group={group} |
| 42 | + groupRows={rows} |
| 43 | + onDrill={() => {}} |
| 44 | + />, |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +/** 展开折叠的脚注并返回正文第一段(数据源那段)。 */ |
| 49 | +async function expandDataSourceParagraph(): Promise<HTMLElement> { |
| 50 | + await userEvent.click(screen.getByText("口径说明(数据源 · 延迟 · 速度)")); |
| 51 | + const paragraphs = screen.getByTestId("group-footnote").querySelectorAll("p"); |
| 52 | + expect(paragraphs.length).toBeGreaterThan(0); |
| 53 | + return paragraphs[0] as HTMLElement; |
| 54 | +} |
| 55 | + |
| 56 | +describe("分组表口径说明与数据源一致", () => { |
| 57 | + it("凭证分组:说明小时汇总永久保留,不再提 45 天", async () => { |
| 58 | + renderPanel("credential"); |
| 59 | + const source = await expandDataSourceParagraph(); |
| 60 | + expect(source).toHaveTextContent("凭证分组取自全维度小时汇总(永久保留,整点桶粒度)"); |
| 61 | + expect(source).toHaveTextContent("无凭证的预热失败等请求不计入"); |
| 62 | + expect(source).not.toHaveTextContent("逐请求明细"); |
| 63 | + expect(source.textContent).not.toContain("45 天"); |
| 64 | + }); |
| 65 | + |
| 66 | + it("渠道分组:仍写小时汇总永久保留", async () => { |
| 67 | + renderPanel("provider"); |
| 68 | + const source = await expandDataSourceParagraph(); |
| 69 | + expect(source).toHaveTextContent("各维度数据源为小时汇总(永久保留)"); |
| 70 | + expect(source).not.toHaveTextContent("凭证分组"); |
| 71 | + }); |
| 72 | +}); |
0 commit comments