forked from seanpdoyle/stimulus_aria_widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combobox_controller_test.rb
71 lines (49 loc) · 2.18 KB
/
combobox_controller_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require "application_system_test_case"
class ComboboxControllerTest < ApplicationSystemTestCase
test "can toggle when input is entered into the Combobox" do
visit examples_path
assert_combo_box "Names", expanded: false
assert_no_list_box_option
fill_in "Names", with: "A"
assert_combo_box "Names", expanded: true, options: %w[ Alan Alex Alice ]
send_keys :escape
assert_combo_box "Names", expanded: false
assert_no_list_box_option
end
test "can toggle when input is cleared from the Combobox" do
visit examples_path
fill_in "Names", with: "A"
assert_combo_box "Names", expanded: true, options: %w[ Alan Alex Alice ]
send_keys :backspace
assert_combo_box "Names", expanded: false
assert_no_list_box_option
end
test "can expand the Combobox in response to an event other than InputEvent" do
visit examples_path
assert_combo_box "Names", expanded: false
click_on "Expand combobox"
assert_combo_box "Names", expanded: true
end
test "wraps keyboard navigation from last to first and first to last" do
visit examples_path
fill_in "Names", with: "A"
find(:field, "Names").click.then { assert_list_box_option "Alan", selected: true }
send_keys(:arrow_down).then { assert_list_box_option "Alex", selected: true }
send_keys(:arrow_down).then { assert_list_box_option "Alice", selected: true }
send_keys(:arrow_down).then { assert_list_box_option "Alan", selected: true }
send_keys(:arrow_up).then { assert_list_box_option "Alice", selected: true }
send_keys(:arrow_up).then { assert_list_box_option "Alex", selected: true }
send_keys(:home).then { assert_list_box_option "Alan", selected: true }
send_keys(:end).then { assert_list_box_option "Alice", selected: true }
end
private
def assert_combo_box(locator = nil, **options)
assert_selector :combo_box, locator, **options
end
def assert_list_box_option(locator = nil, **options)
assert_selector :list_box_option, locator, **options
end
def assert_no_list_box_option(locator = nil, **options)
assert_no_selector :list_box_option, locator, **options
end
end