Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(NavigationStack): read each screen right before its bar (#10455)

Christopher Chedeau77377ea2af29
diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
index 31fbf6123a..9770da5380 100644
--- a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
@@ -178,10 +178,10 @@ interface BarFrame {
* stack and the back button's effective opacities. The returned function
* stops and returns them. A layer's x is its computed `translate`: the cards
* and bars sit at the stack's leading edge, checked when the trace starts. So
- * a frame reads no layout. Under load, in a frame that comes a few
- * milliseconds late, WebKit evaluates two layers that animate on one clock
- * about a millisecond apart. This holds for boxes and translates alike.
- * `animating` says which frames an animation drives.
+ * a frame reads no layout. Under load, WebKit can evaluate two layers that
+ * share one clock at two times in one frame, as far apart as their reads.
+ * This holds for boxes and translates alike. So each card is read right
+ * before its bar. `animating` says which frames an animation drives.
*/
async function traceBars(page: Page): Promise<() => Promise<BarFrame[]>> {
await page.evaluate(() => {
@@ -204,15 +204,32 @@ async function traceBars(page: Page): Promise<() => Promise<BarFrame[]>> {
const value = getComputedStyle(element).translate;
return value === 'none' ? 0 : parseFloat(value);
};
- const read = (selector: string, attribute: string) => {
- const out: Record<string, number> = {};
- for (const element of document.querySelectorAll<HTMLElement>(selector)) {
- const key = element.getAttribute(attribute);
- if (key != null) {
- out[key] = translateX(element);
+ const readLayers = () => {
+ const cards: Record<string, number> = {};
+ const bars: Record<string, number> = {};
+ for (const card of document.querySelectorAll(
+ '[data-navigation-screen]',
+ )) {
+ const key = card.getAttribute('data-navigation-screen');
+ if (key == null) {
+ continue;
+ }
+ cards[key] = translateX(card);
+ const keyBars = document.querySelectorAll(
+ `[data-navigation-bar="${CSS.escape(key)}"]`,
+ );
+ const bar = keyBars.item(keyBars.length - 1);
+ if (bar != null) {
+ bars[key] = translateX(bar);
+ }
+ }
+ for (const bar of document.querySelectorAll('[data-navigation-bar]')) {
+ const key = bar.getAttribute('data-navigation-bar');
+ if (key != null && !(key in cards)) {
+ bars[key] = translateX(bar);
}
}
- return out;
+ return {cards, bars};
};
// A layer at rest sits at the stack's edge: its box is its translate.
const left = stack?.getBoundingClientRect().left ?? 0;
@@ -234,8 +251,7 @@ async function traceBars(page: Page): Promise<() => Promise<BarFrame[]>> {
const chevron = button?.firstElementChild ?? null;
w.__bars.push({
t: performance.now() - t0,
- cards: read('[data-navigation-screen]', 'data-navigation-screen'),
- bars: read('[data-navigation-bar]', 'data-navigation-bar'),
+ ...readLayers(),
back:
button == null || chevron == null
? null