feat(asset): animate asset detail drawer
This commit is contained in:
@@ -395,6 +395,167 @@ const server = http.createServer(async (req, res) => {
|
||||
await page.goto(origin + "/asset/");
|
||||
await page.locator("#am-total").filter({ hasText: "30" }).waitFor();
|
||||
assert.equal(await page.locator("#am-rows tr").count(), 25);
|
||||
// 실제 브라우저의 애니메이션 시각을 고정해 중간 위치와 닫기 완료 시점을 확인합니다.
|
||||
await page.evaluate(() => {
|
||||
const drawer = document.querySelector("#am-detail"),
|
||||
animate = drawer.animate.bind(drawer);
|
||||
drawer.animate = (frames, options) => {
|
||||
const motion = animate(frames, options);
|
||||
motion.pause();
|
||||
return motion;
|
||||
};
|
||||
});
|
||||
const finishDrawer = () =>
|
||||
page.evaluate(async () => {
|
||||
const motion = document
|
||||
.querySelector("#am-detail")
|
||||
.getAnimations()
|
||||
.find((a) => a.id === "asset-drawer");
|
||||
if (motion) {
|
||||
motion.finish();
|
||||
await motion.finished;
|
||||
}
|
||||
});
|
||||
const drawerPosition = (time) =>
|
||||
page.evaluate((time) => {
|
||||
const drawer = document.querySelector("#am-detail"),
|
||||
motion = drawer
|
||||
.getAnimations()
|
||||
.find((a) => a.id === "asset-drawer");
|
||||
if (time !== null) motion.currentTime = time;
|
||||
const rect = drawer.getBoundingClientRect();
|
||||
return {
|
||||
left: rect.left,
|
||||
width: rect.width,
|
||||
viewport: innerWidth,
|
||||
open: drawer.open,
|
||||
closing: drawer.classList.contains("am-closing"),
|
||||
};
|
||||
}, time);
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelector("#am-detail-title").textContent ===
|
||||
"KING-DESKTOP",
|
||||
);
|
||||
const entryStart = await drawerPosition(0),
|
||||
entryMiddle = await drawerPosition(140);
|
||||
assert.ok(
|
||||
Math.abs(entryStart.left - entryStart.viewport) < 2,
|
||||
"entry starts beyond the right screen edge",
|
||||
);
|
||||
assert.ok(
|
||||
entryMiddle.left < entryStart.left &&
|
||||
entryMiddle.left > entryStart.viewport - entryStart.width,
|
||||
"entry moves from right to left",
|
||||
);
|
||||
await finishDrawer();
|
||||
const atRest = await drawerPosition(null);
|
||||
assert.ok(Math.abs(atRest.left - (atRest.viewport - atRest.width)) < 2);
|
||||
await page.locator('[data-close="am-detail"]').click();
|
||||
const exitStart = await drawerPosition(0),
|
||||
exitMiddle = await drawerPosition(110);
|
||||
assert.ok(
|
||||
exitStart.open && exitStart.closing,
|
||||
"X retains the drawer until animation completion",
|
||||
);
|
||||
assert.ok(exitMiddle.left > exitStart.left, "exit moves back to the right");
|
||||
await finishDrawer();
|
||||
assert.equal(
|
||||
await page.locator("#am-detail").evaluate((el) => el.open),
|
||||
false,
|
||||
);
|
||||
assert.equal(new URL(page.url()).searchParams.has("asset"), false);
|
||||
assert.equal(
|
||||
await page.evaluate(() => document.activeElement.dataset.open),
|
||||
"asset0",
|
||||
"focus returns to the selected asset",
|
||||
);
|
||||
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
await finishDrawer();
|
||||
const rect = await page.locator("#am-detail").boundingBox();
|
||||
await page.mouse.move(rect.x + 100, 300);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(10, 300);
|
||||
await page.mouse.up();
|
||||
assert.equal(
|
||||
(await drawerPosition(null)).closing,
|
||||
false,
|
||||
"inside-to-outside drag must not dismiss",
|
||||
);
|
||||
await page.mouse.click(10, 400);
|
||||
assert.equal(
|
||||
(await drawerPosition(80)).closing,
|
||||
true,
|
||||
"backdrop click starts animated dismissal",
|
||||
);
|
||||
// 닫기 도중 다시 열면 취소한 닫기의 완료 콜백이 새 패널을 닫지 않습니다.
|
||||
const interrupted = await drawerPosition(null);
|
||||
await page.evaluate(() =>
|
||||
document.querySelector('#am-rows [data-open="asset0"]').click(),
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs((await drawerPosition(0)).left - interrupted.left) < 2,
|
||||
"reopen continues from the current position",
|
||||
);
|
||||
await finishDrawer();
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelector("#am-detail-title").textContent ===
|
||||
"KING-DESKTOP",
|
||||
);
|
||||
assert.equal((await drawerPosition(null)).closing, false);
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(
|
||||
(await drawerPosition(110)).closing,
|
||||
true,
|
||||
"Escape uses the same exit animation",
|
||||
);
|
||||
await finishDrawer();
|
||||
|
||||
// 닫힌 뒤 도착하는 응답이 패널을 다시 열거나 선택 URL을 복구하지 않습니다.
|
||||
await page.route("**/asset/api/assets/asset0", async (route) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
await route.continue();
|
||||
});
|
||||
const delayedResponse = page.waitForResponse((response) =>
|
||||
response.url().endsWith("/asset/api/assets/asset0"),
|
||||
);
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
await drawerPosition(100);
|
||||
await page.evaluate(() =>
|
||||
document.querySelector('[data-close="am-detail"]').click(),
|
||||
);
|
||||
await finishDrawer();
|
||||
await delayedResponse;
|
||||
await page.evaluate(
|
||||
() => new Promise((resolve) => requestAnimationFrame(resolve)),
|
||||
);
|
||||
assert.equal(
|
||||
await page.locator("#am-detail").evaluate((el) => el.open),
|
||||
false,
|
||||
);
|
||||
assert.equal(new URL(page.url()).searchParams.has("asset"), false);
|
||||
await page.unroute("**/asset/api/assets/asset0");
|
||||
|
||||
await page.emulateMedia({ reducedMotion: "reduce" });
|
||||
await page.locator('[data-open="asset0"]').first().click();
|
||||
assert.equal(
|
||||
await page
|
||||
.locator("#am-detail")
|
||||
.evaluate((el) => el.getAnimations().length),
|
||||
0,
|
||||
);
|
||||
await page.locator('[data-close="am-detail"]').click();
|
||||
assert.equal(
|
||||
await page.locator("#am-detail").evaluate((el) => el.open),
|
||||
false,
|
||||
);
|
||||
await page.emulateMedia({ reducedMotion: "no-preference" });
|
||||
await page.evaluate(() => {
|
||||
delete document.querySelector("#am-detail").animate;
|
||||
});
|
||||
await page.screenshot({
|
||||
path: path.join(OUT, "asset-desktop.png"),
|
||||
fullPage: true,
|
||||
@@ -591,13 +752,11 @@ const server = http.createServer(async (req, res) => {
|
||||
await page.screenshot({ path: path.join(OUT, "asset-monitor-links.png") });
|
||||
await page.locator('[data-detail-tab="overview"]').click();
|
||||
await page.locator("[data-photo]").click();
|
||||
await page
|
||||
.locator("#am-photo-file")
|
||||
.setInputFiles({
|
||||
name: "test.png",
|
||||
mimeType: "image/png",
|
||||
buffer: photoPNG,
|
||||
});
|
||||
await page.locator("#am-photo-file").setInputFiles({
|
||||
name: "test.png",
|
||||
mimeType: "image/png",
|
||||
buffer: photoPNG,
|
||||
});
|
||||
await page.locator('#am-photo-form [type="submit"]').click();
|
||||
await page.waitForFunction(() => !document.querySelector("#am-photo").open);
|
||||
await page.locator('.am-photo-grid img[alt="test.png"]').waitFor();
|
||||
@@ -677,7 +836,7 @@ const server = http.createServer(async (req, res) => {
|
||||
);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
"ALL PASS: Chrome desktop/mobile, search races, paging, specs, XSS escaping, conflict draft, create, checkout/checkin, reports, setup mode, photos, monitor registration/link/overview, super-admin deletion",
|
||||
"ALL PASS: Chrome desktop/mobile, drawer entry/exit/backdrop/X/Escape, interrupt/reopen, late responses, reduced motion, search races, paging, specs, XSS escaping, conflict draft, create, checkout/checkin, reports, setup mode, photos, monitor registration/link/overview, super-admin deletion",
|
||||
);
|
||||
} finally {
|
||||
await browser?.close();
|
||||
|
||||
Reference in New Issue
Block a user