test: assert composer draft map stays within maxDraftCount

Newest keys win when the store is already full so prefs cannot grow without bound.
This commit is contained in:
Taksh 2026-07-31 11:44:52 +03:00
parent 8090d9421d
commit c887c313cd

View File

@ -62,3 +62,15 @@ struct ComposerDraftStoreTests {
#expect(defaults.object(forKey: ComposerDraftStore.storageKey) == nil)
}
}
@Test func maxDraftCountEvictsSurplusKeys() {
let defaults = makeDefaults()
for index in 0..<ComposerDraftStore.maxDraftCount {
ComposerDraftStore.save("d\(index)", for: .location(geohash: String(format: "gh%04d", index)), in: defaults)
}
ComposerDraftStore.save("newest", for: .mesh, in: defaults)
let map = defaults.dictionary(forKey: ComposerDraftStore.storageKey) as? [String: String] ?? [:]
#expect(map.count == ComposerDraftStore.maxDraftCount)
#expect(map["mesh"] == "newest")
}
}