mirror of
git://jb55.com/damus
synced 2024-09-05 21:03:51 +00:00
tests: add ndb support to tests
stops it from crashing
This commit is contained in:
parent
22d635d850
commit
69c7acea76
@ -285,7 +285,7 @@ public struct ImageFill {
|
|||||||
struct ImageCarousel_Previews: PreviewProvider {
|
struct ImageCarousel_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
|
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
|
||||||
ImageCarousel(state: test_damus_state(), evid: test_note.id, urls: [url, url])
|
ImageCarousel(state: test_damus_state, evid: test_note.id, urls: [url, url])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ let test_invoice = Invoice(description: .description("this is a description"), a
|
|||||||
|
|
||||||
struct InvoiceView_Previews: PreviewProvider {
|
struct InvoiceView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
InvoiceView(our_pubkey: .empty, invoice: test_invoice, settings: test_damus_state().settings)
|
InvoiceView(our_pubkey: .empty, invoice: test_invoice, settings: test_damus_state.settings)
|
||||||
.frame(width: 300, height: 200)
|
.frame(width: 300, height: 200)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ struct InvoicesView: View {
|
|||||||
|
|
||||||
struct InvoicesView_Previews: PreviewProvider {
|
struct InvoicesView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
InvoicesView(our_pubkey: test_note.pubkey, invoices: [Invoice.init(description: .description("description"), amount: .specific(10000), string: "invstr", expiry: 100000, payment_hash: Data(), created_at: 1000000)], settings: test_damus_state().settings)
|
InvoicesView(our_pubkey: test_note.pubkey, invoices: [Invoice.init(description: .description("description"), amount: .specific(10000), string: "invstr", expiry: 100000, payment_hash: Data(), created_at: 1000000)], settings: test_damus_state.settings)
|
||||||
.frame(width: 300)
|
.frame(width: 300)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func use_nip05_color(pubkey: Pubkey, contacts: Contacts) -> Bool {
|
|||||||
|
|
||||||
struct NIP05Badge_Previews: PreviewProvider {
|
struct NIP05Badge_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let test_state = test_damus_state()
|
let test_state = test_damus_state
|
||||||
VStack {
|
VStack {
|
||||||
NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles)
|
NIP05Badge(nip05: NIP05(username: "jb55", host: "jb55.com"), pubkey: test_state.pubkey, contacts: test_state.contacts, show_domain: true, profiles: test_state.profiles)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ struct Reposted: View {
|
|||||||
|
|
||||||
struct Reposted_Previews: PreviewProvider {
|
struct Reposted_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let test_state = test_damus_state()
|
let test_state = test_damus_state
|
||||||
Reposted(damus: test_state, pubkey: test_state.pubkey)
|
Reposted(damus: test_state, pubkey: test_state.pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,9 +168,9 @@ func is_following_hashtag(contacts: NostrEvent?, hashtag: String) -> Bool {
|
|||||||
struct SearchHeaderView_Previews: PreviewProvider {
|
struct SearchHeaderView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
SearchHeaderView(state: test_damus_state(), described: .hashtag("damus"))
|
SearchHeaderView(state: test_damus_state, described: .hashtag("damus"))
|
||||||
|
|
||||||
SearchHeaderView(state: test_damus_state(), described: .unknown)
|
SearchHeaderView(state: test_damus_state, described: .unknown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,6 @@ struct UserStatusSheet: View {
|
|||||||
|
|
||||||
struct UserStatusSheet_Previews: PreviewProvider {
|
struct UserStatusSheet_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
UserStatusSheet(postbox: PostBox(pool: RelayPool(ndb: .empty)), keypair: Keypair(pubkey: .empty, privkey: nil), status: .init())
|
UserStatusSheet(postbox: test_damus_state.postbox, keypair: test_keypair, status: .init())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ extension View {
|
|||||||
|
|
||||||
struct TranslateView_Previews: PreviewProvider {
|
struct TranslateView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
TranslateView(damus_state: ds, event: test_note, size: .normal)
|
TranslateView(damus_state: ds, event: test_note, size: .normal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,6 @@ struct UserView: View {
|
|||||||
|
|
||||||
struct UserView_Previews: PreviewProvider {
|
struct UserView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
UserView(damus_state: test_damus_state(), pubkey: test_note.pubkey)
|
UserView(damus_state: test_damus_state, pubkey: test_note.pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ struct ZapButton_Previews: PreviewProvider {
|
|||||||
let pending_zap = PendingZap(amount_msat: 1000, target: ZapTarget.note(id: test_note.id, author: test_note.pubkey), request: .normal(test_zap_request), type: .pub, state: .external(.init(state: .fetching_invoice)))
|
let pending_zap = PendingZap(amount_msat: 1000, target: ZapTarget.note(id: test_note.id, author: test_note.pubkey), request: .normal(test_zap_request), type: .pub, state: .external(.init(state: .fetching_invoice)))
|
||||||
let zaps = ZapsDataModel([.pending(pending_zap)])
|
let zaps = ZapsDataModel([.pending(pending_zap)])
|
||||||
|
|
||||||
ZapButton(damus_state: test_damus_state(), target: ZapTarget.note(id: test_note.id, author: test_note.pubkey), lnurl: "lnurl", zaps: zaps)
|
ZapButton(damus_state: test_damus_state, target: ZapTarget.note(id: test_note.id, author: test_note.pubkey), lnurl: "lnurl", zaps: zaps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +48,53 @@ let test_private_zap = Zap(event: test_note, invoice: test_zap_invoice, zapper:
|
|||||||
|
|
||||||
let test_pending_zap = PendingZap(amount_msat: 10000, target: .note(id: test_note.id, author: test_note.pubkey), request: .normal(test_zap_request), type: .pub, state: .external(.init(state: .fetching_invoice)))
|
let test_pending_zap = PendingZap(amount_msat: 10000, target: .note(id: test_note.id, author: test_note.pubkey), request: .normal(test_zap_request), type: .pub, state: .external(.init(state: .fetching_invoice)))
|
||||||
|
|
||||||
let test_following_model = FollowingModel(damus_state: test_damus_state(), contacts: [test_pubkey, test_pubkey_2], hashtags: [Hashtag(hashtag: "grownostr"), Hashtag(hashtag: "zapathon")])
|
let test_following_model = FollowingModel(damus_state: test_damus_state, contacts: [test_pubkey, test_pubkey_2], hashtags: [Hashtag(hashtag: "grownostr"), Hashtag(hashtag: "zapathon")])
|
||||||
|
|
||||||
|
|
||||||
func test_damus_state() -> DamusState {
|
var test_damus_state: DamusState = ({
|
||||||
let damus = DamusState.empty
|
// Create a unique temporary directory
|
||||||
|
var tempDir: String!
|
||||||
|
do {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
let temp = fileManager.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||||
|
try fileManager.createDirectory(at: temp, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
tempDir = temp.absoluteString
|
||||||
|
} catch {
|
||||||
|
tempDir = "."
|
||||||
|
}
|
||||||
|
|
||||||
|
print("opening \(tempDir!)")
|
||||||
|
let ndb = Ndb(path: tempDir)!
|
||||||
|
let our_pubkey = test_pubkey
|
||||||
|
let user_search_cache = UserSearchCache()
|
||||||
|
let pool = RelayPool(ndb: ndb)
|
||||||
|
let settings = UserSettingsStore()
|
||||||
|
let damus = DamusState(pool: pool,
|
||||||
|
keypair: test_keypair,
|
||||||
|
likes: .init(our_pubkey: our_pubkey),
|
||||||
|
boosts: .init(our_pubkey: our_pubkey),
|
||||||
|
contacts: .init(our_pubkey: our_pubkey),
|
||||||
|
profiles: .init(user_search_cache: user_search_cache, ndb: ndb),
|
||||||
|
dms: .init(our_pubkey: our_pubkey),
|
||||||
|
previews: .init(),
|
||||||
|
zaps: .init(our_pubkey: our_pubkey),
|
||||||
|
lnurls: .init(),
|
||||||
|
settings: settings,
|
||||||
|
relay_filters: .init(our_pubkey: our_pubkey),
|
||||||
|
relay_model_cache: .init(),
|
||||||
|
drafts: .init(),
|
||||||
|
events: .init(ndb: ndb),
|
||||||
|
bookmarks: .init(pubkey: our_pubkey),
|
||||||
|
postbox: .init(pool: pool),
|
||||||
|
bootstrap_relays: .init(),
|
||||||
|
replies: .init(our_pubkey: our_pubkey),
|
||||||
|
muted_threads: .init(keypair: test_keypair),
|
||||||
|
wallet: .init(settings: settings),
|
||||||
|
nav: .init(),
|
||||||
|
user_search_cache: user_search_cache,
|
||||||
|
music: .init(onChange: {_ in }),
|
||||||
|
video: .init(),
|
||||||
|
ndb: ndb)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io", damus_donation: nil)
|
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io", damus_donation: nil)
|
||||||
@ -60,7 +102,7 @@ func test_damus_state() -> DamusState {
|
|||||||
damus.profiles.add(id: test_pubkey, profile: tsprof)
|
damus.profiles.add(id: test_pubkey, profile: tsprof)
|
||||||
*/
|
*/
|
||||||
return damus
|
return damus
|
||||||
}
|
})()
|
||||||
|
|
||||||
let test_wire_events = """
|
let test_wire_events = """
|
||||||
["EVENT","s",{"id":"d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650049978,"kind":0,"tags":[],"content":"{\\"name\\\":\\"jb55\\",\\"picture\\":\\\"http://cdn.jb55.com/img/red-me.jpg\\",\\"about\\":\\"bitcoin, lightning and nostr dev\\",\\"nip05\\":\\"jb55.com\\"}","sig":"1315045da793c4825de1517149172bf35a6da39d91b7787afb3263721e07bc816cb898996ed8d69af05d6efcd1c926a089bd66cad870bcc361405c11ba302c51"}]
|
["EVENT","s",{"id":"d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650049978,"kind":0,"tags":[],"content":"{\\"name\\\":\\"jb55\\",\\"picture\\":\\\"http://cdn.jb55.com/img/red-me.jpg\\",\\"about\\":\\"bitcoin, lightning and nostr dev\\",\\"nip05\\":\\"jb55.com\\"}","sig":"1315045da793c4825de1517149172bf35a6da39d91b7787afb3263721e07bc816cb898996ed8d69af05d6efcd1c926a089bd66cad870bcc361405c11ba302c51"}]
|
||||||
|
@ -374,7 +374,7 @@ struct LikeButton: View {
|
|||||||
|
|
||||||
struct EventActionBar_Previews: PreviewProvider {
|
struct EventActionBar_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
let ev = NostrEvent(content: "hi", keypair: test_keypair)!
|
let ev = NostrEvent(content: "hi", keypair: test_keypair)!
|
||||||
|
|
||||||
let bar = ActionBarModel.empty()
|
let bar = ActionBarModel.empty()
|
||||||
|
@ -56,6 +56,6 @@ struct EventDetailBar: View {
|
|||||||
|
|
||||||
struct EventDetailBar_Previews: PreviewProvider {
|
struct EventDetailBar_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
EventDetailBar(state: test_damus_state(), target: .empty, target_pk: .empty)
|
EventDetailBar(state: test_damus_state, target: .empty, target_pk: .empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,6 @@ struct RepostAction: View {
|
|||||||
|
|
||||||
struct RepostAction_Previews: PreviewProvider {
|
struct RepostAction_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RepostAction(damus_state: test_damus_state(), event: test_note)
|
RepostAction(damus_state: test_damus_state, event: test_note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,6 @@ struct AddRelayView_Previews: PreviewProvider {
|
|||||||
@State static var relay: String = ""
|
@State static var relay: String = ""
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
AddRelayView(state: test_damus_state())
|
AddRelayView(state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ struct ConfigView: View {
|
|||||||
struct ConfigView_Previews: PreviewProvider {
|
struct ConfigView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
ConfigView(state: test_damus_state())
|
ConfigView(state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ struct DMChatView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
let model = DirectMessageModel(events: [ev], our_pubkey: test_pubkey, pubkey: test_pubkey)
|
let model = DirectMessageModel(events: [ev], our_pubkey: test_pubkey, pubkey: test_pubkey)
|
||||||
|
|
||||||
DMChatView(damus_state: test_damus_state(), dms: model)
|
DMChatView(damus_state: test_damus_state, dms: model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,6 @@ struct DMView: View {
|
|||||||
struct DMView_Previews: PreviewProvider {
|
struct DMView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ev = NostrEvent(content: "Hey there *buddy*, want to grab some drinks later? 🍻", keypair: test_keypair, kind: 1, tags: [])!
|
let ev = NostrEvent(content: "Hey there *buddy*, want to grab some drinks later? 🍻", keypair: test_keypair, kind: 1, tags: [])!
|
||||||
DMView(event: ev, damus_state: test_damus_state())
|
DMView(event: ev, damus_state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func would_filter_non_friends_from_dms(contacts: Contacts, dms: [DirectMessageMo
|
|||||||
|
|
||||||
struct DirectMessagesView_Previews: PreviewProvider {
|
struct DirectMessagesView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
DirectMessagesView(damus_state: ds, model: ds.dms, settings: ds.settings)
|
DirectMessagesView(damus_state: ds, model: ds.dms, settings: ds.settings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ struct EventDetailView: View {
|
|||||||
|
|
||||||
struct EventDetailView_Previews: PreviewProvider {
|
struct EventDetailView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let _ = test_damus_state()
|
let _ = test_damus_state
|
||||||
EventDetailView()
|
EventDetailView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,9 +131,9 @@ struct EventView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EventView( damus: test_damus_state(), event: test_note )
|
EventView( damus: test_damus_state, event: test_note )
|
||||||
|
|
||||||
EventView( damus: test_damus_state(), event: test_longform_event.event, options: [.wide] )
|
EventView( damus: test_damus_state, event: test_longform_event.event, options: [.wide] )
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ struct BuilderEventView: View {
|
|||||||
|
|
||||||
struct BuilderEventView_Previews: PreviewProvider {
|
struct BuilderEventView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
BuilderEventView(damus: test_damus_state(), event_id: test_note.id)
|
BuilderEventView(damus: test_damus_state, event_id: test_note.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,6 @@ struct EventTop: View {
|
|||||||
|
|
||||||
struct EventTop_Previews: PreviewProvider {
|
struct EventTop_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
EventTop(state: test_damus_state(), event: test_note, pubkey: test_note.pubkey, is_anon: false)
|
EventTop(state: test_damus_state, event: test_note, pubkey: test_note.pubkey, is_anon: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ struct ReplyDescription: View {
|
|||||||
|
|
||||||
struct ReplyDescription_Previews: PreviewProvider {
|
struct ReplyDescription_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ReplyDescription(event: test_note, replying_to: test_note, ndb: test_damus_state().ndb)
|
ReplyDescription(event: test_note, replying_to: test_note, ndb: test_damus_state.ndb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,6 @@ struct ReplyPart: View {
|
|||||||
|
|
||||||
struct ReplyPart_Previews: PreviewProvider {
|
struct ReplyPart_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ReplyPart(events: test_damus_state().events, event: test_note, keypair: Keypair(pubkey: .empty, privkey: nil), ndb: test_damus_state().ndb)
|
ReplyPart(events: test_damus_state.events, event: test_note, keypair: Keypair(pubkey: .empty, privkey: nil), ndb: test_damus_state.ndb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,6 @@ struct EventBody: View {
|
|||||||
|
|
||||||
struct EventBody_Previews: PreviewProvider {
|
struct EventBody_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
EventBody(damus_state: test_damus_state(), event: test_note, size: .normal, options: [])
|
EventBody(damus_state: test_damus_state, event: test_note, size: .normal, options: [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,6 @@ struct EventProfile: View {
|
|||||||
|
|
||||||
struct EventProfile_Previews: PreviewProvider {
|
struct EventProfile_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
EventProfile(damus_state: test_damus_state(), pubkey: test_note.pubkey, size: .normal)
|
EventProfile(damus_state: test_damus_state, pubkey: test_note.pubkey, size: .normal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,11 +137,11 @@ struct EventShell_Previews: PreviewProvider {
|
|||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
EventShell(state: test_damus_state(), event: test_note, options: [.no_action_bar]) {
|
EventShell(state: test_damus_state, event: test_note, options: [.no_action_bar]) {
|
||||||
Text(verbatim: "Hello")
|
Text(verbatim: "Hello")
|
||||||
}
|
}
|
||||||
|
|
||||||
EventShell(state: test_damus_state(), event: test_note, options: [.no_action_bar, .wide]) {
|
EventShell(state: test_damus_state, event: test_note, options: [.no_action_bar, .wide]) {
|
||||||
Text(verbatim: "Hello")
|
Text(verbatim: "Hello")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ struct LongformPreview: View {
|
|||||||
struct LongformPreview_Previews: PreviewProvider {
|
struct LongformPreview_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
LongformPreview(state: test_damus_state(), ev: test_longform_event.event, options: [])
|
LongformPreview(state: test_damus_state, ev: test_longform_event.event, options: [])
|
||||||
|
|
||||||
LongformPreview(state: test_damus_state(), ev: test_longform_event.event, options: [.wide])
|
LongformPreview(state: test_damus_state, ev: test_longform_event.event, options: [.wide])
|
||||||
}
|
}
|
||||||
.frame(height: 400)
|
.frame(height: 400)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ let test_longform_event = LongformEvent.parse(from: NostrEvent(
|
|||||||
|
|
||||||
struct LongformView_Previews: PreviewProvider {
|
struct LongformView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let st = test_damus_state()
|
let st = test_damus_state
|
||||||
let artifacts = render_note_content(ev: test_longform_event.event, profiles: st.profiles, keypair: Keypair(pubkey: .empty, privkey: nil))
|
let artifacts = render_note_content(ev: test_longform_event.event, profiles: st.profiles, keypair: Keypair(pubkey: .empty, privkey: nil))
|
||||||
|
|
||||||
let model = NoteArtifactsModel(state: .loaded(artifacts))
|
let model = NoteArtifactsModel(state: .loaded(artifacts))
|
||||||
|
@ -77,7 +77,7 @@ struct MutedEventView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
|
|
||||||
MutedEventView(damus_state: test_damus_state(), event: test_note, selected: false)
|
MutedEventView(damus_state: test_damus_state, event: test_note, selected: false)
|
||||||
.frame(width: .infinity, height: 50)
|
.frame(width: .infinity, height: 50)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,6 @@ struct SelectedEventView: View {
|
|||||||
|
|
||||||
struct SelectedEventView_Previews: PreviewProvider {
|
struct SelectedEventView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SelectedEventView(damus: test_damus_state(), event: test_note, size: .selected)
|
SelectedEventView(damus: test_damus_state, event: test_note, size: .selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,10 @@ func event_is_anonymous(ev: NostrEvent) -> Bool {
|
|||||||
struct TextEvent_Previews: PreviewProvider {
|
struct TextEvent_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack(spacing: 20) {
|
VStack(spacing: 20) {
|
||||||
TextEvent(damus: test_damus_state(), event: test_note, pubkey: test_pubkey, options: [])
|
TextEvent(damus: test_damus_state, event: test_note, pubkey: test_pubkey, options: [])
|
||||||
.frame(height: 400)
|
.frame(height: 400)
|
||||||
|
|
||||||
TextEvent(damus: test_damus_state(), event: test_note, pubkey: test_pubkey, options: [.wide])
|
TextEvent(damus: test_damus_state, event: test_note, pubkey: test_pubkey, options: [.wide])
|
||||||
.frame(height: 400)
|
.frame(height: 400)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,9 @@ struct ZapEvent: View {
|
|||||||
struct ZapEvent_Previews: PreviewProvider {
|
struct ZapEvent_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
ZapEvent(damus: test_damus_state(), zap: .zap(test_zap), is_top_zap: true)
|
ZapEvent(damus: test_damus_state, zap: .zap(test_zap), is_top_zap: true)
|
||||||
|
|
||||||
ZapEvent(damus: test_damus_state(), zap: .zap(test_private_zap), is_top_zap: false)
|
ZapEvent(damus: test_damus_state, zap: .zap(test_private_zap), is_top_zap: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,6 @@ let test_image_url = URL(string: "https://jb55.com/red-me.jpg")!
|
|||||||
|
|
||||||
struct ImageContainerView_Previews: PreviewProvider {
|
struct ImageContainerView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ImageContainerView(video_controller: test_damus_state().video, url: .image(test_image_url), disable_animation: false)
|
ImageContainerView(video_controller: test_damus_state.video, url: .image(test_image_url), disable_animation: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,6 @@ struct ImageView: View {
|
|||||||
struct ImageView_Previews: PreviewProvider {
|
struct ImageView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
|
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
|
||||||
ImageView(video_controller: test_damus_state().video, urls: [url], disable_animation: false)
|
ImageView(video_controller: test_damus_state.video, urls: [url], disable_animation: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,6 @@ func get_mutelist_users(_ mutelist: NostrEvent?) -> Array<Pubkey> {
|
|||||||
|
|
||||||
struct MutelistView_Previews: PreviewProvider {
|
struct MutelistView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
MutelistView(damus_state: test_damus_state(), users: [test_note.pubkey, test_note.pubkey])
|
MutelistView(damus_state: test_damus_state, users: [test_note.pubkey, test_note.pubkey])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,8 +613,8 @@ func trim_prefix(_ str: String) -> String {
|
|||||||
|
|
||||||
struct NoteContentView_Previews: PreviewProvider {
|
struct NoteContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let state = test_damus_state()
|
let state = test_damus_state
|
||||||
let state2 = test_damus_state()
|
let state2 = test_damus_state
|
||||||
|
|
||||||
Group {
|
Group {
|
||||||
VStack {
|
VStack {
|
||||||
|
@ -69,8 +69,9 @@ func determine_reacting_to(our_pubkey: Pubkey, ev: NostrEvent?) -> ReactingTo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func event_author_name(profiles: Profiles, pubkey: Pubkey) -> String {
|
func event_author_name(profiles: Profiles, pubkey: Pubkey) -> String {
|
||||||
let alice_prof_txn = profiles.lookup(id: pubkey).unsafeUnownedValue
|
return profiles.lookup(id: pubkey).map({ profile in
|
||||||
return Profile.displayName(profile: alice_prof_txn, pubkey: pubkey).username.truncate(maxLength: 50)
|
Profile.displayName(profile: profile, pubkey: pubkey).username.truncate(maxLength: 50)
|
||||||
|
}).value
|
||||||
}
|
}
|
||||||
|
|
||||||
func event_group_unique_pubkeys(profiles: Profiles, group: EventGroupType) -> [Pubkey] {
|
func event_group_unique_pubkeys(profiles: Profiles, group: EventGroupType) -> [Pubkey] {
|
||||||
@ -261,11 +262,11 @@ struct EventGroupView: View {
|
|||||||
struct EventGroupView_Previews: PreviewProvider {
|
struct EventGroupView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
EventGroupView(state: test_damus_state(), event: test_note, group: .repost(test_event_group))
|
EventGroupView(state: test_damus_state, event: test_note, group: .repost(test_event_group))
|
||||||
.frame(height: 200)
|
.frame(height: 200)
|
||||||
.padding()
|
.padding()
|
||||||
|
|
||||||
EventGroupView(state: test_damus_state(), event: test_note, group: .reaction(test_event_group))
|
EventGroupView(state: test_damus_state, event: test_note, group: .reaction(test_event_group))
|
||||||
.frame(height: 200)
|
.frame(height: 200)
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,6 @@ let test_notification_item: NotificationItem = .repost(test_note.id, test_event_
|
|||||||
|
|
||||||
struct NotificationItemView_Previews: PreviewProvider {
|
struct NotificationItemView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
NotificationItemView(state: test_damus_state(), item: test_notification_item)
|
NotificationItemView(state: test_damus_state, item: test_notification_item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ struct NotificationsView: View {
|
|||||||
|
|
||||||
struct NotificationsView_Previews: PreviewProvider {
|
struct NotificationsView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
NotificationsView(state: test_damus_state(), notifications: NotificationsModel(), filter: NotificationFilter())
|
NotificationsView(state: test_damus_state, notifications: NotificationsModel(), filter: NotificationFilter())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,6 @@ struct ProfilePicturesView: View {
|
|||||||
struct ProfilePicturesView_Previews: PreviewProvider {
|
struct ProfilePicturesView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let pubkey = test_note.pubkey
|
let pubkey = test_note.pubkey
|
||||||
ProfilePicturesView(state: test_damus_state(), pubkeys: [pubkey, pubkey])
|
ProfilePicturesView(state: test_damus_state, pubkeys: [pubkey, pubkey])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ struct SuggestedUserView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
let user = SuggestedUser(name: "klabo", about: "name", picture: "about", pubkey: test_pubkey)!
|
let user = SuggestedUser(name: "klabo", about: "name", picture: "about", pubkey: test_pubkey)!
|
||||||
List {
|
List {
|
||||||
SuggestedUserView(user: user, damus_state: test_damus_state())
|
SuggestedUserView(user: user, damus_state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,6 @@ struct SuggestedUsersSectionHeader: View {
|
|||||||
|
|
||||||
struct SuggestedUsersView_Previews: PreviewProvider {
|
struct SuggestedUsersView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SuggestedUsersView(model: SuggestedUsersViewModel(damus_state: test_damus_state()))
|
SuggestedUsersView(model: SuggestedUsersViewModel(damus_state: test_damus_state))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ func get_searching_string(_ word: String?) -> String? {
|
|||||||
|
|
||||||
struct PostView_Previews: PreviewProvider {
|
struct PostView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
PostView(action: .posting(.none), damus_state: test_damus_state())
|
PostView(action: .posting(.none), damus_state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ struct UserSearch_Previews: PreviewProvider {
|
|||||||
@State static var newCursorIndex: Int?
|
@State static var newCursorIndex: Int?
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
UserSearch(damus_state: test_damus_state(), search: search, focusWordAttributes: $word, newCursorIndex: $newCursorIndex, post: $post)
|
UserSearch(damus_state: test_damus_state, search: search, focusWordAttributes: $word, newCursorIndex: $newCursorIndex, post: $post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,6 @@ struct CondensedProfilePicturesView: View {
|
|||||||
|
|
||||||
struct CondensedProfilePicturesView_Previews: PreviewProvider {
|
struct CondensedProfilePicturesView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
CondensedProfilePicturesView(state: test_damus_state(), pubkeys: [test_pubkey, test_pubkey, test_pubkey, test_pubkey], maxPictures: 3)
|
CondensedProfilePicturesView(state: test_damus_state, pubkeys: [test_pubkey, test_pubkey, test_pubkey, test_pubkey], maxPictures: 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ struct EditMetadataView: View {
|
|||||||
|
|
||||||
struct EditMetadataView_Previews: PreviewProvider {
|
struct EditMetadataView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
EditMetadataView(damus_state: test_damus_state())
|
EditMetadataView(damus_state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,6 @@ struct EventProfileName: View {
|
|||||||
|
|
||||||
struct EventProfileName_Previews: PreviewProvider {
|
struct EventProfileName_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
EventProfileName(pubkey: test_note.pubkey, damus: test_damus_state())
|
EventProfileName(pubkey: test_note.pubkey, damus: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@ struct MaybeAnonPfpView: View {
|
|||||||
|
|
||||||
struct MaybeAnonPfpView_Previews: PreviewProvider {
|
struct MaybeAnonPfpView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
MaybeAnonPfpView(state: test_damus_state(), is_anon: true, pubkey: ANON_PUBKEY, size: PFP_SIZE)
|
MaybeAnonPfpView(state: test_damus_state, is_anon: true, pubkey: ANON_PUBKEY, size: PFP_SIZE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ struct ProfileEditButton: View {
|
|||||||
struct ProfileEditButton_Previews: PreviewProvider {
|
struct ProfileEditButton_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
Group {
|
Group {
|
||||||
ProfileEditButton(damus_state: test_damus_state())
|
ProfileEditButton(damus_state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,6 @@ struct ProfileName: View {
|
|||||||
|
|
||||||
struct ProfileName_Previews: PreviewProvider {
|
struct ProfileName_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ProfileName(pubkey: test_damus_state().pubkey, damus: test_damus_state())
|
ProfileName(pubkey: test_damus_state.pubkey, damus: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,9 +126,9 @@ struct ProfileNameView: View {
|
|||||||
struct ProfileNameView_Previews: PreviewProvider {
|
struct ProfileNameView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
ProfileNameView(pubkey: test_note.pubkey, damus: test_damus_state())
|
ProfileNameView(pubkey: test_note.pubkey, damus: test_damus_state)
|
||||||
|
|
||||||
ProfileNameView(pubkey: test_note.pubkey, damus: test_damus_state())
|
ProfileNameView(pubkey: test_note.pubkey, damus: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func get_profile_url(picture: String?, pubkey: Pubkey, profiles: Profiles) -> UR
|
|||||||
|
|
||||||
func make_preview_profiles(_ pubkey: Pubkey) -> Profiles {
|
func make_preview_profiles(_ pubkey: Pubkey) -> Profiles {
|
||||||
let user_search_cache = UserSearchCache()
|
let user_search_cache = UserSearchCache()
|
||||||
let profiles = Profiles(user_search_cache: user_search_cache, ndb: .empty)
|
let profiles = Profiles(user_search_cache: user_search_cache, ndb: test_damus_state.ndb)
|
||||||
let picture = "http://cdn.jb55.com/img/red-me.jpg"
|
let picture = "http://cdn.jb55.com/img/red-me.jpg"
|
||||||
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com", damus_donation: nil)
|
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com", damus_donation: nil)
|
||||||
//let ts_profile = TimestampedProfile(profile: profile, timestamp: 0, event: test_note)
|
//let ts_profile = TimestampedProfile(profile: profile, timestamp: 0, event: test_note)
|
||||||
|
@ -505,7 +505,7 @@ struct ProfileView: View {
|
|||||||
|
|
||||||
struct ProfileView_Previews: PreviewProvider {
|
struct ProfileView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
ProfileView(damus_state: ds, pubkey: ds.pubkey)
|
ProfileView(damus_state: ds, pubkey: ds.pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ struct QRCodeView: View {
|
|||||||
|
|
||||||
struct QRCodeView_Previews: PreviewProvider {
|
struct QRCodeView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
QRCodeView(damus_state: test_damus_state(), pubkey: test_note.pubkey)
|
QRCodeView(damus_state: test_damus_state, pubkey: test_note.pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,6 @@ struct ReactionView: View {
|
|||||||
|
|
||||||
struct ReactionView_Previews: PreviewProvider {
|
struct ReactionView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ReactionView(damus_state: test_damus_state(), reaction: NostrEvent(content: "🤙🏼", keypair: test_keypair)!)
|
ReactionView(damus_state: test_damus_state, reaction: NostrEvent(content: "🤙🏼", keypair: test_keypair)!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ struct ReactionsView: View {
|
|||||||
|
|
||||||
struct ReactionsView_Previews: PreviewProvider {
|
struct ReactionsView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let state = test_damus_state()
|
let state = test_damus_state
|
||||||
ReactionsView(damus_state: state, model: ReactionsModel(state: state, target: test_note.id))
|
ReactionsView(damus_state: state, model: ReactionsModel(state: state, target: test_note.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,6 @@ struct RelayFilterView: View {
|
|||||||
|
|
||||||
struct RelayFilterView_Previews: PreviewProvider {
|
struct RelayFilterView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RelayFilterView(state: test_damus_state(), timeline: .search)
|
RelayFilterView(state: test_damus_state, timeline: .search)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,6 +128,6 @@ struct RecommendedRelayView: View {
|
|||||||
|
|
||||||
struct RecommendedRelayView_Previews: PreviewProvider {
|
struct RecommendedRelayView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RecommendedRelayView(damus: test_damus_state(), relay: "wss://relay.damus.io", user_recommended: true)
|
RecommendedRelayView(damus: test_damus_state, relay: "wss://relay.damus.io", user_recommended: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,6 @@ struct RelayConfigView: View {
|
|||||||
|
|
||||||
struct RelayConfigView_Previews: PreviewProvider {
|
struct RelayConfigView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RelayConfigView(state: test_damus_state())
|
RelayConfigView(state: test_damus_state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,6 @@ struct RelayDetailView: View {
|
|||||||
struct RelayDetailView_Previews: PreviewProvider {
|
struct RelayDetailView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let metadata = RelayMetadata(name: "name", description: "desc", pubkey: test_pubkey, contact: "contact", supported_nips: [1,2,3], software: "software", version: "version", limitation: Limitations.empty, payments_url: "https://jb55.com", icon: "")
|
let metadata = RelayMetadata(name: "name", description: "desc", pubkey: test_pubkey, contact: "contact", supported_nips: [1,2,3], software: "software", version: "version", limitation: Limitations.empty, payments_url: "https://jb55.com", icon: "")
|
||||||
RelayDetailView(state: test_damus_state(), relay: "relay", nip11: metadata)
|
RelayDetailView(state: test_damus_state, relay: "relay", nip11: metadata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ struct RelayStatusView: View {
|
|||||||
|
|
||||||
struct RelayStatusView_Previews: PreviewProvider {
|
struct RelayStatusView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let connection = test_damus_state().pool.get_relay("wss://relay.damus.io")!.connection
|
let connection = test_damus_state.pool.get_relay("wss://relay.damus.io")!.connection
|
||||||
RelayStatusView(connection: connection)
|
RelayStatusView(connection: connection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ struct RelayToggle: View {
|
|||||||
|
|
||||||
struct RelayToggle_Previews: PreviewProvider {
|
struct RelayToggle_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RelayToggle(state: test_damus_state(), timeline: .search, relay_id: "wss://jb55.com")
|
RelayToggle(state: test_damus_state, timeline: .search, relay_id: "wss://jb55.com")
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,6 @@ struct RelayView: View {
|
|||||||
|
|
||||||
struct RelayView_Previews: PreviewProvider {
|
struct RelayView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RelayView(state: test_damus_state(), relay: "wss://relay.damus.io", showActionButtons: .constant(false))
|
RelayView(state: test_damus_state, relay: "wss://relay.damus.io", showActionButtons: .constant(false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,6 @@ struct SignalView: View {
|
|||||||
|
|
||||||
struct SignalView_Previews: PreviewProvider {
|
struct SignalView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
SignalView(state: test_damus_state(), signal: SignalModel(signal: 5, max_signal: 10))
|
SignalView(state: test_damus_state, signal: SignalModel(signal: 5, max_signal: 10))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,13 +93,13 @@ struct ReplyView_Previews: PreviewProvider {
|
|||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack {
|
VStack {
|
||||||
ReplyView(replying_to: test_note,
|
ReplyView(replying_to: test_note,
|
||||||
damus: test_damus_state(),
|
damus: test_damus_state,
|
||||||
original_pubkeys: [],
|
original_pubkeys: [],
|
||||||
filtered_pubkeys: .constant([]))
|
filtered_pubkeys: .constant([]))
|
||||||
.frame(height: 300)
|
.frame(height: 300)
|
||||||
|
|
||||||
ReplyView(replying_to: test_longform_event.event,
|
ReplyView(replying_to: test_longform_event.event,
|
||||||
damus: test_damus_state(),
|
damus: test_damus_state,
|
||||||
original_pubkeys: [],
|
original_pubkeys: [],
|
||||||
filtered_pubkeys: .constant([]))
|
filtered_pubkeys: .constant([]))
|
||||||
.frame(height: 300)
|
.frame(height: 300)
|
||||||
|
@ -129,7 +129,7 @@ struct ReportView: View {
|
|||||||
|
|
||||||
struct ReportView_Previews: PreviewProvider {
|
struct ReportView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
VStack {
|
VStack {
|
||||||
|
|
||||||
ReportView(postbox: ds.postbox, target: ReportTarget.user(test_pubkey), keypair: test_keypair.to_full()!)
|
ReportView(postbox: ds.postbox, target: ReportTarget.user(test_pubkey), keypair: test_keypair.to_full()!)
|
||||||
|
@ -18,7 +18,7 @@ struct RepostView: View {
|
|||||||
|
|
||||||
struct RepostView_Previews: PreviewProvider {
|
struct RepostView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RepostView(damus_state: test_damus_state(), repost: NostrEvent(content: "", keypair: test_keypair)!)
|
RepostView(damus_state: test_damus_state, repost: NostrEvent(content: "", keypair: test_keypair)!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,6 @@ struct RepostedEvent: View {
|
|||||||
|
|
||||||
struct RepostedEvent_Previews: PreviewProvider {
|
struct RepostedEvent_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RepostedEvent(damus: test_damus_state(), event: test_note, inner_ev: test_note, options: [])
|
RepostedEvent(damus: test_damus_state, event: test_note, inner_ev: test_note, options: [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ struct RepostsView: View {
|
|||||||
|
|
||||||
struct RepostsView_Previews: PreviewProvider {
|
struct RepostsView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let state = test_damus_state()
|
let state = test_damus_state
|
||||||
RepostsView(damus_state: state, model: RepostsModel(state: state, target: test_note.id))
|
RepostsView(damus_state: state, model: RepostsModel(state: state, target: test_note.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ struct SearchingEventView: View {
|
|||||||
|
|
||||||
struct SearchingEventView_Previews: PreviewProvider {
|
struct SearchingEventView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let state = test_damus_state()
|
let state = test_damus_state
|
||||||
SearchingEventView(state: state, search_type: .event(test_note.id))
|
SearchingEventView(state: state, search_type: .event(test_note.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ struct SearchHomeView: View {
|
|||||||
|
|
||||||
struct SearchHomeView_Previews: PreviewProvider {
|
struct SearchHomeView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let state = test_damus_state()
|
let state = test_damus_state
|
||||||
SearchHomeView(damus_state: state, model: SearchHomeModel(damus_state: state))
|
SearchHomeView(damus_state: state, model: SearchHomeModel(damus_state: state))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func describe_search(_ filter: NostrFilter) -> DescribedSearch {
|
|||||||
|
|
||||||
struct SearchView_Previews: PreviewProvider {
|
struct SearchView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let test_state = test_damus_state()
|
let test_state = test_damus_state
|
||||||
let filter = NostrFilter(hashtag: ["bitcoin"])
|
let filter = NostrFilter(hashtag: ["bitcoin"])
|
||||||
|
|
||||||
let model = SearchModel(state: test_state, search: filter)
|
let model = SearchModel(state: test_state, search: filter)
|
||||||
|
@ -107,6 +107,6 @@ struct AppearanceSettingsView: View {
|
|||||||
|
|
||||||
struct TextFormattingSettings_Previews: PreviewProvider {
|
struct TextFormattingSettings_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
AppearanceSettingsView(damus_state: test_damus_state(), settings: UserSettingsStore())
|
AppearanceSettingsView(damus_state: test_damus_state, settings: UserSettingsStore())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ struct SideMenuView: View {
|
|||||||
|
|
||||||
struct Previews_SideMenuView_Previews: PreviewProvider {
|
struct Previews_SideMenuView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
SideMenuView(damus_state: ds, isSidebarVisible: .constant(true))
|
SideMenuView(damus_state: ds, isSidebarVisible: .constant(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ struct ThreadView: View {
|
|||||||
|
|
||||||
struct ThreadView_Previews: PreviewProvider {
|
struct ThreadView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let state = test_damus_state()
|
let state = test_damus_state
|
||||||
let thread = ThreadModel(event: test_note, damus_state: state)
|
let thread = ThreadModel(event: test_note, damus_state: state)
|
||||||
ThreadView(state: state, thread: thread)
|
ThreadView(state: state, thread: thread)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ struct InnerTimelineView: View {
|
|||||||
|
|
||||||
struct InnerTimelineView_Previews: PreviewProvider {
|
struct InnerTimelineView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
InnerTimelineView(events: test_event_holder, damus: test_damus_state(), filter: { _ in true })
|
InnerTimelineView(events: test_event_holder, damus: test_damus_state, filter: { _ in true })
|
||||||
.frame(width: 300, height: 500)
|
.frame(width: 300, height: 500)
|
||||||
.border(Color.red)
|
.border(Color.red)
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,6 @@ struct UserRelaysView: View {
|
|||||||
|
|
||||||
struct UserRelaysView_Previews: PreviewProvider {
|
struct UserRelaysView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
UserRelaysView(state: test_damus_state(), relays: [])
|
UserRelaysView(state: test_damus_state, relays: [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,10 +194,10 @@ struct WalletView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let test_wallet_connect_url = WalletConnectURL(pubkey: test_pubkey, relay: .init("wss://relay.damus.io")!, keypair: test_damus_state().keypair.to_full()!, lud16: "jb55@sendsats.com")
|
let test_wallet_connect_url = WalletConnectURL(pubkey: test_pubkey, relay: .init("wss://relay.damus.io")!, keypair: test_damus_state.keypair.to_full()!, lud16: "jb55@sendsats.com")
|
||||||
|
|
||||||
struct WalletView_Previews: PreviewProvider {
|
struct WalletView_Previews: PreviewProvider {
|
||||||
static let tds = test_damus_state()
|
static let tds = test_damus_state
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
WalletView(damus_state: tds, model: WalletModel(state: .existing(test_wallet_connect_url), settings: tds.settings))
|
WalletView(damus_state: tds, model: WalletModel(state: .existing(test_wallet_connect_url), settings: tds.settings))
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ extension View {
|
|||||||
|
|
||||||
struct CustomizeZapView_Previews: PreviewProvider {
|
struct CustomizeZapView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
CustomizeZapView(state: test_damus_state(), target: ZapTarget.note(id: test_note.id, author: test_note.pubkey), lnurl: "")
|
CustomizeZapView(state: test_damus_state, target: ZapTarget.note(id: test_note.id, author: test_note.pubkey), lnurl: "")
|
||||||
.frame(width: 400, height: 600)
|
.frame(width: 400, height: 600)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ struct ZapTypePicker: View {
|
|||||||
struct ZapTypePicker_Previews: PreviewProvider {
|
struct ZapTypePicker_Previews: PreviewProvider {
|
||||||
@State static var zap_type: ZapType = .pub
|
@State static var zap_type: ZapType = .pub
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state
|
||||||
ZapTypePicker(zap_type: $zap_type, settings: ds.settings, profiles: ds.profiles, pubkey: test_pubkey)
|
ZapTypePicker(zap_type: $zap_type, settings: ds.settings, profiles: ds.profiles, pubkey: test_pubkey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ struct ZapUserView: View {
|
|||||||
|
|
||||||
struct ZapUserView_Previews: PreviewProvider {
|
struct ZapUserView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ZapUserView(state: test_damus_state(), pubkey: ANON_PUBKEY)
|
ZapUserView(state: test_damus_state, pubkey: ANON_PUBKEY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,6 @@ struct ZapsView: View {
|
|||||||
|
|
||||||
struct ZapsView_Previews: PreviewProvider {
|
struct ZapsView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ZapsView(state: test_damus_state(), target: .profile(test_pubkey))
|
ZapsView(state: test_damus_state, target: .profile(test_pubkey))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ final class EventGroupViewTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testEventAuthorName() {
|
func testEventAuthorName() {
|
||||||
let damusState = test_damus_state()
|
let damusState = test_damus_state
|
||||||
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: test_pubkey), "damus")
|
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: test_pubkey), "damus")
|
||||||
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: test_pubkey_2), "1rppft3m:4qxhsgnj")
|
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: test_pubkey_2), "1rppft3m:4qxhsgnj")
|
||||||
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: ANON_PUBKEY), "Anonymous")
|
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: ANON_PUBKEY), "Anonymous")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEventGroupUniquePubkeys() {
|
func testEventGroupUniquePubkeys() {
|
||||||
let damusState = test_damus_state()
|
let damusState = test_damus_state
|
||||||
|
|
||||||
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
|
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ final class EventGroupViewTests: XCTestCase {
|
|||||||
|
|
||||||
func testReactingToText() throws {
|
func testReactingToText() throws {
|
||||||
let enUsLocale = Locale(identifier: "en-US")
|
let enUsLocale = Locale(identifier: "en-US")
|
||||||
let damusState = test_damus_state()
|
let damusState = test_damus_state
|
||||||
|
|
||||||
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
|
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ final class LongPostTests: XCTestCase {
|
|||||||
XCTAssertEqual(subid, "subid")
|
XCTAssertEqual(subid, "subid")
|
||||||
XCTAssertTrue(ev.should_show_event)
|
XCTAssertTrue(ev.should_show_event)
|
||||||
XCTAssertTrue(!ev.too_big)
|
XCTAssertTrue(!ev.too_big)
|
||||||
XCTAssertTrue(should_show_event(keypair: test_keypair, hellthreads: test_damus_state().muted_threads, contacts: contacts, ev: ev))
|
XCTAssertTrue(should_show_event(keypair: test_keypair, hellthreads: test_damus_state.muted_threads, contacts: contacts, ev: ev))
|
||||||
XCTAssertTrue(validate_event(ev: ev) == .ok )
|
XCTAssertTrue(validate_event(ev: ev) == .ok )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class NoteContentViewTests: XCTestCase {
|
|||||||
let note = NostrEvent(content: content, keypair: test_keypair, tags: [["t", "かっこいい"]])!
|
let note = NostrEvent(content: content, keypair: test_keypair, tags: [["t", "かっこいい"]])!
|
||||||
let parsed: Blocks = parse_note_content(content: .init(note: note, keypair: test_keypair))
|
let parsed: Blocks = parse_note_content(content: .init(note: note, keypair: test_keypair))
|
||||||
|
|
||||||
let testState = test_damus_state()
|
let testState = test_damus_state
|
||||||
|
|
||||||
let text: NoteArtifactsSeparated = render_blocks(blocks: parsed, profiles: testState.profiles)
|
let text: NoteArtifactsSeparated = render_blocks(blocks: parsed, profiles: testState.profiles)
|
||||||
let attributedText: AttributedString = text.content.attributed
|
let attributedText: AttributedString = text.content.attributed
|
||||||
|
@ -21,24 +21,25 @@ final class ProfileViewTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testFollowedByString() throws {
|
func testFollowedByString() throws {
|
||||||
let profiles = test_damus_state().profiles
|
|
||||||
|
|
||||||
let pk1 = test_pubkey
|
let pk1 = test_pubkey
|
||||||
let pk2 = test_pubkey_2
|
let pk2 = test_pubkey_2
|
||||||
let pk3 = Pubkey(hex: "b42e44b555013239a0d5dcdb09ebde0857cd8a5a57efbba5a2b6ac78833cb9f0")!
|
let pk3 = Pubkey(hex: "b42e44b555013239a0d5dcdb09ebde0857cd8a5a57efbba5a2b6ac78833cb9f0")!
|
||||||
let pk4 = Pubkey(hex: "cc590e46363d0fa66bb27081368d01f169b8ffc7c614629d4e9eef6c88b38670")!
|
let pk4 = Pubkey(hex: "cc590e46363d0fa66bb27081368d01f169b8ffc7c614629d4e9eef6c88b38670")!
|
||||||
let pk5 = Pubkey(hex: "f2aa579bb998627e04a8f553842a09446360c9d708c6141dd119c479f6ab9d29")!
|
let pk5 = Pubkey(hex: "f2aa579bb998627e04a8f553842a09446360c9d708c6141dd119c479f6ab9d29")!
|
||||||
|
|
||||||
XCTAssertEqual(followedByString([pk1], profiles: profiles, locale: enUsLocale), "Followed by damus")
|
let ndb = Ndb(path: Ndb.db_path)!
|
||||||
XCTAssertEqual(followedByString([pk1, pk2], profiles: profiles, locale: enUsLocale), "Followed by damus & 1rppft3m:4qxhsgnj")
|
let txn = NdbTxn(ndb: ndb)
|
||||||
XCTAssertEqual(followedByString([pk1, pk2, pk3], profiles: profiles, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj & 1kshyfd2:cq04aze0")
|
|
||||||
XCTAssertEqual(followedByString([pk1, pk2, pk3, pk4,], profiles: profiles, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 1 other")
|
XCTAssertEqual(followedByString(txn: txn, [pk1], ndb: ndb, locale: enUsLocale), "Followed by damus")
|
||||||
XCTAssertEqual(followedByString([pk1, pk2, pk3, pk4, pk5], profiles: profiles, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 2 others")
|
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2], ndb: ndb, locale: enUsLocale), "Followed by damus & 1rppft3m:4qxhsgnj")
|
||||||
|
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2, pk3], ndb: ndb, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj & 1kshyfd2:cq04aze0")
|
||||||
|
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2, pk3, pk4,], ndb: ndb, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 1 other")
|
||||||
|
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2, pk3, pk4, pk5], ndb: ndb, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 2 others")
|
||||||
|
|
||||||
let pubkeys = [pk1, pk2, pk3, pk4, pk5, pk1, pk2, pk3, pk4, pk5]
|
let pubkeys = [pk1, pk2, pk3, pk4, pk5, pk1, pk2, pk3, pk4, pk5]
|
||||||
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
|
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
|
||||||
for count in 1...10 {
|
for count in 1...10 {
|
||||||
XCTAssertNoThrow(followedByString(pubkeys.prefix(count).map { $0 }, profiles: profiles, locale: $0))
|
XCTAssertNoThrow(followedByString(txn: txn, pubkeys.prefix(count).map { $0 }, ndb: ndb, locale: $0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import XCTest
|
|||||||
final class UserSearchCacheTests: XCTestCase {
|
final class UserSearchCacheTests: XCTestCase {
|
||||||
|
|
||||||
var keypair: FullKeypair? = nil
|
var keypair: FullKeypair? = nil
|
||||||
let damusState = DamusState.empty
|
let damusState = test_damus_state
|
||||||
let nip05 = "_@somedomain.com"
|
let nip05 = "_@somedomain.com"
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
@ -55,11 +55,6 @@ final class UserSearchCacheTests: XCTestCase {
|
|||||||
|
|
||||||
damusState.profiles.set_validated(keypair.pubkey, nip05: NIP05.parse(newNip05))
|
damusState.profiles.set_validated(keypair.pubkey, nip05: NIP05.parse(newNip05))
|
||||||
|
|
||||||
let newProfile = Profile(name: "whoami", display_name: "T-DAWG", about: nil, picture: nil, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: newNip05, damus_donation: nil)
|
|
||||||
|
|
||||||
// Lookup to synchronize access on profiles dictionary to avoid race conditions.
|
|
||||||
let _ = damusState.profiles.lookup(id: keypair.pubkey)
|
|
||||||
|
|
||||||
// Old profile attributes are removed from cache.
|
// Old profile attributes are removed from cache.
|
||||||
XCTAssertEqual(damusState.user_search_cache.search(key: "tyiu"), [])
|
XCTAssertEqual(damusState.user_search_cache.search(key: "tyiu"), [])
|
||||||
XCTAssertEqual(damusState.user_search_cache.search(key: "ty"), [])
|
XCTAssertEqual(damusState.user_search_cache.search(key: "ty"), [])
|
||||||
|
@ -69,7 +69,7 @@ final class ZapTests: XCTestCase {
|
|||||||
XCTAssertEqual(zap.target, ZapTarget.profile(profile))
|
XCTAssertEqual(zap.target, ZapTarget.profile(profile))
|
||||||
|
|
||||||
XCTAssertEqual(zap_notification_title(zap), "Zap")
|
XCTAssertEqual(zap_notification_title(zap), "Zap")
|
||||||
XCTAssertEqual(zap_notification_body(profiles: Profiles(user_search_cache: UserSearchCache(), ndb: .empty), zap: zap), "You received 1k sats from 107jk7ht:2quqncxg")
|
XCTAssertEqual(zap_notification_body(profiles: Profiles(user_search_cache: UserSearchCache(), ndb: test_damus_state.ndb), zap: zap), "You received 1k sats from 107jk7ht:2quqncxg")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,15 @@ class Ndb {
|
|||||||
let ndb: ndb_t
|
let ndb: ndb_t
|
||||||
|
|
||||||
static var db_path: String {
|
static var db_path: String {
|
||||||
(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.absoluteString.replacingOccurrences(of: "file://", with: ""))!
|
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.absoluteString
|
||||||
|
return remove_file_prefix(path!)
|
||||||
}
|
}
|
||||||
|
|
||||||
static var empty: Ndb {
|
static var empty: Ndb {
|
||||||
Ndb(ndb: ndb_t(ndb: nil))
|
Ndb(ndb: ndb_t(ndb: nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
init?() {
|
init?(path: String? = nil) {
|
||||||
//try? FileManager.default.removeItem(atPath: Ndb.db_path + "/lock.mdb")
|
//try? FileManager.default.removeItem(atPath: Ndb.db_path + "/lock.mdb")
|
||||||
//try? FileManager.default.removeItem(atPath: Ndb.db_path + "/data.mdb")
|
//try? FileManager.default.removeItem(atPath: Ndb.db_path + "/data.mdb")
|
||||||
|
|
||||||
@ -27,7 +28,9 @@ class Ndb {
|
|||||||
let ingest_threads: Int32 = 4
|
let ingest_threads: Int32 = 4
|
||||||
var mapsize: Int = 1024 * 1024 * 1024 * 32
|
var mapsize: Int = 1024 * 1024 * 1024 * 32
|
||||||
|
|
||||||
let ok = Ndb.db_path.withCString { testdir in
|
let path = path.map(remove_file_prefix) ?? Ndb.db_path
|
||||||
|
|
||||||
|
let ok = path.withCString { testdir in
|
||||||
var ok = false
|
var ok = false
|
||||||
while !ok && mapsize > 1024 * 1024 * 700 {
|
while !ok && mapsize > 1024 * 1024 * 700 {
|
||||||
ok = ndb_init(&ndb_p, testdir, mapsize, ingest_threads) != 0
|
ok = ndb_init(&ndb_p, testdir, mapsize, ingest_threads) != 0
|
||||||
@ -199,3 +202,8 @@ func getDebugCheckedRoot<T: FlatBufferObject>(byteBuffer: inout ByteBuffer) thro
|
|||||||
return getRoot(byteBuffer: &byteBuffer)
|
return getRoot(byteBuffer: &byteBuffer)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
func remove_file_prefix(_ str: String) -> String {
|
||||||
|
return str.replacingOccurrences(of: "file://", with: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -8,12 +8,26 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
@testable import damus
|
@testable import damus
|
||||||
|
|
||||||
|
func test_ndb_dir() -> String? {
|
||||||
|
do {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
let tempDir = fileManager.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||||
|
try fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
return remove_file_prefix(tempDir.absoluteString)
|
||||||
|
} catch {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final class NdbTests: XCTestCase {
|
final class NdbTests: XCTestCase {
|
||||||
|
var db_dir: String = ""
|
||||||
|
|
||||||
override func setUpWithError() throws {
|
override func setUpWithError() throws {
|
||||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
guard let db = test_ndb_dir() else {
|
||||||
try? FileManager.default.removeItem(atPath: Ndb.db_path + "/lock.mdb")
|
XCTFail("Could not create temp directory")
|
||||||
try? FileManager.default.removeItem(atPath: Ndb.db_path + "/data.mdb")
|
return
|
||||||
|
}
|
||||||
|
db_dir = db
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tearDownWithError() throws {
|
override func tearDownWithError() throws {
|
||||||
@ -41,26 +55,27 @@ final class NdbTests: XCTestCase {
|
|||||||
func test_ndb_init() {
|
func test_ndb_init() {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let ndb = Ndb()!
|
let ndb = Ndb(path: db_dir)!
|
||||||
let ok = ndb.process_events(test_wire_events)
|
let ok = ndb.process_events(test_wire_events)
|
||||||
XCTAssertTrue(ok)
|
XCTAssertTrue(ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let ndb = Ndb()!
|
let ndb = Ndb(path: db_dir)!
|
||||||
let id = NoteId(hex: "d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349")!
|
let id = NoteId(hex: "d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349")!
|
||||||
let note = ndb.lookup_note(id)
|
let txn = NdbTxn(ndb: ndb)
|
||||||
|
let note = ndb.lookup_note_with_txn(id: id, txn: txn)
|
||||||
XCTAssertNotNil(note)
|
XCTAssertNotNil(note)
|
||||||
guard let note else { return }
|
guard let note else { return }
|
||||||
let pk = Pubkey(hex: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245")!
|
let pk = Pubkey(hex: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245")!
|
||||||
XCTAssertEqual(note.pubkey, pk)
|
XCTAssertEqual(note.pubkey, pk)
|
||||||
|
|
||||||
let profile = ndb.lookup_profile(pk)
|
let profile = ndb.lookup_profile_with_txn(pk, txn: txn)
|
||||||
XCTAssertNotNil(profile)
|
XCTAssertNotNil(profile)
|
||||||
guard let profile else { return }
|
guard let profile else { return }
|
||||||
|
|
||||||
XCTAssertEqual(profile.profile?.name, "jb55")
|
XCTAssertEqual(profile.profile?.name, "jb55")
|
||||||
XCTAssertEqual(profile.lnurl, "fixme")
|
XCTAssertEqual(profile.lnurl, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user