153 lines
6 KiB
TypeScript
153 lines
6 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
const PERSONAS = [
|
|
{ code: "P4", model: "vignette-p4-live2d", defaultExpression: "anxious" },
|
|
{ code: "P5", model: "vignette-p5-live2d", defaultExpression: "guarded" },
|
|
{ code: "P6", model: "vignette-p6-live2d", defaultExpression: "conflicted" },
|
|
{ code: "P7", model: "vignette-p7-live2d", defaultExpression: "tired" },
|
|
] as const;
|
|
|
|
const REQUIRED_EXPRESSIONS = ["joy", "sad", "angry", "rage"] as const;
|
|
|
|
const REQUIRED_EXPRESSION_SNAPSHOTS = PERSONAS.flatMap((persona) =>
|
|
REQUIRED_EXPRESSIONS.map((expression) => ({
|
|
personaCode: persona.code,
|
|
expression,
|
|
motionFile: `expressions/${expression}.exp3.json`,
|
|
fadeInMs: "260",
|
|
affect: expression,
|
|
live2dMotion: expression,
|
|
live2dMotionFile: `expressions/${expression}.exp3.json`,
|
|
live2dExpressionCount: "28",
|
|
animated: "false",
|
|
})),
|
|
);
|
|
|
|
test.describe("avatar expression lab", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.route("**/api/auth/me", (route) =>
|
|
route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({
|
|
user_id: "avatar-lab-learner",
|
|
email: "learner@hs.ac.kr",
|
|
display_name: "Avatar Lab Learner",
|
|
role: "learner",
|
|
cohort_ids: [],
|
|
onboarding_completed_at: Math.floor(Date.now() / 1000),
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
test("renders every P4-P7 expression motion as a visible first-party avatar preview", async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(90_000);
|
|
await page.emulateMedia({ reducedMotion: "reduce" });
|
|
await page.goto("/learn/avatar-expressions");
|
|
|
|
const lab = page.locator('[data-avatar-expression-lab="true"]');
|
|
await expect(lab).toBeVisible({ timeout: 20_000 });
|
|
await expect(lab).toHaveAttribute("data-persona-count", "4");
|
|
await expect(lab).toHaveAttribute("data-expression-count", "28");
|
|
await expect(lab).toHaveAttribute("data-rendered-avatar-count", "112");
|
|
|
|
const panels = page.locator('[data-persona-expression-panel="true"]');
|
|
await expect
|
|
.poll(
|
|
() =>
|
|
panels.evaluateAll(
|
|
(elements, expressions) =>
|
|
elements.flatMap((panel) =>
|
|
expressions.map((expression) => {
|
|
const card = panel.querySelector(`[data-expression-card="true"][data-expression="${expression}"]`);
|
|
const avatar = card?.querySelector(".vg-avatar");
|
|
return {
|
|
personaCode: panel.getAttribute("data-persona-code"),
|
|
expression,
|
|
motionFile: card?.getAttribute("data-motion-file"),
|
|
fadeInMs: card?.getAttribute("data-fade-in-ms"),
|
|
affect: avatar?.getAttribute("data-affect"),
|
|
live2dMotion: avatar?.getAttribute("data-live2d-motion"),
|
|
live2dMotionFile: avatar?.getAttribute("data-live2d-motion-file"),
|
|
live2dExpressionCount: avatar?.getAttribute("data-live2d-expression-count"),
|
|
animated: avatar?.getAttribute("data-avatar-animated"),
|
|
};
|
|
}),
|
|
),
|
|
REQUIRED_EXPRESSIONS,
|
|
),
|
|
{ timeout: 20_000 },
|
|
)
|
|
.toEqual(REQUIRED_EXPRESSION_SNAPSHOTS);
|
|
|
|
for (const persona of PERSONAS) {
|
|
const panel = page.locator(
|
|
`[data-persona-expression-panel="true"][data-persona-code="${persona.code}"]`,
|
|
);
|
|
const code = persona.code.toLowerCase();
|
|
|
|
await expect(panel).toHaveAttribute("data-expression-count", "28");
|
|
await expect(panel).toHaveAttribute("data-live2d-model", persona.model);
|
|
await expect(panel).toHaveAttribute(
|
|
"data-live2d-model-url",
|
|
`/live2d/personas/${code}/${code}.model3.json`,
|
|
);
|
|
await expect(panel.locator('[data-expression-card="true"]')).toHaveCount(28);
|
|
|
|
const cardRenderers = panel.locator(
|
|
'.axl__card .vg-avatar [data-avatar-renderer="linocut"]',
|
|
);
|
|
await expect(cardRenderers).toHaveCount(28);
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
cardRenderers.evaluateAll(
|
|
(els) => els.filter((el) => el.getAttribute("data-load-state") === "ready").length,
|
|
),
|
|
{ timeout: 20_000 },
|
|
)
|
|
.toBe(28);
|
|
|
|
const sectionMetrics = await panel.evaluate((el) => {
|
|
const avatars = Array.from(el.querySelectorAll<HTMLElement>(".axl__card .vg-avatar"));
|
|
const invalid = avatars
|
|
.map((avatar) => {
|
|
const renderer = avatar.querySelector<HTMLElement>('[data-avatar-renderer="linocut"]');
|
|
const svg = avatar.querySelector(".linocut-avatar");
|
|
return {
|
|
affect: avatar.getAttribute("data-affect"),
|
|
loadState: renderer?.getAttribute("data-load-state"),
|
|
svgBox: svg?.getBoundingClientRect().toJSON(),
|
|
};
|
|
})
|
|
.filter((item) => {
|
|
return (
|
|
item.loadState !== "ready" ||
|
|
!item.svgBox ||
|
|
item.svgBox.width <= 0 ||
|
|
item.svgBox.height <= 0
|
|
);
|
|
});
|
|
|
|
return {
|
|
avatarCount: avatars.length,
|
|
animatedCount: avatars.filter((avatar) => avatar.getAttribute("data-avatar-animated") === "true")
|
|
.length,
|
|
invalid,
|
|
};
|
|
});
|
|
|
|
expect(sectionMetrics.avatarCount, `${persona.code} rendered expression avatars`).toBe(28);
|
|
expect(sectionMetrics.animatedCount, `${persona.code} QA avatars should be static`).toBe(0);
|
|
expect(sectionMetrics.invalid, `${persona.code} visible avatar geometry`).toEqual([]);
|
|
|
|
const defaultAvatar = panel.locator(".axl__persona-head .vg-avatar").first();
|
|
await expect(defaultAvatar).toHaveAttribute("data-affect", persona.defaultExpression);
|
|
await expect(defaultAvatar).toHaveAttribute("data-live2d-model", persona.model);
|
|
await expect(defaultAvatar).toHaveAttribute("data-live2d-expression-count", "28");
|
|
}
|
|
});
|
|
});
|