Skip to content

Commit 1a3b50a

Browse files
committed
fill in missing tests
1 parent e507404 commit 1a3b50a

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

test/scenic/component/input/slider_test.exs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ defmodule Scenic.Component.Input.SliderTest do
7979
# ============================================================================
8080
# handle_input
8181

82-
test "handle_input {:cursor_button, :press" do
82+
test "handle_input {:cursor_button, :press - integer" do
8383
self = self()
8484
context = %ViewPort.Context{viewport: self}
8585
Process.put(:parent_pid, self)
@@ -102,6 +102,78 @@ defmodule Scenic.Component.Input.SliderTest do
102102
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, 34}, ^self}})
103103
end
104104

105+
test "handle_input {:cursor_button, :press - float" do
106+
self = self()
107+
context = %ViewPort.Context{viewport: self}
108+
Process.put(:parent_pid, self)
109+
110+
orig_value = 2.0
111+
extents = {0.0,100.0}
112+
state = %{ @state | value: orig_value, extents: extents }
113+
114+
{:noreply, state} =
115+
Slider.handle_input({:cursor_button, {:left, :press, nil, {103, 0}}}, context, %{
116+
state
117+
| tracking: false
118+
})
119+
120+
assert state.tracking
121+
assert state.value != orig_value
122+
123+
# confirm the input was captured
124+
assert_receive({:"$gen_cast", {:capture_input, ^context, [:cursor_button, :cursor_pos]}})
125+
# confirm the graph was pushed
126+
assert_receive({:"$gen_cast", {:push_graph, _, _, _}})
127+
128+
# confirm the value change was sent
129+
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, pos}, ^self}})
130+
assert pos > 34
131+
assert pos < 35
132+
end
133+
134+
test "handle_input {:cursor_button, :press - list" do
135+
self = self()
136+
context = %ViewPort.Context{viewport: self}
137+
Process.put(:parent_pid, self)
138+
139+
orig_value = :yellow
140+
extents = [:red, :yellow, :purple, :blue, :orange]
141+
state = %{ @state | value: orig_value, extents: extents }
142+
143+
{:noreply, state} =
144+
Slider.handle_input({:cursor_button, {:left, :press, nil, {203, 0}}}, context, %{
145+
state
146+
| tracking: false
147+
})
148+
149+
assert state.tracking
150+
assert state.value != orig_value
151+
152+
# confirm the input was captured
153+
assert_receive({:"$gen_cast", {:capture_input, ^context, [:cursor_button, :cursor_pos]}})
154+
# confirm the graph was pushed
155+
assert_receive({:"$gen_cast", {:push_graph, _, _, _}})
156+
157+
# confirm the value change was sent
158+
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, :blue}, ^self}})
159+
160+
# below min
161+
{:noreply, _} =
162+
Slider.handle_input({:cursor_button, {:left, :press, nil, {-203, 0}}}, context, %{
163+
state
164+
| tracking: false
165+
})
166+
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, :red}, ^self}})
167+
168+
# above max
169+
{:noreply, _} =
170+
Slider.handle_input({:cursor_button, {:left, :press, nil, {1203, 0}}}, context, %{
171+
state
172+
| tracking: false
173+
})
174+
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, :orange}, ^self}})
175+
end
176+
105177
test "handle_input {:cursor_button, :press, far left" do
106178
self = self()
107179
context = %ViewPort.Context{viewport: self}

test/scenic/view_port/input_test.exs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,26 @@ defmodule Scenic.ViewPort.InputTest do
731731
assert_received({:"$gen_cast", {:input, {:cursor_exit, 1}, _}})
732732
refute_received({:"$gen_cast", {:input, {:cursor_enter, _}, _}})
733733
end
734-
end
734+
735+
#============================================================================
736+
# continue input
737+
738+
test "continue_input codepoint", %{graph_key: graph_key, master_graph_key: master_graph_key} do
739+
{:noreply, _} =
740+
Input.handle_cast(
741+
{:continue_input, {:codepoint, :codepoint_input}},
742+
%{
743+
master_graph_key: master_graph_key,
744+
root_graph_key: graph_key,
745+
input_captures: %{}
746+
}
747+
)
748+
749+
assert_received({:"$gen_cast", {:input, {:codepoint, :codepoint_input}, context}})
750+
assert context.graph_key == graph_key
751+
assert context.id == nil
752+
assert context.uid == nil
753+
assert context.viewport == self()
754+
end
755+
756+
end

0 commit comments

Comments
 (0)