mirror of
https://github.com/Matysh/houseplan-card
synced 2026-09-28 19:01:34 +00:00
test(docs): прокручивать настоящий скроллер превью (#600)
После #600 единственный скроллер диалога находится в shadow-root .content. Съёмка продолжала менять scrollTop у старой .body, поэтому обычный кадр устройства и кадр Display preview получались побайтово одинаковыми. Тест фиксирует владельца скролла и запрещает возврат к неработающей .body. Issue: #600 User-Visible: no
This commit is contained in:
@@ -144,18 +144,18 @@ const applyDocumentationState = (page, scenario) => page.evaluate(async (current
|
||||
|
||||
if (current.devicePresentationPreview) {
|
||||
const dialog = card.renderRoot.querySelector('hp-dialog');
|
||||
const body = dialog?.querySelector('.body');
|
||||
const scroller = dialog?.renderRoot?.querySelector('.content');
|
||||
const preview = dialog?.querySelector('hp-device-preview');
|
||||
await preview?.updateComplete;
|
||||
if (!body || !preview)
|
||||
if (!scroller || !preview)
|
||||
throw new Error('documentation device presentation preview is missing');
|
||||
const bodyRect = body.getBoundingClientRect();
|
||||
const scrollerRect = scroller.getBoundingClientRect();
|
||||
const previewRect = preview.getBoundingClientRect();
|
||||
body.scrollTop += previewRect.top - bodyRect.top - 180;
|
||||
scroller.scrollTop += previewRect.top - scrollerRect.top - 180;
|
||||
await frame();
|
||||
const visibleBody = body.getBoundingClientRect();
|
||||
const visibleScroller = scroller.getBoundingClientRect();
|
||||
const visiblePreview = preview.getBoundingClientRect();
|
||||
if (visiblePreview.top < visibleBody.top - 1 || visiblePreview.bottom > visibleBody.bottom + 1)
|
||||
if (visiblePreview.top < visibleScroller.top - 1 || visiblePreview.bottom > visibleScroller.bottom + 1)
|
||||
throw new Error('documentation viewport does not show the device presentation preview');
|
||||
}
|
||||
|
||||
|
||||
@@ -36,3 +36,13 @@ test('съёмка берёт набор из этого модуля, а не
|
||||
assert.doesNotMatch(source, /const DETERMINISTIC_ARGS\s*=/,
|
||||
'собственное объявление в capture.mjs разошлось бы с проверяемым набором');
|
||||
});
|
||||
|
||||
test('#600 кадр превью крутит единственный скроллер hp-dialog', () => {
|
||||
const source = readFileSync(new URL('../demo/docs/capture.mjs', import.meta.url), 'utf8');
|
||||
const block = source.match(/if \(current\.devicePresentationPreview\) \{([\s\S]*?)\n \}/)?.[1] || '';
|
||||
assert.match(block, /dialog\?\.renderRoot\?\.querySelector\('\.content'\)/,
|
||||
'после #600 скроллом владеет .content в shadow root оболочки');
|
||||
assert.match(block, /scroller\.scrollTop\s*\+=/);
|
||||
assert.doesNotMatch(block, /querySelector\('\.body'\)/,
|
||||
'.body больше не скроллер: такая съёмка даёт два одинаковых кадра');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user