Skip to content

Commit

Permalink
Tidy up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Nov 20, 2024
1 parent 5abf1d0 commit 942ad0b
Showing 1 changed file with 16 additions and 42 deletions.
58 changes: 16 additions & 42 deletions tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ fn setup_env_files_with_hidden(include_hidden: bool) -> App {
)
}

#[tokio::test]
async fn test_ignores_hidden_files_by_default() {
let mut app = setup_env_files_with_hidden(false);
async fn hidden_files_test_impl(include_hidden: bool) {
let mut app = setup_env_files_with_hidden(include_hidden);

app.search_fields = SearchFields::with_values(r"This", "bar", false, "");

Expand All @@ -431,8 +430,14 @@ async fn test_ignores_hidden_files_by_default() {
if let scooter::Results::SearchComplete(search_state) = &app.results {
let expected_matches = [
(Path::new("dir1").join("file1.txt"), 1),
(Path::new(".dir2").join("file2.rs"), 0),
(Path::new(".file3.txt").to_path_buf(), 0),
(
Path::new(".dir2").join("file2.rs"),
if include_hidden { 1 } else { 0 },
),
(
Path::new(".file3.txt").to_path_buf(),
if include_hidden { 1 } else { 0 },
),
];
for (file_path, num_matches) in expected_matches.clone() {
assert_eq!(
Expand Down Expand Up @@ -461,44 +466,13 @@ async fn test_ignores_hidden_files_by_default() {
}

#[tokio::test]
async fn test_includes_hidden_files_with_flag() {
let mut app = setup_env_files_with_hidden(true);

app.search_fields = SearchFields::with_values(r"This", "bar", false, "");

let result = app.update_search_results();
assert!(result.is_ok());
async fn test_ignores_hidden_files_by_default() {
hidden_files_test_impl(false).await;
}

if let scooter::Results::SearchComplete(search_state) = &app.results {
let expected_matches = [
(Path::new("dir1").join("file1.txt"), 1),
(Path::new(".dir2").join("file2.rs"), 1),
(Path::new(".file3.txt").to_path_buf(), 1),
];
for (file_path, num_matches) in expected_matches.clone() {
assert_eq!(
search_state
.results
.iter()
.filter(|result| {
let result_path = result.path.to_str().unwrap();
let file_path = file_path.to_str().unwrap();
result_path.contains(file_path)
})
.count(),
num_matches
);
}
assert_eq!(
search_state.results.len(),
expected_matches
.map(|(_, count)| count)
.into_iter()
.sum::<usize>()
);
} else {
panic!("Expected SearchComplete results");
}
#[tokio::test]
async fn test_includes_hidden_files_with_flag() {
hidden_files_test_impl(true).await;
}

// TODO:
Expand Down

0 comments on commit 942ad0b

Please sign in to comment.