@@ -54,72 +54,91 @@ defmodule Scenic.Component.ButtonTest do
54
54
55
55
test "init works with various alignments" do
56
56
{ :ok , state } = Button . init ( "Button" , [ ] )
57
- % Primitive { styles: % { text_align: :center } } = Graph . get! ( state . graph , :title )
57
+ % Primitive { styles: % { text_align: :center } } = Graph . get! ( state . graph , :title )
58
58
59
59
{ :ok , state } = Button . init ( "Button" , styles: % { alignment: :left } , id: :button_id )
60
- % Primitive { styles: % { text_align: :left } } = Graph . get! ( state . graph , :title )
60
+ % Primitive { styles: % { text_align: :left } } = Graph . get! ( state . graph , :title )
61
61
62
62
{ :ok , state } = Button . init ( "Button" , styles: % { alignment: :center } , id: :button_id )
63
- % Primitive { styles: % { text_align: :center } } = Graph . get! ( state . graph , :title )
63
+ % Primitive { styles: % { text_align: :center } } = Graph . get! ( state . graph , :title )
64
64
65
65
{ :ok , state } = Button . init ( "Button" , styles: % { alignment: :right } , id: :button_id )
66
- % Primitive { styles: % { text_align: :right } } = Graph . get! ( state . graph , :title )
66
+ % Primitive { styles: % { text_align: :right } } = Graph . get! ( state . graph , :title )
67
67
end
68
68
69
69
# ============================================================================
70
70
# handle_input
71
71
72
72
test "handle_input {:cursor_enter, _uid} sets contained" do
73
- { :noreply , state } = Button . handle_input ( { :cursor_enter , 1 } , % { } , % { @ state | pressed: true } )
73
+ { :noreply , state } = Button . handle_input ( { :cursor_enter , 1 } , % { } , % { @ state | pressed: true } )
74
74
assert state . contained
75
75
# confirm the graph was pushed
76
- assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
76
+ assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
77
77
end
78
78
79
79
test "handle_input {:cursor_exit, _uid} clears contained" do
80
- { :noreply , state } = Button . handle_input ( { :cursor_exit , 1 } , % { } , % { @ state | pressed: true } )
80
+ { :noreply , state } = Button . handle_input ( { :cursor_exit , 1 } , % { } , % { @ state | pressed: true } )
81
81
refute state . contained
82
82
# confirm the graph was pushed
83
- assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
83
+ assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
84
84
end
85
85
86
86
test "handle_input {:cursor_button, :press" do
87
87
context = % ViewPort.Context { viewport: self ( ) }
88
- { :noreply , state } = Button . handle_input ( { :cursor_button , { :left , :press , nil , nil } } , context , % { @ state | pressed: false , contained: true } )
88
+
89
+ { :noreply , state } =
90
+ Button . handle_input ( { :cursor_button , { :left , :press , nil , nil } } , context , % {
91
+ @ state
92
+ | pressed: false ,
93
+ contained: true
94
+ } )
95
+
89
96
assert state . pressed
90
97
91
98
# confirm the input was captured
92
- assert_receive ( { :"$gen_cast" , { :capture_input , ^ context , [ :cursor_button , :cursor_pos ] } } )
99
+ assert_receive ( { :"$gen_cast" , { :capture_input , ^ context , [ :cursor_button , :cursor_pos ] } } )
93
100
# confirm the graph was pushed
94
- assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
101
+ assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
95
102
end
96
103
97
104
test "handle_input {:cursor_button, :release" do
98
105
context = % ViewPort.Context { viewport: self ( ) }
99
- { :noreply , state } = Button . handle_input ( { :cursor_button , { :left , :release , nil , nil } } , context , % { @ state | pressed: true , contained: true } )
106
+
107
+ { :noreply , state } =
108
+ Button . handle_input ( { :cursor_button , { :left , :release , nil , nil } } , context , % {
109
+ @ state
110
+ | pressed: true ,
111
+ contained: true
112
+ } )
113
+
100
114
refute state . pressed
101
115
102
116
# confirm the input was released
103
- assert_receive ( { :"$gen_cast" , { :release_input , [ :cursor_button , :cursor_pos ] } } )
117
+ assert_receive ( { :"$gen_cast" , { :release_input , [ :cursor_button , :cursor_pos ] } } )
104
118
105
119
# confirm the graph was pushed
106
- assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
120
+ assert_receive ( { :"$gen_cast" , { :push_graph , _ , _ , _ } } )
107
121
end
108
122
109
-
110
123
test "handle_input {:cursor_button, :release sends a message if contained" do
111
124
self = self ( )
112
125
Process . put ( :parent_pid , self )
113
126
context = % ViewPort.Context { viewport: self ( ) }
114
- { :noreply , _ } = Button . handle_input ( { :cursor_button , { :left , :release , nil , nil } } , context , % { @ state | pressed: true , contained: true } )
127
+
128
+ { :noreply , _ } =
129
+ Button . handle_input ( { :cursor_button , { :left , :release , nil , nil } } , context , % {
130
+ @ state
131
+ | pressed: true ,
132
+ contained: true
133
+ } )
115
134
116
135
# confirm the graph was pushed
117
- assert_receive ( { :"$gen_cast" , { :event , { :click , :test_id } , ^ self } } )
136
+ assert_receive ( { :"$gen_cast" , { :event , { :click , :test_id } , ^ self } } )
118
137
end
119
138
120
139
test "handle_input does nothing on unknown input" do
121
140
context = % ViewPort.Context { viewport: self ( ) }
122
- { :noreply , state } = Button . handle_input ( :unknown , context , @ state )
141
+ { :noreply , state } = Button . handle_input ( :unknown , context , @ state )
123
142
assert state == @ state
124
143
end
125
- end
144
+ end
0 commit comments