fix(h5): reduce report swipe conflicts and limit edge overscroll
This commit is contained in:
@@ -65,18 +65,30 @@ try {
|
||||
const touch = (type, x, y, timestamp) => cdp.send('Input.dispatchTouchEvent', {
|
||||
type, ...(timestamp ? { timestamp } : {}), touchPoints: /touchEnd|touchCancel/.test(type) ? [] : [{ x, y, id: 1 }]
|
||||
});
|
||||
async function drag(card, dx, { dy = 0, cancel = false, pause = 0, flick = false, verify = false } = {}) {
|
||||
const frame = card.locator('.dpanel.active .viz-frame');
|
||||
async function drag(card, dx, { dy = 0, cancel = false, pause = 0, flick = false, verify = false, text = false } = {}) {
|
||||
const frame = card.locator('.dpanel.active ' + (text ? '.ditem-text' : '.viz-frame'));
|
||||
await frame.scrollIntoViewIfNeeded(); await page.waitForTimeout(400);
|
||||
const box = await frame.boundingBox(), x = box.x + box.width / 2, y = Math.min(500, box.y + box.height / 2);
|
||||
const box = await frame.boundingBox(), x = box.x + box.width / 2, y = box.y + box.height / 2;
|
||||
const before = await offset(card), previous = await selected(card), now = flick ? Date.now() / 1000 : null;
|
||||
const scrollBefore = await page.locator('#s-report').evaluate(el => el.scrollTop);
|
||||
const beforeHeight = await card.locator('.detail-viewport').evaluate(el => el.getBoundingClientRect().height);
|
||||
await touch('touchStart', x, y, now);
|
||||
await touch('touchMove', x + dx / 2, y + dy / 2, now && now + .02);
|
||||
await touch('touchMove', x + dx, y + dy, now && now + .04);
|
||||
const liveOffset = await offset(card), limit = await card.locator('.detail-viewport').evaluate(el => el.clientWidth * (el.querySelectorAll('.dpanel').length - 1));
|
||||
assert(liveOffset <= 17 && liveOffset >= -limit - 17, 'edge resistance caps overscroll at 16px');
|
||||
if (verify) {
|
||||
assert(Math.abs(await offset(card) - before - dx) < 3, 'report follows finger before release');
|
||||
assert.equal(await selected(card), previous, 'selection commits only on release');
|
||||
assert.equal(await card.locator('.detail-panels.dragging').count(), 1);
|
||||
assert(Math.abs(await card.locator('.detail-viewport').evaluate(el => el.getBoundingClientRect().height) - beforeHeight) < 1, 'card height stays fixed during horizontal dragging');
|
||||
await card.locator('.dpanel.active .ditem-text').evaluate(el => {
|
||||
const growth = document.createElement('span');
|
||||
growth.dataset.testGrowth = ''; growth.style.cssText = 'display:block;height:80px'; el.append(growth);
|
||||
});
|
||||
await page.waitForTimeout(100);
|
||||
assert(Math.abs(await card.locator('.detail-viewport').evaluate(el => el.getBoundingClientRect().height) - beforeHeight) < 1, 'height stays fixed even when panel content resizes while held');
|
||||
await card.locator('[data-test-growth]').evaluate(el => el.remove());
|
||||
if (process.env.H5_ARTIFACT_DIR) {
|
||||
fs.mkdirSync(process.env.H5_ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.H5_ARTIFACT_DIR, 'report-drag-' + await card.locator('.dtab').first().textContent() + '.png') });
|
||||
@@ -85,6 +97,9 @@ try {
|
||||
if (pause) await page.waitForTimeout(pause);
|
||||
await touch(cancel ? 'touchCancel' : 'touchEnd', 0, 0, now && now + .05);
|
||||
await page.waitForTimeout(400);
|
||||
if (dy <= -80 && Math.abs(dx) < 10) {
|
||||
assert(await page.locator('#s-report').evaluate(el => el.scrollTop) > scrollBefore + 10, 'vertical gesture actually scrolls the report');
|
||||
}
|
||||
assert.equal(await card.locator('.detail-panels.dragging').count(), 0);
|
||||
assert.equal(await page.locator('#p-zoom.show').count(), 0, 'drag never opens zoom');
|
||||
}
|
||||
@@ -105,6 +120,9 @@ try {
|
||||
await drag(card, 25, { pause: 160 }); assert.equal(await selected(card), '1', 'short slow drag snaps back');
|
||||
await drag(card, 100, { cancel: true }); assert.equal(await selected(card), '1', 'cancellation restores selection');
|
||||
await drag(card, 2, { dy: -90 }); assert.equal(await selected(card), '1', 'vertical scrolling preserves tab');
|
||||
await drag(card, 65, { dy: -60 }); assert.equal(await selected(card), '1', 'ambiguous diagonal scrolling does not switch tabs');
|
||||
await drag(card, 100, { text: true }); assert.equal(await selected(card), '1', 'horizontal dragging on analysis text does not switch tabs');
|
||||
await drag(card, 2, { dy: -90, text: true }); assert.equal(await selected(card), '1', 'reading text keeps vertical scrolling and current tab');
|
||||
await drag(card, 40, { flick: true }); assert.equal(await selected(card), '0', 'short fast flick goes back');
|
||||
await drag(card, 100); assert.equal(await selected(card), '0', 'first edge cannot overshoot');
|
||||
await card.locator('.dtab').last().click(); await page.waitForTimeout(400); await aligned(card);
|
||||
|
||||
Reference in New Issue
Block a user