Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35c0d83819 |
@@ -1,12 +1,6 @@
|
|||||||
import { test, expect } from '../support/fixtures.js';
|
import { test, expect } from '../support/fixtures.js';
|
||||||
import type { Page } from '@playwright/test';
|
import type { Page } from '@playwright/test';
|
||||||
|
|
||||||
/**
|
|
||||||
* How far the scroll test scrolls. One constant, because the guard and
|
|
||||||
* the assertion have to agree about it — they did not, which is #133.
|
|
||||||
*/
|
|
||||||
const SCROLL_TARGET = 80;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plan 007 phase 5: expanding an album shows its tracks.
|
* Plan 007 phase 5: expanding an album shows its tracks.
|
||||||
*
|
*
|
||||||
@@ -110,27 +104,20 @@ test.describe('the album dropdown', () => {
|
|||||||
await app.setViewportSize({ width: 900, height: 600 });
|
await app.setViewportSize({ width: 900, height: 600 });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Wait for the range the assertion below actually needs, not for
|
await expect.poll(() => scrollRange(app)).toMatchObject({
|
||||||
// "scrollable at all" (#133). The guard used to be
|
scrollable: true,
|
||||||
// `scrollHeight > clientHeight + 40` while the next line asks to
|
overflowY: 'auto',
|
||||||
// reach 80, so any range in 41-79 satisfied it and could not
|
});
|
||||||
// satisfy the assertion — and the grid passes through exactly
|
|
||||||
// that while it settles, because it recomputes its columns after
|
|
||||||
// the resize rather than during it. The settled range here is
|
|
||||||
// 330, so this waits rather than weakening anything.
|
|
||||||
await expect
|
|
||||||
.poll(() => scrollRange(app))
|
|
||||||
.toMatchObject({ room: true, overflowY: 'auto' });
|
|
||||||
|
|
||||||
await app.evaluate((target) => {
|
await app.evaluate(() => {
|
||||||
const sc = document
|
const sc = document
|
||||||
.querySelector('cover-grid')
|
.querySelector('cover-grid')
|
||||||
?.shadowRoot?.querySelector('.grid-scroll-container');
|
?.shadowRoot?.querySelector('.grid-scroll-container');
|
||||||
|
|
||||||
if (sc) sc.scrollTop = target;
|
if (sc) sc.scrollTop = 80;
|
||||||
}, SCROLL_TARGET);
|
});
|
||||||
|
|
||||||
expect(await scrollTop(app)).toBe(SCROLL_TARGET);
|
expect(await scrollTop(app)).toBe(80);
|
||||||
|
|
||||||
// And the dropdown it opens is on screen, wherever the manager
|
// And the dropdown it opens is on screen, wherever the manager
|
||||||
// decides that leaves the scroll. It is *not* "the position is
|
// decides that leaves the scroll. It is *not* "the position is
|
||||||
@@ -263,19 +250,16 @@ async function closeDropdown(app: Page): Promise<void> {
|
|||||||
|
|
||||||
/** Whether the grid can scroll at all, which decides if a probe can move. */
|
/** Whether the grid can scroll at all, which decides if a probe can move. */
|
||||||
async function scrollRange(app: Page) {
|
async function scrollRange(app: Page) {
|
||||||
return app.evaluate((target) => {
|
return app.evaluate(() => {
|
||||||
const sc = document
|
const sc = document
|
||||||
.querySelector('cover-grid')
|
.querySelector('cover-grid')
|
||||||
?.shadowRoot?.querySelector('.grid-scroll-container');
|
?.shadowRoot?.querySelector('.grid-scroll-container');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// `room` is the precondition of the assertion that follows it:
|
scrollable: !!sc && sc.scrollHeight > sc.clientHeight + 40,
|
||||||
// enough range to actually reach the target. A threshold below
|
|
||||||
// what the caller depends on is not a guard.
|
|
||||||
room: !!sc && sc.scrollHeight - sc.clientHeight >= target,
|
|
||||||
overflowY: sc ? getComputedStyle(sc).overflowY : '',
|
overflowY: sc ? getComputedStyle(sc).overflowY : '',
|
||||||
};
|
};
|
||||||
}, SCROLL_TARGET);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function scrollTop(app: Page): Promise<number> {
|
async function scrollTop(app: Page): Promise<number> {
|
||||||
|
|||||||
@@ -160,52 +160,29 @@ export class HomeView extends ViewLifecycleMixin(LitElement) {
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The hover play button is a *hover* affordance, so it is
|
|
||||||
* gated on the device having hover rather than on width. A
|
|
||||||
* touch long-press synthesises a hover state in the WebView,
|
|
||||||
* so on a phone it flashed into view during the 500ms hold
|
|
||||||
* that utils/long-press.ts is measuring for a context menu —
|
|
||||||
* a control appearing because you were reaching for a
|
|
||||||
* different one. A phone user taps the album and plays from
|
|
||||||
* the detail view, so there is nothing to replace it with.
|
|
||||||
*
|
|
||||||
* display:none outside the query rather than opacity:0 on
|
|
||||||
* its own: an opacity-0 button still takes taps and is
|
|
||||||
* still in the accessibility tree, so the invisible control
|
|
||||||
* would keep the hit area it was never meant to have on
|
|
||||||
* touch. Everything else stays inside, so the desktop
|
|
||||||
* animation is unchanged.
|
|
||||||
*/
|
|
||||||
.play {
|
.play {
|
||||||
display: none;
|
position: absolute;
|
||||||
|
right: 8px;
|
||||||
|
bottom: 8px;
|
||||||
|
width: 38px;
|
||||||
|
height: 38px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--yj-accent, #ffd43b);
|
||||||
|
color: var(--yj-accent-fg, #000);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(6px);
|
||||||
|
transition: opacity 0.12s ease, transform 0.12s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (hover: hover) and (pointer: fine) {
|
.card:hover .play,
|
||||||
.play {
|
.card:focus-within .play {
|
||||||
position: absolute;
|
opacity: 1;
|
||||||
right: 8px;
|
transform: translateY(0);
|
||||||
bottom: 8px;
|
|
||||||
width: 38px;
|
|
||||||
height: 38px;
|
|
||||||
border: none;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: var(--yj-accent, #ffd43b);
|
|
||||||
color: var(--yj-accent-fg, #000);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
cursor: pointer;
|
|
||||||
opacity: 0;
|
|
||||||
transform: translateY(6px);
|
|
||||||
transition: opacity 0.12s ease, transform 0.12s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card:hover .play,
|
|
||||||
.card:focus-within .play {
|
|
||||||
opacity: 1;
|
|
||||||
transform: translateY(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.name {
|
.name {
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
/**
|
|
||||||
* A hover affordance is gated on the device having hover.
|
|
||||||
*
|
|
||||||
* The home page's cover cards reveal a play button on :hover. A touch
|
|
||||||
* long-press synthesises a hover state in the WebView, so on a phone
|
|
||||||
* that button flashed into view during the 500ms hold that
|
|
||||||
* utils/long-press.ts is measuring for a context menu — a control
|
|
||||||
* appearing because the user was reaching for a different one.
|
|
||||||
*
|
|
||||||
* This is asserted against the *parsed stylesheet* rather than by
|
|
||||||
* emulating a touch device, and that is a limitation worth stating
|
|
||||||
* rather than hiding. CDP's Emulation.setEmulatedMedia does not reach
|
|
||||||
* this tier's iframe — matchMedia still answers `hover: hover` after it
|
|
||||||
* is set — so there is no way here to render the component as a phone
|
|
||||||
* would and read the computed style. What can be checked is the shape
|
|
||||||
* the browser actually built from the css`` literal: that the reveal
|
|
||||||
* lives inside a hover media query and that the default is display:none.
|
|
||||||
*
|
|
||||||
* Which is the regression worth catching anyway. The failure mode is
|
|
||||||
* someone hoisting the rule back out of the query for a one-line tidy —
|
|
||||||
* a change nothing renders differently on a desktop, so every other
|
|
||||||
* assertion in this repo passes and the phone silently regresses.
|
|
||||||
*/
|
|
||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
|
|
||||||
import '@components/home-view/home-view';
|
|
||||||
import { fixture } from '@test/support/render';
|
|
||||||
|
|
||||||
/** Every rule in the element's own adopted stylesheets, flattened. */
|
|
||||||
function rulesOf(host: Element): { text: string; condition: string | null }[] {
|
|
||||||
const sheets = host.shadowRoot?.adoptedStyleSheets ?? [];
|
|
||||||
const out: { text: string; condition: string | null }[] = [];
|
|
||||||
|
|
||||||
for (const sheet of sheets) {
|
|
||||||
for (const rule of Array.from(sheet.cssRules)) {
|
|
||||||
if (rule instanceof CSSMediaRule) {
|
|
||||||
for (const inner of Array.from(rule.cssRules)) {
|
|
||||||
out.push({ text: inner.cssText, condition: rule.conditionText });
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.push({ text: rule.cssText, condition: null });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('the home card play button', () => {
|
|
||||||
it('reveals itself only where the device has hover', async () => {
|
|
||||||
const el = await fixture('home-view', {});
|
|
||||||
const rules = rulesOf(el);
|
|
||||||
|
|
||||||
// The sweep is worth nothing if it read no rules at all — the same
|
|
||||||
// first assertion icon-language.test.ts makes for the same reason.
|
|
||||||
expect(rules.length).toBeGreaterThan(0);
|
|
||||||
|
|
||||||
const reveals = rules.filter(
|
|
||||||
(r) => r.text.includes('.play') && /opacity:\s*1/.test(r.text),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(reveals.length).toBeGreaterThan(0);
|
|
||||||
|
|
||||||
for (const rule of reveals) {
|
|
||||||
expect(rule.condition).toMatch(/hover:\s*hover/);
|
|
||||||
expect(rule.condition).toMatch(/pointer:\s*fine/);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is display:none rather than transparent where it is absent', async () => {
|
|
||||||
const el = await fixture('home-view', {});
|
|
||||||
|
|
||||||
// opacity:0 alone would leave a button that still takes taps and is
|
|
||||||
// still in the accessibility tree, so a phone would keep the hit
|
|
||||||
// area for a control it can never see.
|
|
||||||
const unconditional = rulesOf(el).filter(
|
|
||||||
(r) => r.condition === null && r.text.startsWith('.play'),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(unconditional.length).toBeGreaterThan(0);
|
|
||||||
expect(unconditional.some((r) => /display:\s*none/.test(r.text))).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user