- 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.
263 lines
7.6 KiB
JavaScript
263 lines
7.6 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { visit, click, currentURL, waitUntil } from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'marco/tests/helpers';
|
|
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 viewport service reads window.matchMedia when it is
|
|
// first instantiated (during the application render), 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;
|
|
},
|
|
}));
|
|
}
|
|
|
|
function makePhoto(id) {
|
|
return {
|
|
id,
|
|
pubkey: 'a'.repeat(64),
|
|
kind: 360,
|
|
created_at: 1,
|
|
tags: [
|
|
['i', 'osm:node:123'],
|
|
[
|
|
'imeta',
|
|
'url data:image/gif;base64,R0lGODlhAQABAAAAACw=',
|
|
'dim 800x600',
|
|
],
|
|
],
|
|
};
|
|
}
|
|
|
|
function clickSavedPlaces() {
|
|
const button = Array.from(document.querySelectorAll('.app-menu button')).find(
|
|
(b) => b.textContent.includes('Saved Places')
|
|
);
|
|
return click(button);
|
|
}
|
|
|
|
module('Acceptance | drawer header', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.owner.register('service:osm', MockOsmService);
|
|
this.owner.register('service:storage', MockStorageService);
|
|
});
|
|
|
|
test('mobile top-level drawer drops the back button and the X closes it', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
await visit('/menu');
|
|
|
|
assert.dom('.sheet-top .sidebar-header').exists('menu header is shown');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header .back-btn')
|
|
.doesNotExist('no back button on mobile');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header-title')
|
|
.includesText('Marco', 'title is shown');
|
|
|
|
await click('.sheet-top .sidebar-header .close-btn');
|
|
assert.strictEqual(
|
|
currentURL(),
|
|
'/',
|
|
'the X closed the top-level drawer'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('mobile X on a child drawer goes back to its parent', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
await visit('/menu');
|
|
await clickSavedPlaces();
|
|
assert.strictEqual(currentURL(), '/lists', 'on the lists index');
|
|
|
|
assert
|
|
.dom('.sheet-top .sidebar-header .back-btn')
|
|
.doesNotExist('no back button on mobile');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header-title')
|
|
.includesText('Saved Places', 'title is shown');
|
|
|
|
await click('.sheet-top .sidebar-header .close-btn');
|
|
assert.strictEqual(
|
|
currentURL(),
|
|
'/menu',
|
|
'the X went back to the parent (menu), not index'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('mobile place details uses the place name as the header title', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
this.owner.lookup('service:nostr-data').placePhotos = [makePhoto('p1')];
|
|
|
|
await visit('/search?lat=1&lon=1');
|
|
await click('.place-item');
|
|
await waitUntil(() =>
|
|
document.querySelector('.sheet-top .sidebar-header-title')
|
|
);
|
|
|
|
assert
|
|
.dom('.sheet-top .sidebar-header-title')
|
|
.includesText('Test Place', 'the place name is the header title');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header-place')
|
|
.exists('the header uses the compact place variant');
|
|
assert
|
|
.dom('.sheet-top .sidebar-content-place')
|
|
.exists('the content uses the place spacing');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header .back-btn')
|
|
.doesNotExist('no back button on mobile');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header.no-border')
|
|
.exists('the place details header is borderless');
|
|
assert
|
|
.dom('.sheet-top .place-details h3')
|
|
.doesNotExist('the name is not repeated in the body');
|
|
|
|
const type = document.querySelector(
|
|
'.sheet-top .place-details .place-type'
|
|
);
|
|
const carousel = document.querySelector(
|
|
'.sheet-top .place-details .photo-carousel'
|
|
);
|
|
assert.ok(type && carousel, 'the type and photo carousel are rendered');
|
|
assert.true(
|
|
Boolean(
|
|
type.compareDocumentPosition(carousel) &
|
|
Node.DOCUMENT_POSITION_FOLLOWING
|
|
),
|
|
'the photo carousel sits below the place type'
|
|
);
|
|
|
|
await click('.sheet-top .sidebar-header .close-btn');
|
|
await waitUntil(() => currentURL().includes('/search'));
|
|
assert.ok(
|
|
currentURL().includes('/search'),
|
|
'the X popped back to the search sheet'
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('place details header keeps the same top gap as a standard drawer header', async function (assert) {
|
|
const matchMediaStub = installMobileMatchMedia();
|
|
try {
|
|
await visit('/search?lat=1&lon=1');
|
|
await waitUntil(() =>
|
|
document.querySelector('.sheet-top .sidebar-header-title')
|
|
);
|
|
|
|
const searchHeader = document.querySelector('.sheet-top .sidebar-header');
|
|
const searchTitle = searchHeader.querySelector('.sidebar-header-title');
|
|
const searchGap =
|
|
searchTitle.getBoundingClientRect().top -
|
|
searchHeader.getBoundingClientRect().top;
|
|
|
|
await click('.place-item');
|
|
await waitUntil(() =>
|
|
document.querySelector(
|
|
'.sheet-top .sidebar-header-place .sidebar-header-title'
|
|
)
|
|
);
|
|
|
|
const placeHeader = document.querySelector(
|
|
'.sheet-top .sidebar-header-place'
|
|
);
|
|
const placeTitle = placeHeader.querySelector('.sidebar-header-title');
|
|
const placeGap =
|
|
placeTitle.getBoundingClientRect().top -
|
|
placeHeader.getBoundingClientRect().top;
|
|
|
|
// Measured relative to the header, so the entrance transition on the
|
|
// sheet itself does not affect the comparison.
|
|
assert.true(
|
|
Math.abs(placeGap - searchGap) <= 3,
|
|
`place header top gap (${placeGap.toFixed(1)}px) matches the standard header (${searchGap.toFixed(1)}px)`
|
|
);
|
|
} finally {
|
|
matchMediaStub.restore();
|
|
}
|
|
});
|
|
|
|
test('desktop keeps the back button and centered title', async function (assert) {
|
|
await visit('/menu');
|
|
await clickSavedPlaces();
|
|
assert.strictEqual(currentURL(), '/lists', 'on the lists index');
|
|
|
|
assert
|
|
.dom('.sheet-top .sidebar-header .back-btn')
|
|
.exists('back button is present on desktop');
|
|
assert
|
|
.dom('.sheet-top .sidebar-header-text-centered')
|
|
.includesText('Saved Places', 'title stays centered on desktop');
|
|
});
|
|
});
|