From 86074d2976f992e7292b39dd97373983c54810a5 Mon Sep 17 00:00:00 2001
From: jugeeya <jugeeya@live.com>
Date: Thu, 17 Aug 2023 12:53:17 -0700
Subject: [PATCH] Small test refactor

---
 training_mod_tui/src/main.rs | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/training_mod_tui/src/main.rs b/training_mod_tui/src/main.rs
index 8b43435..ef7a6af 100644
--- a/training_mod_tui/src/main.rs
+++ b/training_mod_tui/src/main.rs
@@ -187,6 +187,23 @@ fn test_save_and_reset_defaults() -> Result<(), Box<dyn Error>> {
     Ok(())
 }
 
+fn _get_frame_buffer(
+    mut terminal: Terminal<training_mod_tui::TestBackend>,
+    mut app: training_mod_tui::App,
+) -> Result<String, Box<dyn Error>> {
+    let frame_res = terminal.draw(|f| training_mod_tui::ui(f, &mut app))?;
+    let mut full_frame_buffer = String::new();
+    for (i, cell) in frame_res.buffer.content().iter().enumerate() {
+        full_frame_buffer.push_str(&cell.symbol);
+        if i % frame_res.area.width as usize == frame_res.area.width as usize - 1 {
+            full_frame_buffer.push_str("\n");
+        }
+    }
+    full_frame_buffer.push_str("\n");
+
+    Ok(full_frame_buffer)
+}
+
 #[test]
 fn test_toggle_naming() -> Result<(), Box<dyn Error>> {
     let menu;
@@ -204,16 +221,8 @@ fn test_toggle_naming() -> Result<(), Box<dyn Error>> {
     // Set Mash Airdodge
     app.on_a();
 
-    let frame_res = terminal.draw(|f| training_mod_tui::ui(f, &mut app))?;
-    let mut full_frame_buffer = String::new();
-    for (i, cell) in frame_res.buffer.content().iter().enumerate() {
-        full_frame_buffer.push_str(&cell.symbol);
-        if i % frame_res.area.width as usize == frame_res.area.width as usize - 1 {
-            full_frame_buffer.push_str("\n");
-        }
-    }
-    full_frame_buffer.push_str("\n");
-    assert!(full_frame_buffer.contains("Airdodge"));
+    let frame_buffer = _get_frame_buffer(terminal, app)?;
+    assert!(frame_buffer.contains("Airdodge"));
 
     Ok(())
 }