| ... | ... | @@ -281,10 +281,16 @@ describe("sidebar list motion", () => { |
| 281 | 281 | layout([b, fresh]); |
| 282 | 282 | motion.update(true); |
| 283 | 283 | expect(a.animations[0]!.cancel).toHaveBeenCalledOnce(); |
| 284 | | expect(fresh.animate).toHaveBeenLastCalledWith([{ opacity: 0 }, { opacity: 1 }], { |
| 285 | | duration: 150, |
| 286 | | easing: "ease-out", |
| 287 | | }); |
| 284 | expect(fresh.animate).toHaveBeenLastCalledWith( |
| 285 | [ |
| 286 | { opacity: 0, transform: "translateY(83px)" }, |
| 287 | { opacity: 1, transform: "translateY(0px)" }, |
| 288 | ], |
| 289 | { |
| 290 | duration: 150, |
| 291 | easing: "ease-out", |
| 292 | }, |
| 293 | ); |
| 288 | 294 | const clone = a.clones[0]!; |
| 289 | 295 | expect(clone.style).toMatchObject({ |
| 290 | 296 | position: "absolute", |
| ... | ... | @@ -299,10 +305,16 @@ describe("sidebar list motion", () => { |
| 299 | 305 | expect(clone.attributes).toEqual([{ name: "aria-hidden", value: "true" }]); |
| 300 | 306 | expect(clone.children[0]!.attributes).toEqual([{ name: "data-state", value: "open" }]); |
| 301 | 307 | expect(clone.children[1]!.attributes).toEqual(icon.attributes); |
| 302 | | expect(clone.animate).toHaveBeenCalledWith([{ opacity: 1 }, { opacity: 0 }], { |
| 303 | | duration: 150, |
| 304 | | easing: "ease-out", |
| 305 | | }); |
| 308 | expect(clone.animate).toHaveBeenCalledWith( |
| 309 | [ |
| 310 | { opacity: 1, transform: "translateY(0px)" }, |
| 311 | { opacity: 0, transform: "translateY(-83px)" }, |
| 312 | ], |
| 313 | { |
| 314 | duration: 150, |
| 315 | easing: "ease-out", |
| 316 | }, |
| 317 | ); |
| 306 | 318 | expect(parent.children.includes(clone)).toBe(true); |
| 307 | 319 | motion.update(true); |
| 308 | 320 | expect(clone.animations).toHaveLength(1); |
| ... | ... | @@ -311,6 +323,106 @@ describe("sidebar list motion", () => { |
| 311 | 323 | expect(parent.children.includes(clone)).toBe(false); |
| 312 | 324 | }); |
| 313 | 325 | |
| 326 | it("rides entering rows on the shelf displacement so an opened shelf moves as one block", () => { |
| 327 | const a = new TestRow("a", 40); |
| 328 | const header = new TestRow("header", 32); |
| 329 | const x = new TestRow("x", 36); |
| 330 | const y = new TestRow("y", 36); |
| 331 | const z = new TestRow("z", 36); |
| 332 | const { motion, layout } = fixture([a, header, x]); |
| 333 | motion.update(true); |
| 334 | // The shelf is anchored below the list, so two revealed rows lift the |
| 335 | // header and its existing rows by the same 72px. |
| 336 | layout([a, header, x, y, z]); |
| 337 | for (const row of [header, x, y, z]) row.offsetTop -= 72; |
| 338 | motion.update(true); |
| 339 | expectMove(header, 72); |
| 340 | expectMove(x, 72); |
| 341 | expect(a.animate).not.toHaveBeenCalled(); |
| 342 | expect(y.animate).toHaveBeenLastCalledWith( |
| 343 | [ |
| 344 | { opacity: 0, transform: "translateY(72px)" }, |
| 345 | { opacity: 1, transform: "translateY(0px)" }, |
| 346 | ], |
| 347 | { duration: 150, easing: "ease-out" }, |
| 348 | ); |
| 349 | expect(z.animate).toHaveBeenLastCalledWith( |
| 350 | [ |
| 351 | { opacity: 0, transform: "translateY(72px)" }, |
| 352 | { opacity: 1, transform: "translateY(0px)" }, |
| 353 | ], |
| 354 | { duration: 150, easing: "ease-out" }, |
| 355 | ); |
| 356 | }); |
| 357 | |
| 358 | it("rides new rows on a retained header's unfinished travel", () => { |
| 359 | const header = new TestRow("header", 32); |
| 360 | const above = new TestRow("above", 39); |
| 361 | const incoming = new TestRow("incoming", 36); |
| 362 | const { motion, layout } = fixture([header]); |
| 363 | motion.update(true); |
| 364 | layout([above, header]); |
| 365 | motion.update(true); |
| 366 | header.animations[0]!.progress = 0.25; |
| 367 | layout([above, header, incoming]); |
| 368 | motion.update(true); |
| 369 | expect(incoming.animate).toHaveBeenLastCalledWith( |
| 370 | [ |
| 371 | { opacity: 0, transform: "translateY(-30px)" }, |
| 372 | { opacity: 1, transform: "translateY(0px)" }, |
| 373 | ], |
| 374 | { duration: 150, easing: "ease-out" }, |
| 375 | ); |
| 376 | }); |
| 377 | |
| 378 | it("cancels in-flight row travel when a bulk update skips animation", () => { |
| 379 | const a = new TestRow("a"); |
| 380 | const b = new TestRow("b"); |
| 381 | const { motion, layout } = fixture([a, b]); |
| 382 | motion.update(true); |
| 383 | layout([b, a]); |
| 384 | motion.update(true); |
| 385 | const first = a.animations[0]!; |
| 386 | first.progress = 0.4; |
| 387 | const incoming = Array.from({ length: 41 }, (_, index) => new TestRow(`new-${index}`)); |
| 388 | layout(incoming); |
| 389 | motion.update(true); |
| 390 | expect(first.cancel).toHaveBeenCalledOnce(); |
| 391 | expect(incoming.every((row) => row.animate.mock.calls.length === 0)).toBe(true); |
| 392 | }); |
| 393 | |
| 394 | it("keeps in-flight shelf entry travel when the shelf closes mid-animation", () => { |
| 395 | const a = new TestRow("a", 40); |
| 396 | const header = new TestRow("header", 32); |
| 397 | const x = new TestRow("x", 36); |
| 398 | const y = new TestRow("y", 36); |
| 399 | const { motion, layout } = fixture([a, header, x]); |
| 400 | motion.update(true); |
| 401 | layout([a, header, x, y]); |
| 402 | for (const row of [header, x, y]) row.offsetTop -= 36; |
| 403 | motion.update(true); |
| 404 | const entry = y.animations[0]!; |
| 405 | header.animations[0]!.progress = 0.25; |
| 406 | x.animations[0]!.progress = 0.25; |
| 407 | entry.progress = 0.25; |
| 408 | layout([a, header, x]); |
| 409 | motion.update(true); |
| 410 | expect(entry.cancel).toHaveBeenCalledOnce(); |
| 411 | const clone = y.clones[0]!; |
| 412 | // Remaining entry travel (36 * 0.75) is baked into the clone's box so the |
| 413 | // fade starts from the row's current visual top instead of jumping to 0. |
| 414 | expect(clone.style.top).toBe("110px"); |
| 415 | expect(clone.animate).toHaveBeenCalledWith( |
| 416 | [ |
| 417 | { opacity: 0.25, transform: "translateY(0px)" }, |
| 418 | { opacity: 0, transform: "translateY(9px)" }, |
| 419 | ], |
| 420 | { duration: 150, easing: "ease-out" }, |
| 421 | ); |
| 422 | expectMove(header, -9); |
| 423 | expectMove(x, -9); |
| 424 | }); |
| 425 | |
| 314 | 426 | it("clears exit clones on pickup and does not fade the release commit", () => { |
| 315 | 427 | const [a, b, c] = [new TestRow("a"), new TestRow("b"), new TestRow("c")]; |
| 316 | 428 | const { motion, layout, parent } = fixture([a, b]); |
| ... | ... | @@ -329,10 +441,16 @@ describe("sidebar list motion", () => { |
| 329 | 441 | expect(c.animations).toHaveLength(0); |
| 330 | 442 | layout([c, a]); |
| 331 | 443 | motion.update(true); |
| 332 | | expect(a.animate).toHaveBeenCalledWith([{ opacity: 0 }, { opacity: 1 }], { |
| 333 | | duration: 150, |
| 334 | | easing: "ease-out", |
| 335 | | }); |
| 444 | expect(a.animate).toHaveBeenCalledWith( |
| 445 | [ |
| 446 | { opacity: 0, transform: "translateY(0px)" }, |
| 447 | { opacity: 1, transform: "translateY(0px)" }, |
| 448 | ], |
| 449 | { |
| 450 | duration: 150, |
| 451 | easing: "ease-out", |
| 452 | }, |
| 453 | ); |
| 336 | 454 | motion.dispose(); |
| 337 | 455 | expect(a.animations.at(-1)!.cancel).toHaveBeenCalledOnce(); |
| 338 | 456 | }); |
| ... | ... | @@ -349,15 +467,40 @@ describe("sidebar list motion", () => { |
| 349 | 467 | motion.update(true); |
| 350 | 468 | expect(marker.clones).toHaveLength(0); |
| 351 | 469 | const clone = a.clones[0]!; |
| 352 | | expect(clone.animate).toHaveBeenCalledWith([{ opacity: 0.4 }, { opacity: 0 }], { |
| 353 | | duration: 150, |
| 354 | | easing: "ease-out", |
| 355 | | }); |
| 470 | expect(clone.animate).toHaveBeenCalledWith( |
| 471 | [ |
| 472 | { opacity: 0.4, transform: "translateY(0px)" }, |
| 473 | { opacity: 0, transform: "translateY(40px)" }, |
| 474 | ], |
| 475 | { |
| 476 | duration: 150, |
| 477 | easing: "ease-out", |
| 478 | }, |
| 479 | ); |
| 356 | 480 | motion.update(false); |
| 357 | 481 | expect(parent.children).toEqual([]); |
| 358 | 482 | expect(clone.animations[0]!.cancel).toHaveBeenCalledOnce(); |
| 359 | 483 | }); |
| 360 | 484 | |
| 485 | it("retargets an in-flight entry when a later layout shift moves the row", () => { |
| 486 | const a = new TestRow("a", 40); |
| 487 | const header = new TestRow("header", 32); |
| 488 | const x = new TestRow("x", 36); |
| 489 | const y = new TestRow("y", 36); |
| 490 | const { motion, layout } = fixture([a, header, x]); |
| 491 | motion.update(true); |
| 492 | layout([a, header, x, y]); |
| 493 | for (const row of [header, x, y]) row.offsetTop -= 36; |
| 494 | motion.update(true); |
| 495 | const entry = y.animations[0]!; |
| 496 | entry.progress = 0.25; |
| 497 | for (const row of [header, x, y]) row.offsetTop += 40; |
| 498 | motion.update(true); |
| 499 | expect(entry.cancel).not.toHaveBeenCalled(); |
| 500 | // Remaining 27px of the 36px entry plus the new 40px shift. |
| 501 | expectMove(y, -13); |
| 502 | }); |
| 503 | |
| 361 | 504 | it("skips fades when a large list change would clone too many rows", () => { |
| 362 | 505 | const rows = Array.from({ length: 41 }, (_, index) => new TestRow(`row-${index}`)); |
| 363 | 506 | const { motion, layout, parent } = fixture(rows); |