Skip to content

Commit 9a1ccb4

Browse files
committed
test captured cursor_pos
1 parent 7505b0b commit 9a1ccb4

File tree

1 file changed

+109
-4
lines changed

1 file changed

+109
-4
lines changed

test/scenic/view_port/input_test.exs

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,113 @@ defmodule Scenic.ViewPort.InputTest do
621621
assert context.graph_key == graph_key1
622622
end
623623

624-
test "captured cursor_pos over nothing"
625-
test "captured cursor_pos over non-captured graph"
626-
test "captured cursor_pos enter primitive"
627-
test "captured cursor_pos exit primitive"
624+
test "captured cursor_pos over nothing", %{
625+
graph_key: graph_key,
626+
graph_key1: graph_key1,
627+
context: context,
628+
master_graph_key: master_graph_key
629+
} do
630+
# start NOT over a primitive
631+
{:noreply, _} =
632+
Input.handle_cast(
633+
{:input, {:cursor_pos, {1, 1}}},
634+
%{
635+
master_graph_key: master_graph_key,
636+
root_graph_key: graph_key,
637+
input_captures: %{cursor_pos: context},
638+
max_depth: 10,
639+
hover_primitve: nil
640+
}
641+
)
642+
643+
assert_received(
644+
{:"$gen_cast", {:input, {:cursor_pos, {0.0, 0.0}}, context}}
645+
)
646+
assert context.graph_key == graph_key1
647+
assert context.id == nil
648+
assert context.uid == nil
649+
end
650+
651+
test "captured cursor_pos over non-captured graph", %{
652+
graph_key: graph_key,
653+
graph_key1: graph_key1,
654+
context: context,
655+
master_graph_key: master_graph_key
656+
} do
657+
# start NOT over a primitive
658+
{:noreply, _} =
659+
Input.handle_cast(
660+
{:input, {:cursor_pos, {25, 25}}},
661+
%{
662+
master_graph_key: master_graph_key,
663+
root_graph_key: graph_key,
664+
input_captures: %{cursor_pos: context},
665+
max_depth: 10,
666+
hover_primitve: nil
667+
}
668+
)
669+
670+
assert_received(
671+
{:"$gen_cast", {:input, {:cursor_pos, {24.0, 24.0}}, context}}
672+
)
673+
assert context.graph_key == graph_key1
674+
assert context.id == nil
675+
assert context.uid == nil
676+
end
677+
678+
test "captured cursor_pos enter primitive", %{
679+
graph_key: graph_key,
680+
graph_key1: graph_key1,
681+
context: context,
682+
master_graph_key: master_graph_key
683+
} do
684+
# start NOT over a primitive
685+
{:noreply, _} =
686+
Input.handle_cast(
687+
{:input, {:cursor_pos, {50, 50}}},
688+
%{
689+
master_graph_key: master_graph_key,
690+
root_graph_key: graph_key,
691+
input_captures: %{cursor_pos: context},
692+
max_depth: 10,
693+
hover_primitve: nil
694+
}
695+
)
696+
697+
assert_received(
698+
{:"$gen_cast", {:input, {:cursor_pos, {49.0, 49.0}}, context}}
699+
)
700+
refute_received({:"$gen_cast", {:input, {:cursor_exit, _}, _}})
701+
assert_received({:"$gen_cast", {:input, {:cursor_enter, 1}, _}})
702+
703+
assert context.graph_key == graph_key1
704+
assert context.id == :circle
705+
assert context.uid == 1
706+
end
707+
708+
test "captured cursor_pos exit primitive", %{
709+
graph_key: graph_key,
710+
graph_key1: graph_key1,
711+
context: context,
712+
master_graph_key: master_graph_key
713+
} do
714+
# start NOT over a primitive
715+
{:noreply, _} =
716+
Input.handle_cast(
717+
{:input, {:cursor_pos, {2, 2}}},
718+
%{
719+
master_graph_key: master_graph_key,
720+
root_graph_key: graph_key,
721+
input_captures: %{cursor_pos: context},
722+
max_depth: 10,
723+
hover_primitve: {1, graph_key1}
724+
}
725+
)
726+
727+
assert_received(
728+
{:"$gen_cast", {:input, {:cursor_pos, {1.0, 1.0}}, context}}
729+
)
730+
assert_received({:"$gen_cast", {:input, {:cursor_exit, 1}, _}})
731+
refute_received({:"$gen_cast", {:input, {:cursor_enter, _}, _}})
732+
end
628733
end

0 commit comments

Comments
 (0)