forked from janek/mostr
fix(tasks): properly test quick access bookmarks and view
This commit is contained in:
parent
0cf354942e
commit
94976905d3
1 changed files with 22 additions and 17 deletions
39
src/tasks.rs
39
src/tasks.rs
|
@ -562,7 +562,7 @@ impl TasksRelay {
|
||||||
self.search_depth + self.view_depth,
|
self.search_depth + self.view_depth,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.resolve_tasks_rec(view.into_iter(), true, self.view_depth)
|
self.resolve_tasks_rec(view.into_iter(), true, self.view_depth + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,7 +577,7 @@ impl TasksRelay {
|
||||||
.chain(
|
.chain(
|
||||||
// Latest
|
// Latest
|
||||||
self.tasks.values()
|
self.tasks.values()
|
||||||
.sorted_unstable().rev()
|
.sorted_unstable()
|
||||||
.take(3).map(|t| t.get_id()))
|
.take(3).map(|t| t.get_id()))
|
||||||
.chain(
|
.chain(
|
||||||
// Highest Prio
|
// Highest Prio
|
||||||
|
@ -1774,30 +1774,30 @@ mod tasks_test {
|
||||||
|
|
||||||
macro_rules! assert_tasks_visible {
|
macro_rules! assert_tasks_visible {
|
||||||
($left:expr, $right:expr $(,)?) => {
|
($left:expr, $right:expr $(,)?) => {
|
||||||
assert_eq!(
|
let tasks = $left.visible_tasks();
|
||||||
$left
|
assert_tasks!($left, tasks, $right);
|
||||||
.visible_tasks()
|
|
||||||
.iter()
|
|
||||||
.map(|t| t.event.id)
|
|
||||||
.collect::<HashSet<EventId>>(),
|
|
||||||
HashSet::from($right)
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_tasks_view {
|
macro_rules! assert_tasks_view {
|
||||||
($left:expr, $right:expr $(,)?) => {
|
($left:expr, $right:expr $(,)?) => {
|
||||||
let tasks = $left.viewed_tasks();
|
let tasks = $left.viewed_tasks();
|
||||||
|
assert_tasks!($left, tasks, $right);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! assert_tasks {
|
||||||
|
($left:expr, $tasks:expr, $right:expr $(,)?) => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tasks
|
$tasks
|
||||||
.iter()
|
.iter()
|
||||||
.map(|t| t.event.id)
|
.map(|t| t.event.id)
|
||||||
.collect::<HashSet<EventId>>(),
|
.collect::<HashSet<EventId>>(),
|
||||||
HashSet::from($right),
|
HashSet::from_iter($right.clone()),
|
||||||
"Tasks Visible: {:?}\nExpected: {:?}",
|
"Tasks Visible: {:?}\nExpected: {:?}",
|
||||||
tasks,
|
$tasks.iter().map(|t| t.event.id).map(|id| $left.get_relative_path(id)).collect_vec(),
|
||||||
$right.map(|id| $left.get_relative_path(id))
|
$right.into_iter().map(|id| $left.get_relative_path(id)).collect_vec(),
|
||||||
)
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1914,10 +1914,15 @@ mod tasks_test {
|
||||||
);
|
);
|
||||||
|
|
||||||
tasks.submit(EventBuilder::new(Kind::Bookmarks, ""));
|
tasks.submit(EventBuilder::new(Kind::Bookmarks, ""));
|
||||||
|
assert!(tasks.bookmarks.is_empty());
|
||||||
tasks.clear_filters();
|
tasks.clear_filters();
|
||||||
assert_tasks_visible!(tasks, [pin, test]);
|
assert_tasks_visible!(tasks, [pin, test]);
|
||||||
tasks.set_view_depth(0);
|
tasks.set_view_depth(0);
|
||||||
assert_tasks_visible!(tasks, [test, parent]);
|
tasks.custom_time = Some(now());
|
||||||
|
let mut new = (0..3).map(|t| tasks.make_task(t.to_string().as_str())).collect_vec();
|
||||||
|
// Show the newest tasks in quick access and remove old pin
|
||||||
|
new.extend([test, parent]);
|
||||||
|
assert_tasks_visible!(tasks, new);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -2082,7 +2087,7 @@ mod tasks_test {
|
||||||
assert_tasks_view!(tasks, [t11]);
|
assert_tasks_view!(tasks, [t11]);
|
||||||
tasks.set_view_depth(1);
|
tasks.set_view_depth(1);
|
||||||
assert_tasks_view!(tasks, [t111]);
|
assert_tasks_view!(tasks, [t111]);
|
||||||
tasks.set_search_depth(1); // resets view
|
tasks.set_search_depth(2); // resets view
|
||||||
assert_tasks_view!(tasks, [t111, t12]);
|
assert_tasks_view!(tasks, [t111, t12]);
|
||||||
tasks.set_view_depth(0);
|
tasks.set_view_depth(0);
|
||||||
assert_tasks_view!(tasks, [t11, t12]);
|
assert_tasks_view!(tasks, [t11, t12]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue