Initial public release of Warp.
Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use warpui::{
|
||||
async_assert, integration::TestStep, windowing::WindowManager, SingletonEntity, WindowId,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ai::facts::{view::AIFactPage, AIMemory},
|
||||
cloud_object::{model::persistence::CloudModel, Space},
|
||||
integration_testing::view_getters::workspace_view,
|
||||
server::{
|
||||
cloud_objects::update_manager::UpdateManager,
|
||||
ids::{ClientId, SyncId},
|
||||
},
|
||||
workspaces::user_workspaces::UserWorkspaces,
|
||||
};
|
||||
|
||||
/// Create a personal rule and save its sync ID into the step data.
|
||||
pub fn create_a_personal_rule(
|
||||
key: impl Into<String>,
|
||||
name: impl Into<String>,
|
||||
content: impl Into<String>,
|
||||
) -> TestStep {
|
||||
let key = key.into();
|
||||
let name = Arc::new(Some(name.into()));
|
||||
let content = Arc::new(content.into());
|
||||
TestStep::new("Create a personal rule")
|
||||
.with_action(move |app, _, data| {
|
||||
let client_id = ClientId::new();
|
||||
let sync_id = SyncId::ClientId(client_id);
|
||||
UpdateManager::handle(app).update(app, |update_manager, ctx| {
|
||||
let ai_fact = crate::ai::facts::AIFact::Memory(AIMemory {
|
||||
is_autogenerated: false,
|
||||
name: name.as_ref().clone(),
|
||||
content: content.as_ref().clone(),
|
||||
suggested_logging_id: None,
|
||||
});
|
||||
update_manager.create_ai_fact(
|
||||
ai_fact,
|
||||
client_id,
|
||||
UserWorkspaces::as_ref(ctx)
|
||||
.personal_drive(ctx)
|
||||
.expect("User UID must be set in tests"),
|
||||
ctx,
|
||||
);
|
||||
});
|
||||
|
||||
data.insert(key.clone(), sync_id);
|
||||
})
|
||||
.add_assertion(move |app, _| {
|
||||
CloudModel::handle(app).read(app, |cloud_model, ctx| {
|
||||
async_assert!(
|
||||
cloud_model
|
||||
.active_cloud_objects_in_space(Space::Personal, ctx)
|
||||
.count()
|
||||
> 0,
|
||||
"Rule exists"
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Open the rule pane saved at `key` in the active tab of the window saved at `window_key`
|
||||
pub fn open_rule_pane(window_key: impl Into<String>, key: impl Into<String>) -> TestStep {
|
||||
let window_key = window_key.into();
|
||||
let key = key.into();
|
||||
|
||||
TestStep::new("Open rule pane").with_action(move |app, _, data| {
|
||||
let window_id: &WindowId = data.get(&window_key).expect("No saved window ID");
|
||||
let fact_id: &SyncId = data.get(&key).expect("No saved rule ID");
|
||||
workspace_view(app, *window_id).update(app, |workspace, ctx| {
|
||||
// Focus the window first
|
||||
WindowManager::as_ref(ctx).show_window_and_focus_app(*window_id);
|
||||
|
||||
// Open the AI facts pane
|
||||
let page = AIFactPage::RuleEditor {
|
||||
sync_id: Some(*fact_id),
|
||||
};
|
||||
workspace.open_ai_fact_collection_pane(None, Some(page), ctx);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Update a rule's content
|
||||
pub fn update_rule_content(
|
||||
fact_key: impl Into<String>,
|
||||
new_content: impl Into<String>,
|
||||
) -> TestStep {
|
||||
let fact_key = fact_key.into();
|
||||
let new_content = Arc::new(new_content.into());
|
||||
TestStep::new("Update rule content").with_action(move |app, _, data| {
|
||||
let sync_id: &SyncId = data.get(&fact_key).expect("No saved rule ID");
|
||||
UpdateManager::handle(app).update(app, |update_manager, ctx| {
|
||||
let ai_fact = crate::ai::facts::AIFact::Memory(AIMemory {
|
||||
is_autogenerated: false,
|
||||
name: None,
|
||||
content: new_content.as_ref().clone(),
|
||||
suggested_logging_id: None,
|
||||
});
|
||||
update_manager.update_ai_fact(ai_fact, *sync_id, None, ctx);
|
||||
});
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user