- Place details header now keeps the same top gap as the standard 56px drawer header, so the place name is not crammed against the drag handle. - Read the sheet inset untracked in the map's pin/center helpers so updateSelectedPin no longer re-runs on every drag frame. This stops the selected marker from jittering while a drawer is dragged. - Re-center the selected place in the resized visible area when a drawer settles at a new detent, and pan it clear of the sheet on a same-size settle (restores the auto-pan that untracking removed). - Commit the sheet's hidden position with the transform transition disabled so the entrance animates from fully hidden and slides up, instead of shrinking down from the top. - Add acceptance tests for the header gap, the per-frame pin recompute, and the settle recenter/pan behaviour.
717 lines
22 KiB
JavaScript
717 lines
22 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
visit,
|
|
click,
|
|
currentURL,
|
|
settled,
|
|
triggerEvent,
|
|
waitFor,
|
|
waitUntil,
|
|
} from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'marco/tests/helpers';
|
|
import { computeDetentLayout } from 'marco/utils/sheet-detents';
|
|
import MapComponent from 'marco/components/map';
|
|
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();
|
|
}
|
|
});
|
|
|
|
test('resizing the sheet does not recompute the selected pin per frame', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
// The matchMedia stub makes the app think it is on a phone, but the map
|
|
// still sizes itself from its container. Narrow it so the map takes its
|
|
// mobile branch, which is the one that reads the sheet inset.
|
|
const style = document.createElement('style');
|
|
style.textContent = '.map-container { width: 400px; }';
|
|
document.head.appendChild(style);
|
|
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');
|
|
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
|
|
|
// updateSelectedPin restarts the pin's drop-in animation (remove/force
|
|
// reflow/add the `active` class) every time it re-runs. Watch the pin's
|
|
// class so a per-frame re-run is detectable without depending on geometry.
|
|
const pin = document.querySelector('.selected-pin-container');
|
|
assert.ok(pin, 'the selected pin is rendered');
|
|
assert.true(pin.classList.contains('active'), 'the pin is active');
|
|
let classMutations = 0;
|
|
const observer = new MutationObserver((records) => {
|
|
classMutations += records.length;
|
|
});
|
|
observer.observe(pin, { attributes: true, attributeFilter: ['class'] });
|
|
|
|
// Simulate the per-frame covered-height writes a drag makes.
|
|
for (const inset of [500, 700, 850]) {
|
|
mapUi.sheetInsetPx = inset;
|
|
await settled();
|
|
}
|
|
classMutations += observer.takeRecords().length;
|
|
observer.disconnect();
|
|
|
|
assert.strictEqual(
|
|
classMutations,
|
|
0,
|
|
'the selected pin is not recomputed while the sheet is resized'
|
|
);
|
|
} finally {
|
|
style.remove();
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('settling the sheet at a new size recenters the selected place', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
const handleStub = sinon.stub(
|
|
MapComponent.prototype,
|
|
'handlePinVisibility'
|
|
);
|
|
const centerStub = sinon.stub(
|
|
MapComponent.prototype,
|
|
'animateToSmartCenter'
|
|
);
|
|
const panStub = sinon.stub(MapComponent.prototype, 'panIfObscured');
|
|
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');
|
|
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
|
|
|
handleStub.resetHistory();
|
|
centerStub.resetHistory();
|
|
panStub.resetHistory();
|
|
|
|
// The modifier publishes the new covered height and bumps the snap
|
|
// sequence together when a drag settles.
|
|
mapUi.sheetInsetPx = mapUi.sheetInsetPx + 140;
|
|
mapUi.sheetSnapSeq = mapUi.sheetSnapSeq + 1;
|
|
await settled();
|
|
|
|
assert.strictEqual(
|
|
handleStub.callCount,
|
|
0,
|
|
'settling does not recompute the selected pin'
|
|
);
|
|
assert.true(
|
|
centerStub.called,
|
|
'the selected place is re-centered after the sheet settles at a new size'
|
|
);
|
|
assert.false(
|
|
panStub.called,
|
|
'a resize re-centers instead of only panning'
|
|
);
|
|
|
|
// A settle that keeps the same detent must fall back to the obscured-pin
|
|
// safety net instead of re-centering.
|
|
centerStub.resetHistory();
|
|
panStub.resetHistory();
|
|
mapUi.sheetSnapSeq = mapUi.sheetSnapSeq + 1;
|
|
await settled();
|
|
assert.false(
|
|
centerStub.called,
|
|
'a same-size settle does not re-center the place'
|
|
);
|
|
assert.true(
|
|
panStub.called,
|
|
'a same-size settle still pans the marker if it is hidden'
|
|
);
|
|
} finally {
|
|
panStub.restore();
|
|
centerStub.restore();
|
|
handleStub.restore();
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
});
|