137 lines
4.4 KiB
Rust
Raw Normal View History

2023-08-06 15:54:18 +08:00
use std::time::Duration;
use event_integration::EventIntegrationTest;
use flowy_folder::entities::{ChildViewUpdatePB, RepeatedViewPB, UpdateViewPayloadPB};
use flowy_folder::notification::FolderNotification;
2023-08-06 15:54:18 +08:00
use crate::util::receive_with_timeout;
#[tokio::test]
/// The primary purpose of this test is to validate that the notification subscription mechanism
/// correctly notifies the subscriber of updates to workspace views.
/// 1. Initialize the `FlowyCoreTest` with a guest user.
/// 2. Retrieve the current workspace for the test user.
/// 3. Subscribe to workspace view updates using the `RepeatedViewPB` notification.
/// 4. Spawn a new asynchronous task to create a new view named "test_view" within the workspace.
/// 5. Await the notification for workspace view updates with a timeout of 30 seconds.
/// 6. Ensure that the received views contain the newly created "test_view".
async fn create_child_view_in_workspace_subscription_test() {
feat: folder search mvp (#4665) * feat: implement folder indexer * feat: sqlite search views using fts5 * feat: add view indexing to user manager * feat: implement folder indexer * feat: add sqlite search documents * feat: add document indexing to user manager * feat: add document indexing to folder indexer * chore: update collab rev * feat: search frontend integration * refactor: search index * test: add event test * chore: fix ci * feat: initial command palette overlay impl (#4619) * chore: test search engine * chore: initial structure * chore: replace old search request * chore: enable log for lib-dispatch * chore: move search manager to core * feat: move traits and responsibility to search crate * feat: move search to search crate * feat: replace sqlite with tantivy * feat: deserialize tantivy documents * chore: fixes after rebase * chore: clean code * feat: fetch and sort results * fix: code review + cleaning * feat: support custom icons * feat: support view layout icons * feat: rename bloc and fix indexing * fix: prettify dialog * feat: score results * chore: update collab rev * feat: add recent view history to command palette * test: add integration_tests * fix: clippy changes * fix: focus traversal in cmd palette * fix: remove file after merging main * chore: code review and panic-safe * feat: index all views if index does not exist * chore: improve logic with conditional * chore: add is_empty check * chore: abstract logic from folder manager init * chore: update collab rev * chore: code review * chore: fixes after merge + update lock file * chore: revert cargo lock * fix: set icon type when removing icon * fix: code review + dependency inversion * fix: remove icon fix for not persisting icon type * test: simple tests manipulating views * test: create 100 views * fix: tauri build * chore: create 1000 views * chore: create util methods * chore: test * chore: test * chore: remove logs * chore: fix build.rs * chore: export models * chore: enable clear cache on Rust-CI * fix: navigate to newly created views * fix: force disable setting workspace listener on rebuilds * fix: remove late final * fix: missing returns * fix: localization and minor fixes * test: add index assert to large test * fix: missing section param after merging main * chore: try fix unzip file error * chore: lower the test * feat: show hint when result is in trash --------- Co-authored-by: nathan <nathan@appflowy.io> Co-authored-by: Jiraffe7 <twajxjiraffe@gmail.com> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2024-03-21 17:34:53 +01:00
let test = EventIntegrationTest::new_anon().await;
let workspace = test.get_current_workspace().await;
let rx = test
2023-08-06 15:54:18 +08:00
.notification_sender
.subscribe::<RepeatedViewPB>(&workspace.id, FolderNotification::DidUpdateWorkspaceViews);
let cloned_test = test.clone();
let cloned_workspace_id = workspace.id.clone();
test.appflowy_core.dispatcher().spawn(async move {
2023-08-06 15:54:18 +08:00
cloned_test
.create_view(&cloned_workspace_id, "workspace child view".to_string())
.await;
});
let views = receive_with_timeout(rx, Duration::from_secs(30))
2023-08-06 15:54:18 +08:00
.await
.unwrap()
.items;
assert_eq!(views.len(), 2);
assert_eq!(views[1].name, "workspace child view".to_string());
}
#[tokio::test]
async fn create_child_view_in_view_subscription_test() {
feat: folder search mvp (#4665) * feat: implement folder indexer * feat: sqlite search views using fts5 * feat: add view indexing to user manager * feat: implement folder indexer * feat: add sqlite search documents * feat: add document indexing to user manager * feat: add document indexing to folder indexer * chore: update collab rev * feat: search frontend integration * refactor: search index * test: add event test * chore: fix ci * feat: initial command palette overlay impl (#4619) * chore: test search engine * chore: initial structure * chore: replace old search request * chore: enable log for lib-dispatch * chore: move search manager to core * feat: move traits and responsibility to search crate * feat: move search to search crate * feat: replace sqlite with tantivy * feat: deserialize tantivy documents * chore: fixes after rebase * chore: clean code * feat: fetch and sort results * fix: code review + cleaning * feat: support custom icons * feat: support view layout icons * feat: rename bloc and fix indexing * fix: prettify dialog * feat: score results * chore: update collab rev * feat: add recent view history to command palette * test: add integration_tests * fix: clippy changes * fix: focus traversal in cmd palette * fix: remove file after merging main * chore: code review and panic-safe * feat: index all views if index does not exist * chore: improve logic with conditional * chore: add is_empty check * chore: abstract logic from folder manager init * chore: update collab rev * chore: code review * chore: fixes after merge + update lock file * chore: revert cargo lock * fix: set icon type when removing icon * fix: code review + dependency inversion * fix: remove icon fix for not persisting icon type * test: simple tests manipulating views * test: create 100 views * fix: tauri build * chore: create 1000 views * chore: create util methods * chore: test * chore: test * chore: remove logs * chore: fix build.rs * chore: export models * chore: enable clear cache on Rust-CI * fix: navigate to newly created views * fix: force disable setting workspace listener on rebuilds * fix: remove late final * fix: missing returns * fix: localization and minor fixes * test: add index assert to large test * fix: missing section param after merging main * chore: try fix unzip file error * chore: lower the test * feat: show hint when result is in trash --------- Co-authored-by: nathan <nathan@appflowy.io> Co-authored-by: Jiraffe7 <twajxjiraffe@gmail.com> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2024-03-21 17:34:53 +01:00
let test = EventIntegrationTest::new_anon().await;
let mut workspace = test.get_current_workspace().await;
2023-08-06 15:54:18 +08:00
let workspace_child_view = workspace.views.pop().unwrap();
let rx = test.notification_sender.subscribe::<ChildViewUpdatePB>(
2023-08-06 15:54:18 +08:00
&workspace_child_view.id,
FolderNotification::DidUpdateChildViews,
);
let cloned_test = test.clone();
let child_view_id = workspace_child_view.id.clone();
test.appflowy_core.dispatcher().spawn(async move {
2023-08-06 15:54:18 +08:00
cloned_test
.create_view(
&child_view_id,
"workspace child view's child view".to_string(),
)
.await;
});
let update = receive_with_timeout(rx, Duration::from_secs(30))
2023-08-06 15:54:18 +08:00
.await
.unwrap();
assert_eq!(update.create_child_views.len(), 1);
assert_eq!(
update.create_child_views[0].name,
"workspace child view's child view".to_string()
);
}
#[tokio::test]
async fn delete_view_subscription_test() {
feat: folder search mvp (#4665) * feat: implement folder indexer * feat: sqlite search views using fts5 * feat: add view indexing to user manager * feat: implement folder indexer * feat: add sqlite search documents * feat: add document indexing to user manager * feat: add document indexing to folder indexer * chore: update collab rev * feat: search frontend integration * refactor: search index * test: add event test * chore: fix ci * feat: initial command palette overlay impl (#4619) * chore: test search engine * chore: initial structure * chore: replace old search request * chore: enable log for lib-dispatch * chore: move search manager to core * feat: move traits and responsibility to search crate * feat: move search to search crate * feat: replace sqlite with tantivy * feat: deserialize tantivy documents * chore: fixes after rebase * chore: clean code * feat: fetch and sort results * fix: code review + cleaning * feat: support custom icons * feat: support view layout icons * feat: rename bloc and fix indexing * fix: prettify dialog * feat: score results * chore: update collab rev * feat: add recent view history to command palette * test: add integration_tests * fix: clippy changes * fix: focus traversal in cmd palette * fix: remove file after merging main * chore: code review and panic-safe * feat: index all views if index does not exist * chore: improve logic with conditional * chore: add is_empty check * chore: abstract logic from folder manager init * chore: update collab rev * chore: code review * chore: fixes after merge + update lock file * chore: revert cargo lock * fix: set icon type when removing icon * fix: code review + dependency inversion * fix: remove icon fix for not persisting icon type * test: simple tests manipulating views * test: create 100 views * fix: tauri build * chore: create 1000 views * chore: create util methods * chore: test * chore: test * chore: remove logs * chore: fix build.rs * chore: export models * chore: enable clear cache on Rust-CI * fix: navigate to newly created views * fix: force disable setting workspace listener on rebuilds * fix: remove late final * fix: missing returns * fix: localization and minor fixes * test: add index assert to large test * fix: missing section param after merging main * chore: try fix unzip file error * chore: lower the test * feat: show hint when result is in trash --------- Co-authored-by: nathan <nathan@appflowy.io> Co-authored-by: Jiraffe7 <twajxjiraffe@gmail.com> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2024-03-21 17:34:53 +01:00
let test = EventIntegrationTest::new_anon().await;
let workspace = test.get_current_workspace().await;
let rx = test
2023-08-06 15:54:18 +08:00
.notification_sender
.subscribe::<ChildViewUpdatePB>(&workspace.id, FolderNotification::DidUpdateChildViews);
let cloned_test = test.clone();
let delete_view_id = workspace.views.first().unwrap().id.clone();
let cloned_delete_view_id = delete_view_id.clone();
test
.appflowy_core
.dispatcher()
.spawn(async move {
cloned_test.delete_view(&cloned_delete_view_id).await;
})
.await
.unwrap();
2023-08-06 15:54:18 +08:00
let update = test
.appflowy_core
.dispatcher()
.run_until(receive_with_timeout(rx, Duration::from_secs(30)))
2023-08-06 15:54:18 +08:00
.await
.unwrap();
2023-08-06 15:54:18 +08:00
assert_eq!(update.delete_child_views.len(), 1);
assert_eq!(update.delete_child_views[0], delete_view_id);
}
#[tokio::test]
async fn update_view_subscription_test() {
feat: folder search mvp (#4665) * feat: implement folder indexer * feat: sqlite search views using fts5 * feat: add view indexing to user manager * feat: implement folder indexer * feat: add sqlite search documents * feat: add document indexing to user manager * feat: add document indexing to folder indexer * chore: update collab rev * feat: search frontend integration * refactor: search index * test: add event test * chore: fix ci * feat: initial command palette overlay impl (#4619) * chore: test search engine * chore: initial structure * chore: replace old search request * chore: enable log for lib-dispatch * chore: move search manager to core * feat: move traits and responsibility to search crate * feat: move search to search crate * feat: replace sqlite with tantivy * feat: deserialize tantivy documents * chore: fixes after rebase * chore: clean code * feat: fetch and sort results * fix: code review + cleaning * feat: support custom icons * feat: support view layout icons * feat: rename bloc and fix indexing * fix: prettify dialog * feat: score results * chore: update collab rev * feat: add recent view history to command palette * test: add integration_tests * fix: clippy changes * fix: focus traversal in cmd palette * fix: remove file after merging main * chore: code review and panic-safe * feat: index all views if index does not exist * chore: improve logic with conditional * chore: add is_empty check * chore: abstract logic from folder manager init * chore: update collab rev * chore: code review * chore: fixes after merge + update lock file * chore: revert cargo lock * fix: set icon type when removing icon * fix: code review + dependency inversion * fix: remove icon fix for not persisting icon type * test: simple tests manipulating views * test: create 100 views * fix: tauri build * chore: create 1000 views * chore: create util methods * chore: test * chore: test * chore: remove logs * chore: fix build.rs * chore: export models * chore: enable clear cache on Rust-CI * fix: navigate to newly created views * fix: force disable setting workspace listener on rebuilds * fix: remove late final * fix: missing returns * fix: localization and minor fixes * test: add index assert to large test * fix: missing section param after merging main * chore: try fix unzip file error * chore: lower the test * feat: show hint when result is in trash --------- Co-authored-by: nathan <nathan@appflowy.io> Co-authored-by: Jiraffe7 <twajxjiraffe@gmail.com> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
2024-03-21 17:34:53 +01:00
let test = EventIntegrationTest::new_anon().await;
let mut workspace = test.get_current_workspace().await;
let rx = test
2023-08-06 15:54:18 +08:00
.notification_sender
.subscribe::<ChildViewUpdatePB>(&workspace.id, FolderNotification::DidUpdateChildViews);
let cloned_test = test.clone();
let view = workspace.views.pop().unwrap();
assert!(!view.is_favorite);
2023-08-06 15:54:18 +08:00
let update_view_id = view.id.clone();
test.appflowy_core.dispatcher().spawn(async move {
2023-08-06 15:54:18 +08:00
cloned_test
.update_view(UpdateViewPayloadPB {
view_id: update_view_id,
name: Some("hello world".to_string()),
is_favorite: Some(true),
..Default::default()
})
.await;
});
let update = receive_with_timeout(rx, Duration::from_secs(30))
2023-08-06 15:54:18 +08:00
.await
.unwrap();
assert_eq!(update.update_child_views.len(), 1);
let expected_view = update.update_child_views.first().unwrap();
assert_eq!(expected_view.id, view.id);
assert_eq!(expected_view.name, "hello world".to_string());
assert!(expected_view.is_favorite);
2023-08-06 15:54:18 +08:00
}