Skip to content

Commit

Permalink
test(term): add filter entries integration test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Jun 9, 2024
1 parent 659aa81 commit d005d0d
Show file tree
Hide file tree
Showing 16 changed files with 605 additions and 76 deletions.
13 changes: 13 additions & 0 deletions crates/synd_term/src/application/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ApplicationBuilder<

pub(super) authenticator: Option<Authenticator>,
pub(super) interactor: Option<Interactor>,
pub(super) dry_run: bool,
}

impl Default for ApplicationBuilder {
Expand All @@ -37,6 +38,7 @@ impl Default for ApplicationBuilder {
theme: (),
authenticator: None,
interactor: None,
dry_run: false,
}
}
}
Expand All @@ -53,6 +55,7 @@ impl<T1, T2, T3, T4, T5> ApplicationBuilder<(), T1, T2, T3, T4, T5> {
theme: self.theme,
authenticator: self.authenticator,
interactor: self.interactor,
dry_run: self.dry_run,
}
}
}
Expand All @@ -69,6 +72,7 @@ impl<T1, T2, T3, T4, T5> ApplicationBuilder<T1, (), T2, T3, T4, T5> {
theme: self.theme,
authenticator: self.authenticator,
interactor: self.interactor,
dry_run: self.dry_run,
}
}
}
Expand All @@ -88,6 +92,7 @@ impl<T1, T2, T3, T4, T5> ApplicationBuilder<T1, T2, (), T3, T4, T5> {
theme: self.theme,
authenticator: self.authenticator,
interactor: self.interactor,
dry_run: self.dry_run,
}
}
}
Expand All @@ -104,6 +109,7 @@ impl<T1, T2, T3, T4, T5> ApplicationBuilder<T1, T2, T3, (), T4, T5> {
theme: self.theme,
authenticator: self.authenticator,
interactor: self.interactor,
dry_run: self.dry_run,
}
}
}
Expand All @@ -120,6 +126,7 @@ impl<T1, T2, T3, T4, T5> ApplicationBuilder<T1, T2, T3, T4, (), T5> {
theme: self.theme,
authenticator: self.authenticator,
interactor: self.interactor,
dry_run: self.dry_run,
}
}
}
Expand All @@ -136,6 +143,7 @@ impl<T1, T2, T3, T4, T5> ApplicationBuilder<T1, T2, T3, T4, T5, ()> {
theme,
authenticator: self.authenticator,
interactor: self.interactor,
dry_run: self.dry_run,
}
}
}
Expand All @@ -156,6 +164,11 @@ impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, T2, T3, T4, T5, T6> {
..self
}
}

#[must_use]
pub fn dry_run(self, dry_run: bool) -> Self {
Self { dry_run, ..self }
}
}

impl ApplicationBuilder<Terminal, Client, Categories, Cache, Config, Theme> {
Expand Down
7 changes: 6 additions & 1 deletion crates/synd_term/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl Application {
theme,
authenticator,
interactor,
dry_run,
} = builder;

let key_handlers = {
Expand Down Expand Up @@ -158,7 +159,11 @@ impl Application {
key_handlers,
categories,
latest_release: None,
flags: Should::empty(),
flags: if dry_run {
Should::Quit
} else {
Should::empty()
},
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/synd_term/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub struct Args {
pub api: ApiOptions,
#[command(flatten)]
pub feed: FeedOptions,
#[arg(hide = true, long = "dry-run", hide_long_help = true)]
pub dry_run: bool,
}

#[derive(clap::Args, Debug)]
Expand Down
19 changes: 19 additions & 0 deletions crates/synd_term/src/keymap/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,28 @@ macro_rules! key {
crossterm::event::KeyCode::Tab,
))
};
( esc ) => {
crossterm::event::Event::Key(crossterm::event::KeyEvent::from(
crossterm::event::KeyCode::Esc,
))
};
( backspace ) => {
crossterm::event::Event::Key(crossterm::event::KeyEvent::from(
crossterm::event::KeyCode::Backspace,
))
};
( $char:literal ) => {
crossterm::event::Event::Key(crossterm::event::KeyEvent::from(
crossterm::event::KeyCode::Char($char),
))
};
}

#[macro_export]
macro_rules! shift {
( $char:literal ) => {{
let mut k = crossterm::event::KeyEvent::from(crossterm::event::KeyCode::Char($char));
k.modifiers.insert(crossterm::event::KeyModifiers::SHIFT);
crossterm::event::Event::Key(k)
}};
}
4 changes: 4 additions & 0 deletions crates/synd_term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn build_app(
entries_limit,
}: FeedOptions,
cache_dir: PathBuf,
dry_run: bool,
) -> anyhow::Result<Application> {
let app = Application::builder()
.terminal(Terminal::new().context("Failed to construct terminal")?)
Expand All @@ -84,6 +85,7 @@ fn build_app(
})
.cache(Cache::new(cache_dir))
.theme(Theme::with_palette(&palette.into()))
.dry_run(dry_run)
.build();

Ok(app)
Expand All @@ -101,6 +103,7 @@ async fn main() {
cache_dir,
command,
palette,
dry_run,
} = cli::parse();

// Subcommand logs to the terminal, tui writes logs to a file.
Expand All @@ -125,6 +128,7 @@ async fn main() {
palette,
feed,
cache_dir,
dry_run,
))
.and_then(|app| {
tracing::info!("Running...");
Expand Down
10 changes: 10 additions & 0 deletions crates/synd_term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ pub struct Context<'a> {
pub in_flight: &'a InFlight,
pub categories: &'a Categories,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn default_icon_is_not_empty() {
assert!(!default_icon().symbol().is_empty());
}
}
42 changes: 42 additions & 0 deletions crates/synd_term/src/ui/widgets/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,45 @@ impl Prompt {
Line::from(spans).render(area, buf);
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn prompt_ascii() {
let mut p = Prompt::new();
assert!(matches!(
p.handle_key_event(&KeyEvent::from(KeyCode::Char('a'))),
KeyEventResult::Consumed { .. }
));

p.handle_key_event(&KeyEvent::from(KeyCode::Char('b')));
p.handle_key_event(&KeyEvent::from(KeyCode::Char('c')));
assert_eq!(p.line(), "abc");

assert!(matches!(
p.handle_key_event(&KeyEvent::from(KeyCode::Enter)),
KeyEventResult::Ignored
));
}

#[test]
fn prompt_grapheme() {
let mut p = Prompt::new();
// insert multi byte
p.handle_key_event(&KeyEvent::from(KeyCode::Char('山')));
p.handle_key_event(&KeyEvent::from(KeyCode::Char('口')));
p.handle_key_event(&KeyEvent::from(KeyCode::Backspace));

assert_eq!(p.line(), "山");

p.handle_key_event(&KeyEvent::from(KeyCode::Backspace));
assert_eq!(p.line(), "");

p.handle_key_event(&KeyEvent::from(KeyCode::Backspace));
p.handle_key_event(&KeyEvent::from(KeyCode::Backspace));
p.handle_key_event(&KeyEvent::from(KeyCode::Backspace));
assert_eq!(p.line(), "");
}
}
27 changes: 7 additions & 20 deletions crates/synd_term/src/ui/widgets/throbber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ pub struct ThrobberState {
}

impl ThrobberState {
/// Get a index.
pub fn index(&self) -> i8 {
self.index
}
pub fn calc_next(&mut self) {
self.calc_step(1);
}

pub fn calc_step(&mut self, step: i8) {
self.index = self.index.saturating_add(step);
}
Expand Down Expand Up @@ -72,18 +64,6 @@ impl<'a> Throbber<'a> {
self
}

#[must_use]
pub fn style(mut self, style: Style) -> Self {
self.style = style;
self
}

#[must_use]
pub fn throbber_style(mut self, style: Style) -> Self {
self.throbber_style = style;
self
}

#[must_use]
pub fn throbber_set(mut self, set: throbber::Set) -> Self {
self.throbber_set = set;
Expand Down Expand Up @@ -205,9 +185,16 @@ pub mod throbber {
};

/// ["⣧", "⣏", "⡟", "⠿", "⢻", "⣹", "⣼", "⣶"]
#[cfg(not(feature = "integration"))]
pub const BRAILLE_EIGHT_DOUBLE: Set = Set {
full: "⣿",
empty: " ",
symbols: &["⣧", "⣏", "⡟", "⠿", "⢻", "⣹", "⣼", "⣶"],
};
#[cfg(feature = "integration")]
pub const BRAILLE_EIGHT_DOUBLE: Set = Set {
full: "⣿",
empty: " ",
symbols: &["⣧", "⣧", "⣧", "⣧", "⣧", "⣧", "⣧", "⣧"],
};
}
Loading

0 comments on commit d005d0d

Please sign in to comment.