Files
bitchat/bitchatTests/LocationChannelsTests.swift
T
a0a973eb81 Fixes/location channels (#465)
* Remove "street" location channel; add coverage + names; style mesh

- Drop GeohashChannelLevel.street and update mappings/tests\n- Map geohash lengths >=8 to Block in teleport, no Street\n- Show ~distance coverage (mi/km via Locale.measurementSystem) next to each #geohash\n- Add reverse geocoding to display coarse names (country/region/city/neighborhood) per level\n- Style "#mesh" row title with toolbar blue\n- Fix iOS 16 deprecation: use Locale.measurementSystem

* Project: update Xcode project (auto)

* UI: use '~' without trailing space before location name in sheet

* Location sheet: poll for location at regular intervals while open (replace significant-move updates)

* UI: show Bluetooth range next to #bluetooth in location sheet

* UI: remove leading '#' from mesh title in location sheet

* UI: bold location name in sheet when geohash has >0 people; refactor row to render subtitle pieces

* UI: bold mesh/level titles when participant count > 0; factor meshCount()

---------

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
2025-08-21 01:01:29 +02:00

46 lines
2.0 KiB
Swift

import XCTest
@testable import bitchat
final class LocationChannelsTests: XCTestCase {
func testGeohashEncoderPrecisionMapping() {
// Sanity: known coords (Statue of Liberty approx)
let lat = 40.6892
let lon = -74.0445
let block = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.block.precision)
let neighborhood = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.neighborhood.precision)
let city = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.city.precision)
let region = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.region.precision)
let country = Geohash.encode(latitude: lat, longitude: lon, precision: GeohashChannelLevel.country.precision)
XCTAssertEqual(block.count, 7)
XCTAssertEqual(neighborhood.count, 6)
XCTAssertEqual(city.count, 5)
XCTAssertEqual(region.count, 4)
XCTAssertEqual(country.count, 2)
// All prefixes must match progressively
XCTAssertTrue(block.hasPrefix(neighborhood))
XCTAssertTrue(neighborhood.hasPrefix(city))
XCTAssertTrue(city.hasPrefix(region))
XCTAssertTrue(region.hasPrefix(country))
}
func testNostrGeohashFilterEncoding() throws {
let gh = "u4pruy"
let filter = NostrFilter.geohashEphemeral(gh)
let data = try JSONEncoder().encode(filter)
let json = String(data: data, encoding: .utf8) ?? ""
// Expect kinds includes 20000 and tag filter '#g':[gh]
XCTAssertTrue(json.contains("20000"))
XCTAssertTrue(json.contains("\"#g\":[\"\(gh)\"]"))
}
func testPerGeohashIdentityDeterministic() throws {
// Derive twice for same geohash; should be identical
let gh = "u4pruy"
let id1 = try NostrIdentityBridge.deriveIdentity(forGeohash: gh)
let id2 = try NostrIdentityBridge.deriveIdentity(forGeohash: gh)
XCTAssertEqual(id1.publicKeyHex, id2.publicKeyHex)
}
}