commit c4d9b5cd3c29f39a3802b098df9f82dcc89bb3f2
parent 9642b9243db949e1241651ed89c8c3866daa03bd
Author: kernelkind <kernelkind@gmail.com>
Date: Fri, 19 Apr 2024 19:44:20 -0400
Extract the sample relay to test_data for reuse
Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
@@ -20,6 +20,7 @@ mod profile;
pub mod relay_pool_manager;
pub mod relay_view;
mod result;
+mod test_data;
mod time;
mod timecache;
mod timeline;
diff --git a/src/relay_view.rs b/src/relay_view.rs
@@ -172,41 +172,34 @@ fn get_connection_icon(status: &RelayStatus) -> egui::Image<'static> {
// PREVIEWS
-pub struct RelayViewPreview {
- pool: RelayPool,
-}
-
-#[allow(unused_must_use)]
-impl RelayViewPreview {
- fn new() -> Self {
- let mut pool = RelayPool::new();
- let wakeup = move || {};
+mod preview {
+ use super::*;
+ use crate::test_data::sample_pool;
- pool.add_url("wss://relay.damus.io".to_string(), wakeup);
- pool.add_url("wss://eden.nostr.land".to_string(), wakeup);
- pool.add_url("wss://nostr.wine".to_string(), wakeup);
- pool.add_url("wss://nos.lol".to_string(), wakeup);
- pool.add_url("wss://test_relay_url_long_00000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_string(), wakeup);
+ pub struct RelayViewPreview {
+ pool: RelayPool,
+ }
- for _ in 0..20 {
- pool.add_url("tmp".to_string(), wakeup);
+ impl RelayViewPreview {
+ fn new() -> Self {
+ RelayViewPreview {
+ pool: sample_pool(),
+ }
}
-
- RelayViewPreview { pool }
}
-}
-impl View for RelayViewPreview {
- fn ui(&mut self, ui: &mut egui::Ui) {
- self.pool.try_recv();
- RelayView::new(RelayPoolManager::new(&mut self.pool)).ui(ui)
+ impl View for RelayViewPreview {
+ fn ui(&mut self, ui: &mut egui::Ui) {
+ self.pool.try_recv();
+ RelayView::new(RelayPoolManager::new(&mut self.pool)).ui(ui)
+ }
}
-}
-impl<'a> Preview for RelayView<'a> {
- type Prev = RelayViewPreview;
+ impl<'a> Preview for RelayView<'a> {
+ type Prev = RelayViewPreview;
- fn preview() -> Self::Prev {
- RelayViewPreview::new()
+ fn preview() -> Self::Prev {
+ RelayViewPreview::new()
+ }
}
}
diff --git a/src/test_data.rs b/src/test_data.rs
@@ -0,0 +1,19 @@
+use enostr::RelayPool;
+
+#[allow(unused_must_use)]
+pub fn sample_pool() -> RelayPool {
+ let mut pool = RelayPool::new();
+ let wakeup = move || {};
+
+ pool.add_url("wss://relay.damus.io".to_string(), wakeup);
+ pool.add_url("wss://eden.nostr.land".to_string(), wakeup);
+ pool.add_url("wss://nostr.wine".to_string(), wakeup);
+ pool.add_url("wss://nos.lol".to_string(), wakeup);
+ pool.add_url("wss://test_relay_url_long_00000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_string(), wakeup);
+
+ for _ in 0..20 {
+ pool.add_url("tmp".to_string(), wakeup);
+ }
+
+ pool
+}