Drawer headers: a shared DrawerHeader component renders the desktop nav-bar layout (back + centered title + close) and a mobile variant (left title, no back button, a single X that dismisses the top sheet — back when there is a parent, otherwise close). Place details uses the place name as its title with a compact, borderless header, and on mobile moves the photos below the place type. The X and back buttons now have aria-labels. Sheet scrolling: the content only scrolls while the sheet is at its largest detent; below that, dragging anywhere on the sheet (including list rows and links, not just the header) resizes it. At the largest detent, pulling down on the content while it is scrolled to the top shrinks the sheet (overscroll to shrink). Place details opens at the medium detent again. The mobile photo carousel no longer bleeds to the sheet edges, gets a wider gap and the same corner radius as the action buttons.
223 lines
6.2 KiB
JavaScript
223 lines
6.2 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('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');
|
|
});
|
|
});
|