mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
feat: tests: add TestCheckpointEvent and Context.trigger_checkpoint_event
This commit is contained in:
@@ -152,6 +152,13 @@ impl CommandApi {
|
||||
tokio::time::sleep(std::time::Duration::from_secs_f64(delay)).await
|
||||
}
|
||||
|
||||
/// Emit the test checkpoint event, used for tests.
|
||||
/// Returns a unique id of the emitted `TestCheckpointEvent`.
|
||||
async fn trigger_checkpoint_event(&self, account_id: u32) -> Result<usize> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
Ok(ctx.emit_test_checkpoint_event().await)
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Misc top level functions
|
||||
// ---------------------------------------------
|
||||
|
||||
@@ -259,6 +259,13 @@ pub enum EventType {
|
||||
/// If `chat_id` is set to None, then all currently visible chats need to be rerendered, and all not-visible items need to be cleared from cache if the UI has a cache.
|
||||
#[serde(rename_all = "camelCase")]
|
||||
ChatlistItemChanged { chat_id: Option<u32> },
|
||||
|
||||
/// Tests can trigger this event and then wait for it, to make sure all events before it were consumed.
|
||||
/// Useful for tests that test whether a specific event is emitted,
|
||||
TestCheckpointEvent {
|
||||
/// unique id to recognize the event
|
||||
id: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<CoreEventType> for EventType {
|
||||
@@ -370,6 +377,7 @@ impl From<CoreEventType> for EventType {
|
||||
chat_id: chat_id.map(|id| id.to_u32()),
|
||||
},
|
||||
CoreEventType::ChatlistChanged => ChatlistChanged,
|
||||
CoreEventType::TestCheckpointEvent { id } => TestCheckpointEvent { id },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user