-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make organisations field searchable #3172
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,26 +26,16 @@ def assert_select_permission_to_grant_with_javascript | |
|
||
click_link "Update permissions for #{@application.name}" | ||
|
||
@autocomplete_input = find(".autocomplete__input") | ||
@autocomplete_input_element = find(".autocomplete__input") | ||
@select_element = find("#new_permission_id-select", visible: false) | ||
assert_equal "", @autocomplete_input.value | ||
assert_equal "", @select_element.value | ||
|
||
# when I type a few characters from a permission called "adding" | ||
@autocomplete_input.fill_in with: "add" | ||
autocomplete_option = find(".autocomplete__option") | ||
|
||
# the autcomplete value reflects what I typed, a matching option appears, but the select element remains empty | ||
assert_equal "add", @autocomplete_input.value | ||
assert_equal @new_permission_to_grant.name, autocomplete_option.text | ||
assert_equal "", @select_element.value | ||
|
||
# when I click on the matching option | ||
autocomplete_option.click | ||
|
||
# the autocomplete and select elements reflect my selection | ||
assert_equal @new_permission_to_grant.name, @autocomplete_input.value | ||
assert_equal @new_permission_to_grant.id.to_s, @select_element.value | ||
assert_select_with_autocomplete( | ||
autocomplete_input_element: @autocomplete_input_element, | ||
select_element: @select_element, | ||
option_text: @new_permission_to_grant.name, | ||
option_value: @new_permission_to_grant.id.to_s, | ||
unique_partial_string: "add", | ||
) | ||
end | ||
|
||
def assert_permissions_unchanged | ||
|
@@ -162,14 +152,13 @@ def assert_permissions_unchanged | |
should "reset the value of the select element when it no longer matches what's shown in the autocomplete input" do | ||
assert_select_permission_to_grant_with_javascript | ||
|
||
@autocomplete_input.fill_in with: "addin" | ||
autocomplete_option = find(".autocomplete__option") | ||
|
||
assert_equal "addin", @autocomplete_input.value | ||
assert_equal @new_permission_to_grant.name, autocomplete_option.text | ||
assert_equal "", @select_element.value | ||
assert_resets_select_when_desynced_with_autocomplete( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are going to go down a more abstracted approach with our tests, could we make method names for our helpers even more human readable? I know we're following the lead taken by Minitest here, but I'm not the biggest fan of the brevity of Minitest's DSL. Also, forgive my ignorance but I'm not sure what desynced means! |
||
autocomplete_input_element: @autocomplete_input_element, | ||
select_element: @select_element, | ||
option_text: @new_permission_to_grant.name, | ||
unique_partial_string: "addin", | ||
) | ||
|
||
@autocomplete_input.native.send_keys :escape | ||
click_button "Add and finish" | ||
|
||
assert_permissions_unchanged | ||
|
@@ -179,10 +168,10 @@ def assert_permissions_unchanged | |
should "clear the value of the select and autocomplete elements when clicking the clear button" do | ||
assert_select_permission_to_grant_with_javascript | ||
|
||
click_button "Clear selection" | ||
|
||
assert_equal "", @autocomplete_input.value | ||
assert_equal "", @select_element.value | ||
assert_clear_autocomplete_selection_by_click( | ||
autocomplete_input_element: @autocomplete_input_element, | ||
select_element: @select_element, | ||
) | ||
|
||
click_button "Add and finish" | ||
|
||
|
@@ -193,11 +182,10 @@ def assert_permissions_unchanged | |
should "clear the value of the select and autocomplete elements when hitting space on the clear button" do | ||
assert_select_permission_to_grant_with_javascript | ||
|
||
clear_button = find(".js-autocomplete__clear-button") | ||
clear_button.native.send_keys :space | ||
|
||
assert_equal "", @autocomplete_input.value | ||
assert_equal "", @select_element.value | ||
assert_clear_autocomplete_selection_by_space( | ||
autocomplete_input_element: @autocomplete_input_element, | ||
select_element: @select_element, | ||
) | ||
|
||
click_button "Add and finish" | ||
|
||
|
@@ -208,11 +196,10 @@ def assert_permissions_unchanged | |
should "clear the value of the select and autocomplete elements when hitting enter on the clear button" do | ||
assert_select_permission_to_grant_with_javascript | ||
|
||
clear_button = find(".js-autocomplete__clear-button") | ||
clear_button.native.send_keys :enter | ||
|
||
assert_equal "", @autocomplete_input.value | ||
assert_equal "", @select_element.value | ||
assert_clear_autocomplete_selection_by_enter( | ||
autocomplete_input_element: @autocomplete_input_element, | ||
select_element: @select_element, | ||
) | ||
|
||
click_button "Add and finish" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module AutocompleteHelpers | ||
def assert_select_with_autocomplete( | ||
autocomplete_input_element:, | ||
select_element:, | ||
option_text:, | ||
option_value:, | ||
unique_partial_string: | ||
) | ||
assert_equal "", autocomplete_input_element.value | ||
assert_equal "", select_element.value | ||
|
||
# when I type a few characters from the option that are unique to that option | ||
autocomplete_input_element.fill_in with: unique_partial_string | ||
autocomplete_option = find(".autocomplete__option") | ||
|
||
# the autcomplete value reflects what I typed, a matching option appears, but the select element remains empty | ||
assert_equal unique_partial_string, autocomplete_input_element.value | ||
assert_equal option_text, autocomplete_option.text | ||
assert_equal "", select_element.value | ||
|
||
# when I click on the matching option | ||
autocomplete_option.click | ||
|
||
# the autocomplete and select elements reflect my selection | ||
assert_equal option_text, autocomplete_input_element.value | ||
assert_equal option_value, select_element.value | ||
end | ||
|
||
def assert_resets_select_when_desynced_with_autocomplete( | ||
autocomplete_input_element:, | ||
select_element:, | ||
option_text:, | ||
unique_partial_string: | ||
) | ||
autocomplete_input_element.fill_in with: unique_partial_string | ||
autocomplete_option = find(".autocomplete__option") | ||
|
||
assert_equal unique_partial_string, autocomplete_input_element.value | ||
assert_equal option_text, autocomplete_option.text | ||
assert_equal "", select_element.value | ||
|
||
autocomplete_input_element.native.send_keys :escape | ||
end | ||
|
||
def assert_clear_autocomplete_selection_by_click(autocomplete_input_element:, select_element:) | ||
click_button "Clear selection" | ||
|
||
assert_equal "", autocomplete_input_element.value | ||
assert_equal "", select_element.value | ||
end | ||
|
||
def assert_clear_autocomplete_selection_by_space(autocomplete_input_element:, select_element:) | ||
clear_button = find(".js-autocomplete__clear-button") | ||
clear_button.native.send_keys :space | ||
|
||
assert_equal "", autocomplete_input_element.value | ||
assert_equal "", select_element.value | ||
end | ||
|
||
def assert_clear_autocomplete_selection_by_enter(autocomplete_input_element:, select_element:) | ||
clear_button = find(".js-autocomplete__clear-button") | ||
clear_button.native.send_keys :enter | ||
|
||
assert_equal "", autocomplete_input_element.value | ||
assert_equal "", select_element.value | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you feel about extracting these tests into more "component" style tests? That way we'd only need to test it once as we're reusing the component across multiple pages.
As it stands we're testing this behaviour twice across the two integration tests. We could then restrict the two test files modified in this PR to only test a user inputting some text into the autocomplete and inviting a user.