The tallest detent now fills the viewport down from the top of the search field, so a fully expanded sheet covers the search field and avatar while leaving that little strip visible above. - DETENT_FRACTIONS.expanded is now the whole sheet; the sheet height is the viewport minus a top gap (replacing the 0.92 fraction cap). - The modifier measures that gap from the search field, relative to the sheet's container (the viewport top is not the app's top), falling back to 8px. - Update the sheet-detents unit test and read the real --sheet-height in the stacked-sheets acceptance test.
603 lines
18 KiB
JavaScript
603 lines
18 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
visit,
|
|
click,
|
|
currentURL,
|
|
triggerEvent,
|
|
waitFor,
|
|
waitUntil,
|
|
} from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'marco/tests/helpers';
|
|
import { computeDetentLayout } from 'marco/utils/sheet-detents';
|
|
import Service from '@ember/service';
|
|
import sinon from 'sinon';
|
|
|
|
class MockOsmService extends Service {
|
|
async getNearbyPois() {
|
|
return [
|
|
{
|
|
osmId: '123',
|
|
lat: 1,
|
|
lon: 1,
|
|
osmTags: { name: 'Test Place', amenity: 'cafe' },
|
|
osmType: 'node',
|
|
},
|
|
];
|
|
}
|
|
async getPoiById() {
|
|
return null;
|
|
}
|
|
async fetchOsmObject(id, type) {
|
|
return {
|
|
osmId: id,
|
|
osmType: type,
|
|
lat: 1,
|
|
lon: 1,
|
|
osmTags: { name: 'Test Place' },
|
|
title: 'Test Place',
|
|
};
|
|
}
|
|
}
|
|
|
|
class MockStorageService extends Service {
|
|
initialSyncDone = true;
|
|
savedPlaces = [];
|
|
findPlaceById() {
|
|
return null;
|
|
}
|
|
isPlaceSaved() {
|
|
return false;
|
|
}
|
|
loadPlacesInBounds() {
|
|
return [];
|
|
}
|
|
get placesInView() {
|
|
return [];
|
|
}
|
|
rs = {
|
|
on: () => {},
|
|
};
|
|
}
|
|
|
|
const MOBILE_QUERY = '(max-width: 768px)';
|
|
|
|
// @ember/test-helpers 5.4 has no setViewport helper, so simulate the mobile
|
|
// media query directly. The bottom-sheet modifier reads window.matchMedia at
|
|
// setup, so this must be installed before the route is visited.
|
|
function installMobileMatchMedia() {
|
|
return sinon.stub(window, 'matchMedia').callsFake((query) => ({
|
|
matches: typeof query === 'string' && query.includes(MOBILE_QUERY),
|
|
media: query,
|
|
onchange: null,
|
|
addEventListener() {},
|
|
removeEventListener() {},
|
|
addListener() {},
|
|
removeListener() {},
|
|
dispatchEvent() {
|
|
return false;
|
|
},
|
|
}));
|
|
}
|
|
|
|
module('Acceptance | bottom sheet', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.owner.register('service:osm', MockOsmService);
|
|
this.owner.register('service:storage', MockStorageService);
|
|
});
|
|
|
|
test('does not inject the drag handle at desktop width', async function (assert) {
|
|
await visit('/menu');
|
|
|
|
assert.dom('.sidebar').exists('sheet is rendered');
|
|
assert
|
|
.dom('[data-test-sheet-handle]')
|
|
.doesNotExist('no drag handle on desktop');
|
|
});
|
|
|
|
test('injects a handle and a pixel offset on mobile', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/menu');
|
|
await waitUntil(() => mapUi.sheetDetent !== null);
|
|
|
|
assert.dom('[data-test-sheet-handle]').exists('drag handle is injected');
|
|
|
|
const sheet = document.querySelector('.sidebar');
|
|
const offset = sheet.style.getPropertyValue('--sheet-offset');
|
|
assert.true(
|
|
/px$/.test(offset),
|
|
`--sheet-offset is a pixel value (${offset})`
|
|
);
|
|
assert.strictEqual(
|
|
mapUi.sheetDetent,
|
|
'medium',
|
|
'the app menu opens at the medium detent'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('dragging the handle moves the sheet to another detent', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/menu');
|
|
await waitUntil(() => mapUi.sheetDetent !== null);
|
|
|
|
const sheet = document.querySelector('.sidebar');
|
|
const handle = sheet.querySelector('[data-test-sheet-handle]');
|
|
const before = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
|
|
// Drag downward well past the threshold. Pointer events bubble to the
|
|
// window-level listeners the modifier installs on pointerdown. The first
|
|
// small move crosses the drag threshold (which rebases the gesture on the
|
|
// live offset); the second move performs the actual drag.
|
|
await triggerEvent(handle, 'pointerdown', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 100,
|
|
button: 0,
|
|
});
|
|
await triggerEvent(handle, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 110,
|
|
});
|
|
await triggerEvent(handle, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 370,
|
|
});
|
|
await triggerEvent(handle, 'pointerup', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 370,
|
|
});
|
|
|
|
const after = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
assert.true(after > before, `sheet moved down (${before} -> ${after})`);
|
|
assert.notStrictEqual(
|
|
mapUi.sheetDetent,
|
|
'medium',
|
|
'sheet left its opening detent'
|
|
);
|
|
// The inset is published on a deferred animation-frame flush.
|
|
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
|
assert.true(mapUi.sheetInsetPx > 0, 'map inset is reported');
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('dragging the content resizes the sheet below the largest detent', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/menu');
|
|
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
|
|
|
const sheet = document.querySelector('.sheet-top');
|
|
assert
|
|
.dom('.sheet-top')
|
|
.doesNotHaveClass('sheet-at-max', 'not at the largest detent');
|
|
const content = sheet.querySelector('.sidebar-content');
|
|
const before = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
|
|
// Drag the content itself (not the handle) downward.
|
|
await triggerEvent(content, 'pointerdown', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 100,
|
|
button: 0,
|
|
});
|
|
await triggerEvent(content, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 110,
|
|
});
|
|
await triggerEvent(content, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 300,
|
|
});
|
|
await triggerEvent(content, 'pointerup', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 300,
|
|
});
|
|
|
|
const after = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
assert.true(after > before, `sheet moved down (${before} -> ${after})`);
|
|
assert.notStrictEqual(
|
|
mapUi.sheetDetent,
|
|
'medium',
|
|
'sheet left its opening detent'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('dragging a list row resizes the sheet (mobile)', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/search?lat=1&lon=1');
|
|
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
|
|
|
const sheet = document.querySelector('.sheet-top');
|
|
const row = sheet.querySelector('.place-item');
|
|
const before = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
|
|
// A list row is a <button>; it must still start a sheet drag.
|
|
await triggerEvent(row, 'pointerdown', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 100,
|
|
button: 0,
|
|
});
|
|
await triggerEvent(row, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 110,
|
|
});
|
|
await triggerEvent(row, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 300,
|
|
});
|
|
await triggerEvent(row, 'pointerup', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 300,
|
|
});
|
|
|
|
const after = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
assert.true(after > before, `sheet moved down (${before} -> ${after})`);
|
|
assert.notStrictEqual(
|
|
mapUi.sheetDetent,
|
|
'medium',
|
|
'sheet left its opening detent'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('pulling the content down at the largest detent shrinks the sheet', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
// Open the menu at its largest detent.
|
|
mapUi.setSheetDetent('menu', 'expanded');
|
|
await visit('/menu');
|
|
await waitUntil(() => mapUi.sheetDetent === 'expanded');
|
|
|
|
const sheet = document.querySelector('.sheet-top');
|
|
assert
|
|
.dom('.sheet-top')
|
|
.hasClass('sheet-at-max', 'marked as at the largest detent');
|
|
|
|
const content = sheet.querySelector('.sidebar-content');
|
|
assert.strictEqual(
|
|
content.scrollTop,
|
|
0,
|
|
'content is scrolled to the top'
|
|
);
|
|
const before = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
|
|
// Pull the content down: overscroll shrinks the sheet instead of scrolling.
|
|
await triggerEvent(content, 'pointerdown', {
|
|
pointerId: 2,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 100,
|
|
button: 0,
|
|
});
|
|
await triggerEvent(content, 'pointermove', {
|
|
pointerId: 2,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 110,
|
|
});
|
|
await triggerEvent(content, 'pointermove', {
|
|
pointerId: 2,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 400,
|
|
});
|
|
await triggerEvent(content, 'pointerup', {
|
|
pointerId: 2,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 400,
|
|
});
|
|
|
|
const after = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
|
assert.true(after > before, `sheet shrank (${before} -> ${after})`);
|
|
assert.notStrictEqual(
|
|
mapUi.sheetDetent,
|
|
'expanded',
|
|
'sheet left the largest detent'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('opening a place from search results does not crash (mobile)', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
|
|
await visit('/search?lat=1&lon=1');
|
|
assert.dom('.place-item').exists('search results are rendered');
|
|
|
|
// This is the search→place transition that used to throw the
|
|
// backtracking assertion (Map re-renders in the same pass that installs
|
|
// the new sheet's modifier). click() already settles.
|
|
await click('.place-item');
|
|
|
|
assert.dom('.sheet-top').exists('the place sheet is rendered');
|
|
assert.ok(currentURL().includes('/place/'), 'navigated to the place');
|
|
|
|
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
|
assert.true(
|
|
mapUi.sheetInsetPx > 0,
|
|
'the map inset reflects the open sheet'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('opening a place keeps the search sheet stacked behind it (mobile)', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/search?lat=1&lon=1');
|
|
assert.dom('.place-item').exists('search results are rendered');
|
|
|
|
await click('.place-item');
|
|
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
|
|
|
assert.dom('.sheet-top').exists('the interactive top sheet is marked');
|
|
assert
|
|
.dom('.sheet-top.sheet-background')
|
|
.doesNotExist('the top sheet is not a background sheet');
|
|
assert
|
|
.dom('.sheet-background')
|
|
.exists('the parent sheet is rendered behind the top sheet');
|
|
assert
|
|
.dom('.sheet-background-layer[inert]')
|
|
.exists('the background layer is inert');
|
|
assert
|
|
.dom('.sheet-background .place-item')
|
|
.exists('the parent shows the search results');
|
|
|
|
// Place details opens at medium, and the background is pinned to the
|
|
// minimum so it can never peek above the top sheet. Read the sheet height
|
|
// the modifier wrote rather than recomputing the geometry.
|
|
const top = document.querySelector('.sheet-top');
|
|
const background = document.querySelector('.sheet-background');
|
|
const sheetHeight = parseFloat(
|
|
top.style.getPropertyValue('--sheet-height')
|
|
);
|
|
const layout = computeDetentLayout({
|
|
viewportHeight: window.innerHeight,
|
|
sheetHeight,
|
|
});
|
|
const mediumOffset = layout.find((d) => d.name === 'medium')?.offset;
|
|
const minimumOffset = layout[layout.length - 1].offset;
|
|
await waitUntil(
|
|
() =>
|
|
parseFloat(top.style.getPropertyValue('--sheet-offset')) ===
|
|
mediumOffset
|
|
);
|
|
assert.strictEqual(
|
|
parseFloat(top.style.getPropertyValue('--sheet-offset')),
|
|
mediumOffset,
|
|
'place details opens at the medium detent'
|
|
);
|
|
assert.strictEqual(
|
|
parseFloat(background.style.getPropertyValue('--sheet-offset')),
|
|
minimumOffset,
|
|
'the background sheet is minimized'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('background sheets stay minimized when the top sheet is taller (mobile)', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/search?lat=1&lon=1');
|
|
await click('.place-item');
|
|
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
|
|
|
const top = document.querySelector('.sheet-top');
|
|
const handle = top.querySelector('[data-test-sheet-handle]');
|
|
const background = document.querySelector('.sheet-background');
|
|
const backgroundBefore = parseFloat(
|
|
background.style.getPropertyValue('--sheet-offset')
|
|
);
|
|
const topBefore = parseFloat(
|
|
top.style.getPropertyValue('--sheet-offset')
|
|
);
|
|
|
|
// Drag the top sheet all the way up.
|
|
await triggerEvent(handle, 'pointerdown', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 1000,
|
|
button: 0,
|
|
});
|
|
await triggerEvent(handle, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 990,
|
|
});
|
|
await triggerEvent(handle, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 0,
|
|
});
|
|
await triggerEvent(handle, 'pointerup', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 0,
|
|
});
|
|
|
|
await waitUntil(() => mapUi.sheetDetent !== 'medium');
|
|
const topAfter = parseFloat(top.style.getPropertyValue('--sheet-offset'));
|
|
const backgroundAfter = parseFloat(
|
|
background.style.getPropertyValue('--sheet-offset')
|
|
);
|
|
assert.true(topAfter < topBefore, 'the top sheet expanded');
|
|
assert.true(
|
|
topAfter < backgroundAfter,
|
|
'the top sheet is more visible than the background'
|
|
);
|
|
assert.strictEqual(
|
|
backgroundAfter,
|
|
backgroundBefore,
|
|
'the background stayed minimized'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('tapping the map on mobile pops to the parent search sheet (mobile)', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
window.localStorage.setItem(
|
|
'marco:map-view',
|
|
JSON.stringify({ center: [13.4, 52.5], zoom: 18 })
|
|
);
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
|
|
await visit('/search?lat=1&lon=1');
|
|
await click('.place-item');
|
|
assert.ok(currentURL().includes('/place/'), 'on the place sheet');
|
|
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
|
assert.strictEqual(
|
|
mapUi.sheetDetent,
|
|
'medium',
|
|
'place details opened at the medium detent'
|
|
);
|
|
|
|
await waitFor('canvas', { timeout: 2000 });
|
|
const canvas = document.querySelector('canvas');
|
|
await triggerEvent(canvas, 'pointerdown', {
|
|
clientX: 200,
|
|
clientY: 120,
|
|
button: 0,
|
|
isPrimary: true,
|
|
});
|
|
await triggerEvent(canvas, 'pointerup', {
|
|
clientX: 200,
|
|
clientY: 120,
|
|
button: 0,
|
|
isPrimary: true,
|
|
});
|
|
await triggerEvent(canvas, 'click', {
|
|
clientX: 200,
|
|
clientY: 120,
|
|
bubbles: true,
|
|
});
|
|
|
|
await waitUntil(() => currentURL().includes('/search'));
|
|
assert.ok(
|
|
currentURL().includes('/search'),
|
|
'the outside tap popped back to the search route'
|
|
);
|
|
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
|
assert.strictEqual(
|
|
mapUi.sheetDetent,
|
|
'medium',
|
|
'the search sheet returns to its remembered medium detent'
|
|
);
|
|
assert.dom('.sheet-top').exists('a top sheet is still open');
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
window.localStorage.removeItem('marco:map-view');
|
|
}
|
|
});
|
|
|
|
test('dragging past the collapsed detent dismisses the sheet', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
const mapUi = this.owner.lookup('service:map-ui');
|
|
await visit('/menu');
|
|
await waitUntil(() => mapUi.sheetDetent !== null);
|
|
|
|
const sheet = document.querySelector('.sidebar');
|
|
const handle = sheet.querySelector('[data-test-sheet-handle]');
|
|
|
|
await triggerEvent(handle, 'pointerdown', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 100,
|
|
button: 0,
|
|
});
|
|
await triggerEvent(handle, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 110,
|
|
});
|
|
await triggerEvent(handle, 'pointermove', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 1400,
|
|
});
|
|
await triggerEvent(handle, 'pointerup', {
|
|
pointerId: 1,
|
|
pointerType: 'touch',
|
|
isPrimary: true,
|
|
clientY: 1400,
|
|
});
|
|
|
|
assert.strictEqual(
|
|
mapUi.sheetDetent,
|
|
null,
|
|
'the remembered detent is cleared on dismiss'
|
|
);
|
|
|
|
// dismiss() waits for the slide-out transition before calling onDismiss,
|
|
// so settled() is not enough.
|
|
await waitUntil(() => !document.querySelector('.sidebar'), {
|
|
timeout: 3000,
|
|
});
|
|
assert.dom('.sidebar').doesNotExist('the sheet closed after dismissing');
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
});
|