fix: keep pull request filters session-local

This commit is contained in:
Valdemar Lorenzen
2026-10-21 13:56:24 +02:00
parent fbcb519e13
commit ea7c240eb6
9 changed files with 86 additions and 53 deletions
+27 -4
View File
@@ -59,18 +59,43 @@ fn loading_is_lazy_and_applied_preferences_round_trip_atomically() {
);
store.save(&preferences).unwrap();
let (_, loaded, notice) = Store::load(Ok(path.clone()));
assert_eq!(loaded, preferences);
assert_eq!(loaded.sort, preferences.sort);
assert_eq!(loaded.filters, Preferences::default().filters);
assert!(!fs::read_to_string(&path).unwrap().contains("filters"));
assert!(notice.is_none());
preferences.filters.clear();
preferences.sort.clear();
store.save(&preferences).unwrap();
assert_eq!(Store::load(Ok(path)).1, preferences);
assert_eq!(Store::load(Ok(path)).1, Preferences::default());
assert_eq!(
fs::read_dir(fixture.0.join("state/vamp")).unwrap().count(),
1
);
}
#[test]
fn previously_saved_filters_are_ignored_without_changing_sort_or_file() {
let fixture = Fixture::new();
let path = fixture.path();
fs::create_dir_all(path.parent().unwrap()).unwrap();
for filters in [
r#"[]"#,
r#"["approved"]"#,
r#"["unknown"]"#,
r#"{"invalid":true}"#,
] {
let bytes = format!(
r#"{{"version":1,"preferences":{{"sort":{{"created_at":{{"precedence":1,"direction":"asc"}}}},"filters":{filters}}}}}"#
);
fs::write(&path, &bytes).unwrap();
let (_, loaded, notice) = Store::load(Ok(path.clone()));
assert!(notice.is_none());
assert_eq!(loaded.filters, Preferences::default().filters);
assert_eq!(loaded.sort[&SortField::CreatedAt].direction, Direction::Asc);
assert_eq!(fs::read_to_string(&path).unwrap(), bytes);
}
}
#[test]
fn corrupt_incompatible_and_invalid_data_is_preserved_even_after_apply() {
let fixture = Fixture::new();
@@ -83,8 +108,6 @@ fn corrupt_incompatible_and_invalid_data_is_preserved_even_after_apply() {
r#"{"version":1,"preferences":{"sort":{"updated_at":{"direction":"up"}}}}"#,
r#"{"version":1,"preferences":{"sort":{"updated_at":{"precedence":0}}}}"#,
r#"{"version":1,"preferences":{"sort":{"updated_at":{"precedence":1},"created_at":{"precedence":1}}}}"#,
r#"{"version":1,"preferences":{"filters":["unknown"]}}"#,
r#"{"version":1,"preferences":{"filters":["requested","requested"]}}"#,
] {
fs::write(&path, bytes).unwrap();
let (store, loaded, notice) = Store::load(Ok(path.clone()));