From 804a7f0bf924ed00f2583c254050852542bef2bb Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 13 Nov 2024 10:15:02 -0800 Subject: [PATCH] test: add args column test Adding a testcase for a bug I noticed on another branch Signed-off-by: William Casarin --- src/args.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/args.rs b/src/args.rs index 9ac7d92..4d98e7d 100644 --- a/src/args.rs +++ b/src/args.rs @@ -247,3 +247,61 @@ impl ArgColumn { } } } + +#[cfg(test)] +mod tests { + use crate::{ + app::Damus, + result::Result, + storage::{delete_file, write_file, Directory}, + Error, + }; + + use std::path::{Path, PathBuf}; + + fn create_tmp_dir() -> PathBuf { + tempfile::TempDir::new() + .expect("tmp path") + .path() + .to_path_buf() + } + + fn rmrf(path: impl AsRef) { + std::fs::remove_dir_all(path); + } + + #[tokio::test] + async fn test_column_args() { + let tmpdir = create_tmp_dir(); + let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s"; + let args = vec![ + "--no-keystore", + "--pub", + npub, + "-c", + "notifications", + "-c", + "contacts", + ] + .iter() + .map(|s| s.to_string()) + .collect(); + + let ctx = egui::Context::default(); + let app = Damus::new(&ctx, &tmpdir, args); + + assert_eq!(app.columns.columns().len(), 2); + + let tl1 = app.columns.column(0).router().top().timeline_id(); + let tl2 = app.columns.column(1).router().top().timeline_id(); + + assert_eq!(tl1.is_some(), true); + assert_eq!(tl2.is_some(), true); + + let timelines = app.columns.timelines(); + assert!(timelines[0].kind.is_notifications()); + assert!(timelines[1].kind.is_contacts()); + + rmrf(tmpdir); + } +}