Skip to main content

jellyflow_runtime/runtime/conformance/scenario/action/
graph.rs

1use crate::runtime::events::NodeGraphGestureEvent;
2use jellyflow_core::core::{CanvasPoint, EdgeId, GroupId, NodeId};
3use jellyflow_core::ops::GraphTransaction;
4
5use super::ConformanceAction;
6
7pub(super) fn kind(action: &ConformanceAction) -> Option<&'static str> {
8    Some(match action {
9        ConformanceAction::DispatchTransaction { .. } => "dispatch_transaction",
10        ConformanceAction::AssertNodePosition { .. } => "assert_node_position",
11        ConformanceAction::SetViewport { .. } => "set_viewport",
12        ConformanceAction::SetSelection { .. } => "set_selection",
13        ConformanceAction::EmitGesture { .. } => "emit_gesture",
14        _ => return None,
15    })
16}
17
18impl ConformanceAction {
19    /// Builds the low-level transaction fixture action.
20    ///
21    /// Prefer the interaction-specific constructors when checking adapter behavior.
22    pub fn dispatch_transaction(transaction: GraphTransaction) -> Self {
23        Self::DispatchTransaction { transaction }
24    }
25
26    pub fn assert_node_position(node: NodeId, expected: CanvasPoint) -> Self {
27        Self::AssertNodePosition { node, expected }
28    }
29
30    pub fn set_viewport(pan: CanvasPoint, zoom: f32) -> Self {
31        Self::SetViewport { pan, zoom }
32    }
33
34    pub fn set_selection(
35        nodes: impl IntoIterator<Item = NodeId>,
36        edges: impl IntoIterator<Item = EdgeId>,
37        groups: impl IntoIterator<Item = GroupId>,
38    ) -> Self {
39        Self::SetSelection {
40            nodes: nodes.into_iter().collect(),
41            edges: edges.into_iter().collect(),
42            groups: groups.into_iter().collect(),
43        }
44    }
45
46    pub fn emit_gesture(event: NodeGraphGestureEvent) -> Self {
47        Self::EmitGesture { event }
48    }
49}