Skip to content

Commit

Permalink
test(term): use insta for buffer assersions
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed May 25, 2024
1 parent f6714a4 commit 72f90cb
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 205 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ futures-util = { version = "0.3.30", default-features = false }
graphql_client = { version = "0.13.0", default-features = false }
headers = { version = "0.4.0" }
http = { version = "0.2" } # request use 0.2
insta = { version = "1.39" }
itertools = { version = "0.12", default-features = false, features = ["use_std"] }
kvsd = { version = "0.1.3", default-features = false }
moka = { version = "0.12.7", features = ["future"] }
Expand Down
1 change: 1 addition & 0 deletions crates/synd_term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ synd-api = { path = "../synd_api" }
synd-test = { path = "../synd_test" }

axum-server = { workspace = true }
insta = { workspace = true }
kvsd = { workspace = true }
serial_test = { version = "3.0.0", default_features = false, features = ["async", "file_locks"] }
tempfile = "3"
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ impl Application {

#[cfg(feature = "integration")]
impl Application {
pub fn assert_buffer(&self, expected: &ratatui::buffer::Buffer) {
self.terminal.assert_buffer(expected);
pub fn buffer(&self) -> &ratatui::buffer::Buffer {
self.terminal.buffer()
}
}
4 changes: 2 additions & 2 deletions crates/synd_term/src/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Terminal {
}

#[cfg(feature = "integration")]
pub fn assert_buffer(&self, expected: &Buffer) {
self.backend.backend().assert_buffer(expected);
pub fn buffer(&self) -> &Buffer {
self.backend.backend().buffer()
}
}
201 changes: 3 additions & 198 deletions crates/synd_term/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod test {
let endpoint = format!("https://localhost:{api_port}/graphql")
.parse()
.unwrap();
let terminal = helper::new_test_terminal();
let terminal = helper::new_test_terminal(120, 30);
let client = Client::new(endpoint, Duration::from_secs(30)).unwrap();
let device_flows = DeviceFlows {
github: DeviceFlow::new(
Expand All @@ -65,57 +65,14 @@ mod test {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
let mut event_stream = UnboundedReceiverStream::new(rx);
let theme = Theme::default();
// let bg = theme.background.bg.unwrap_or_default();

let mut application =
Application::with(terminal, client, Categories::default_toml(), config)
.with_theme(theme.clone())
.with_authenticator(authenticator);
application.event_loop_until_idle(&mut event_stream).await;

// login
// #[rustfmt::skip]
// let mut expected = Buffer::with_lines(vec![
// " ",
// " ",
// " ",
// " ",
// " ",
// " Login ",
// " ──────────────────────────────── ",
// " >> 󰊤 GitHub ",
// " 󰊭 Google ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// "  q   j/k 󰹹  Ent 󰏌  ",
// ]);
// for y in 0..expected.area.height {
// for x in 0..expected.area.width {
// expected.get_mut(x, y).set_bg(bg);
// }
// }
// // title
// for x in 38..43 {
// expected
// .get_mut(x, 5)
// .set_style(Style::new().add_modifier(Modifier::BOLD));
// }
// // auth provider
// for x in 24..56 {
// expected
// .get_mut(x, 7)
// .set_style(Style::new().add_modifier(Modifier::BOLD));
// }

// application.assert_buffer(&expected);
insta::assert_debug_snapshot!(application.buffer());

tracing::info!("Login assertion OK");

Expand All @@ -124,55 +81,7 @@ mod test {
tx.send(Ok(event)).unwrap();
application.event_loop_until_idle(&mut event_stream).await;

// assert login prompt
// #[rustfmt::skip]
// let mut expected = Buffer::with_lines(vec![
// " ",
// " ",
// " ",
// " ",
// " ",
// " Login ",
// " ──────────────────────────────── ",
// " Open the following URL and Enter ",
// " ",
// " URL: https://syndicationd.ymgyt ",
// " Code: UC123456 ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// " ",
// ]);
// for y in 0..expected.area.height {
// for x in 0..expected.area.width {
// expected.get_mut(x, y).set_bg(bg);
// }
// }
// // title
// for x in 38..43 {
// expected
// .get_mut(x, 5)
// .set_style(Style::new().add_modifier(Modifier::BOLD));
// }
// // Bold url
// for x in 30..56 {
// expected
// .get_mut(x, 9)
// .set_style(Style::new().add_modifier(Modifier::BOLD));
// }
// // Bold code
// for x in 30..38 {
// expected
// .get_mut(x, 10)
// .set_style(Style::new().add_modifier(Modifier::BOLD));
// }

// application.assert_buffer(&expected);
insta::assert_debug_snapshot!(application.buffer());

tracing::info!("Login prompt assertion OK");

Expand All @@ -181,110 +90,6 @@ mod test {
// polling device access token complete
application.event_loop_until_idle(&mut event_stream).await;

// it would be better to reconsider the current implementation of test
// for instance, assertions for buffers should be performed on a per-component basis
// while here, do snapshots via insta
/*
#[rustfmt::skip]
let mut expected = Buffer::with_lines(vec![
" Syndicationd Entries Feeds ",
" ",
" Published Title Feed ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Summary━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
" ",
" ",
" ",
" ",
" q Quit Tab Next Tab j/k Up/Down Ent Open Entry "
]);
for y in 0..expected.area.height {
for x in 0..expected.area.width {
expected.get_mut(x, y).set_bg(bg);
}
}
// tab line
{
// syndicationd
for x in 4..16 {
expected.get_mut(x, 0).set_style(theme.application_title);
}
// Entries tab left padding
for x in 58..62 {
expected.get_mut(x, 0).set_style(theme.tabs);
}
// selected entries tab
for x in 62..69 {
expected.get_mut(x, 0).set_style(theme.tabs_selected);
}
// left padding and subscription
for x in 69..78 {
expected.get_mut(x, 0).set_style(theme.tabs);
}
}
// table header
{
for x in 1..expected.area.width - 1 {
expected.get_mut(x, 2).set_style(theme.entries.header);
}
}
// prompt
{
// q
for x in 13..16 {
expected.get_mut(x, 19).set_style(theme.prompt.key);
}
// Quit
for x in 16..22 {
expected.get_mut(x, 19).set_style(theme.prompt.key_desc);
}
// Tab
for x in 22..27 {
expected.get_mut(x, 19).set_style(theme.prompt.key);
}
// Next Tab
for x in 27..37 {
expected.get_mut(x, 19).set_style(theme.prompt.key_desc);
}
// j/k
for x in 37..42 {
expected.get_mut(x, 19).set_style(theme.prompt.key);
}
// Up/Down
for x in 42..51 {
expected.get_mut(x, 19).set_style(theme.prompt.key_desc);
}
// r
for x in 51..54 {
expected.get_mut(x, 19).set_style(theme.prompt.key);
}
// Reload
for x in 54..62 {
expected.get_mut(x, 19).set_style(theme.prompt.key_desc);
}
// Ent
for x in 62..67 {
expected.get_mut(x, 19).set_style(theme.prompt.key);
}
// Open entry
for x in 67..79 {
expected.get_mut(x, 19).set_style(theme.prompt.key_desc);
}
}
application.assert_buffer(&expected);
*/

Ok(())
}
}
Loading

0 comments on commit 72f90cb

Please sign in to comment.