Skip to content

Commit 252c404

Browse files
authored
Merge pull request #78 from boydm/boyd
Add missing tests
2 parents 5f2170b + 70f36af commit 252c404

File tree

3 files changed

+162
-37
lines changed

3 files changed

+162
-37
lines changed

lib/scenic/view_port/input.ex

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -192,45 +192,45 @@ defmodule Scenic.ViewPort.Input do
192192

193193
# --------------------------------------------------------
194194
# cursor_enter is only sent to the root graph_key
195-
defp do_handle_captured_input(
196-
{:cursor_enter, global_pos} = input,
197-
context,
198-
%{max_depth: max_depth} = state
199-
) do
200-
{uid, id, point} = find_by_captured_point(global_pos, context, max_depth)
201-
202-
Scene.cast(
203-
context.graph_key,
204-
{
205-
:input,
206-
{:cursor_enter, point},
207-
%{context | uid: uid, id: id, raw_input: input}
208-
}
209-
)
195+
# defp do_handle_captured_input(
196+
# {:cursor_enter, global_pos} = input,
197+
# context,
198+
# %{max_depth: max_depth} = state
199+
# ) do
200+
# {uid, id, point} = find_by_captured_point(global_pos, context, max_depth)
201+
202+
# Scene.cast(
203+
# context.graph_key,
204+
# {
205+
# :input,
206+
# {:cursor_enter, point},
207+
# %{context | uid: uid, id: id, raw_input: input}
208+
# }
209+
# )
210210

211-
{:noreply, state}
212-
end
213-
214-
# --------------------------------------------------------
215-
# cursor_exit is only sent to the root graph_key
216-
defp do_handle_captured_input(
217-
{:cursor_exit, global_pos} = input,
218-
context,
219-
%{max_depth: max_depth} = state
220-
) do
221-
{uid, id, point} = find_by_captured_point(global_pos, context, max_depth)
211+
# {:noreply, state}
212+
# end
222213

223-
Scene.cast(
224-
context.graph_key,
225-
{
226-
:input,
227-
{:cursor_enter, point},
228-
%{context | uid: uid, id: id, raw_input: input}
229-
}
230-
)
214+
# # --------------------------------------------------------
215+
# # cursor_exit is only sent to the root graph_key
216+
# defp do_handle_captured_input(
217+
# {:cursor_exit, global_pos} = input,
218+
# context,
219+
# %{max_depth: max_depth} = state
220+
# ) do
221+
# {uid, id, point} = find_by_captured_point(global_pos, context, max_depth)
222+
223+
# Scene.cast(
224+
# context.graph_key,
225+
# {
226+
# :input,
227+
# {:cursor_enter, point},
228+
# %{context | uid: uid, id: id, raw_input: input}
229+
# }
230+
# )
231231

232-
{:noreply, state}
233-
end
232+
# {:noreply, state}
233+
# end
234234

235235
# --------------------------------------------------------
236236
# cursor_enter is only sent to the root graph_key

test/scenic/component/input/slider_test.exs

Lines changed: 105 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,110 @@ 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+
167+
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, :red}, ^self}})
168+
169+
# above max
170+
{:noreply, _} =
171+
Slider.handle_input({:cursor_button, {:left, :press, nil, {1203, 0}}}, context, %{
172+
state
173+
| tracking: false
174+
})
175+
176+
assert_receive({:"$gen_cast", {:event, {:value_changed, :test_id, :orange}, ^self}})
177+
end
178+
179+
test "handle_input {:cursor_button, :press, far left" do
180+
self = self()
181+
context = %ViewPort.Context{viewport: self}
182+
Process.put(:parent_pid, self)
183+
184+
{:noreply, state} =
185+
Slider.handle_input({:cursor_button, {:left, :press, nil, {-103, 0}}}, context, %{
186+
@state
187+
| tracking: false
188+
})
189+
190+
assert state.tracking
191+
assert state.value == 0
192+
end
193+
194+
test "handle_input {:cursor_button, :press, far right" do
195+
self = self()
196+
context = %ViewPort.Context{viewport: self}
197+
Process.put(:parent_pid, self)
198+
199+
{:noreply, state} =
200+
Slider.handle_input({:cursor_button, {:left, :press, nil, {1003, 0}}}, context, %{
201+
@state
202+
| tracking: false
203+
})
204+
205+
assert state.tracking
206+
assert state.value == 100
207+
end
208+
105209
test "handle_input {:cursor_button, :release" do
106210
self = self()
107211
context = %ViewPort.Context{viewport: self}

test/scenic/view_port/input_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,25 @@ 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+
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
734755
end

0 commit comments

Comments
 (0)