feat(navigation): refine mobile station explorer
This commit is contained in:
@@ -3,6 +3,7 @@ import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const source = fs.readFileSync(new URL('../app.js', import.meta.url), 'utf8');
|
||||
const styles = fs.readFileSync(new URL('../styles.css', import.meta.url), 'utf8');
|
||||
const sandbox = {
|
||||
console,
|
||||
document: { addEventListener() {}, getElementById() { return null; } },
|
||||
@@ -48,7 +49,7 @@ assert.equal(sandbox.stationNodeCount, 3);
|
||||
assert.equal(sandbox.locationOptionCount, 8);
|
||||
vm.runInNewContext(`
|
||||
globalThis.inferredDistrict = stationDistrictName({ province: '浙江省', city: '嘉兴市', address: '嘉兴市海盐县海盐经济开发区' });
|
||||
state.locationFilter = { province: '', city: '', district: '' };
|
||||
state.locationFilters = [];
|
||||
state.query = '广州';
|
||||
globalThis.queryMatches = stationMatchesQuery({ name: '广州合作站' });
|
||||
globalThis.queryMisses = stationMatchesQuery({ name: '杭州合作站' });
|
||||
@@ -56,18 +57,47 @@ vm.runInNewContext(`
|
||||
assert.equal(sandbox.inferredDistrict, '海盐县');
|
||||
assert.equal(sandbox.queryMatches, true);
|
||||
assert.equal(sandbox.queryMisses, false);
|
||||
vm.runInNewContext(`
|
||||
state.query = '';
|
||||
state.locationFilters = [
|
||||
{ level: 'city', province: '广东省', city: '广州市', district: '', label: '广州' },
|
||||
{ level: 'city', province: '浙江省', city: '嘉兴市', district: '', label: '嘉兴' }
|
||||
];
|
||||
globalThis.multiLocationMatches = [
|
||||
stationMatchesLocation({ province: '广东省', city: '广州市', district: '白云区' }),
|
||||
stationMatchesLocation({ province: '浙江省', city: '嘉兴市', district: '海盐县' }),
|
||||
stationMatchesLocation({ province: '广东省', city: '深圳市', district: '南山区' })
|
||||
];
|
||||
`, sandbox);
|
||||
assert.equal(sandbox.multiLocationMatches.join(','), 'true,true,false');
|
||||
assert.ok(Math.abs(sandbox.distanceKm([113, 23], [114, 23]) - 102.4) < 1);
|
||||
assert.match(source, /zoom < 11\) return 'city'/);
|
||||
assert.match(source, /state\.userLocation && left\.kind === 'station'/);
|
||||
assert.doesNotMatch(source, /rankSecondaryTab|setRank\(/);
|
||||
assert.match(source, /stationSearchSuggestions/);
|
||||
assert.match(source, /handleStationSearchInput/);
|
||||
assert.match(source, /locationFilters/);
|
||||
assert.match(source, /renderLocationFilterChips/);
|
||||
assert.match(source, /kpiTotal|kpiPartner/);
|
||||
const index = fs.readFileSync(new URL('../index.html', import.meta.url), 'utf8');
|
||||
assert.match(index, /station-summary-strip/);
|
||||
assert.match(index, /station-status-card/);
|
||||
assert.equal((index.match(/id="statusTotal"/g) || []).length, 1);
|
||||
assert.equal((index.match(/id="mobileStatusTotal"/g) || []).length, 1);
|
||||
assert.match(source, /window\.setTimeout\(\(\) => \{ state\.query = value/);
|
||||
assert.match(source, /focusSearchResults\(\)/);
|
||||
assert.match(source, /visibleOnly && !normalize\(state\.query\)/);
|
||||
assert.match(source, /station-list-partner-tag/);
|
||||
assert.match(source, /station-list-partner-tag\$\{node\.cooperative \? '' : ' is-placeholder'\}/);
|
||||
assert.match(source, /node\.kind === 'station' \? '' : `\$\{formatNumber\(node\.count\)\} 座`/);
|
||||
assert.match(source, /node\.cooperative \? 'H₂ · 合作' : ''/);
|
||||
assert.doesNotMatch(source, /在线 \$\{formatNumber\(node\.online\)\}/);
|
||||
assert.doesNotMatch(source, /monthlyHydrogenKg|totalHydrogenKg|vehicle/);
|
||||
assert.match(source, /uri\.amap\.com\/navigation/);
|
||||
assert.equal((source.match(/function navigateToStation\(/g) || []).length, 1);
|
||||
assert.match(styles, /station-summary-strip/);
|
||||
assert.match(styles, /header-kpi-group,\n \.station-navigation-shell \.station-status-card/);
|
||||
assert.match(styles, /theme-switcher-bw \.bw-btn span \{ display: none; \}/);
|
||||
assert.match(styles, /height: clamp\(430px, 58dvh, 540px\)/);
|
||||
assert.match(styles, /map-action-controls \.glass-btn:nth-child\(2\)/);
|
||||
console.log('station navigation app tests: ok');
|
||||
|
||||
@@ -30,6 +30,9 @@ class StationNavigationTest(unittest.TestCase):
|
||||
def test_static_assets_are_fingerprinted(self):
|
||||
self.assertRegex(server.STATIC_ASSET_VERSION, r"^[0-9a-f]{16}$")
|
||||
|
||||
def test_static_assets_resolve_from_the_release_directory(self):
|
||||
self.assertIn('directory=str(ROOT)', Path(__file__).parents[1].joinpath('server.py').read_text(encoding='utf-8'))
|
||||
|
||||
def test_default_cache_window_is_two_minutes(self):
|
||||
self.assertEqual(server.STATION_CACHE_SECONDS, 120)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user