Skip to content
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

Adjust obs form system test expects #2318

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/controllers/observations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ form_element_data = {
id: "observation_naming_specimen", # @given_name.present?
collapse: "observation_naming_specimen_inner", open: create
) do
tag.div(class: "row mt-3") do
tag.div(class: "row") do
concat(tag.div(class: "col-xs-12 col-md-6") do
render(partial: "observations/namings/fields", locals: naming_locals)
end) if create
Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/observations/form/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ t_s = {

<%= tag.div(class: "panel-body border-top", id: "observation_details") do %>

<%= tag.div(class: "row mt-3") do %>
<%= tag.div(class: "row") do %>
<%= tag.div(class: "col-xs-12 col-md-6") do %>
<!-- WHEN -->
<%= date_select_with_label(
Expand Down
10 changes: 1 addition & 9 deletions app/views/controllers/observations/form/_projects.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ end
) %>
<% end %>

<%= tag.div do
[
tag.strong("#{:PROJECTS.l}:", class: "mr-3"),
collapse_info_trigger("project_help"),
collapse_help_block(nil, id: "project_help") do
:form_observations_project_help.t
end
].safe_join
end %>
<%= tag.p(:form_observations_project_help.t) %>

<%= tag.div(class: "overflow-scroll-checklist") do %>
<% @projects.each do |project| %>
Expand Down
10 changes: 1 addition & 9 deletions app/views/controllers/observations/form/_species_lists.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
<%# tag.div(id: "observation_lists") do %>
<%= fields_for(:list) do |f_l| %>

<%= tag.div do
[
tag.strong("#{:SPECIES_LISTS.l}:", class: "mr-3"),
collapse_info_trigger("species_lists_help"),
collapse_help_block(nil, id: "species_lists_help") do
:form_observations_list_help.t
end
].safe_join
end %>
<%= tag.p(:form_observations_list_help.t) %>

<%= tag.div(class: "overflow-scroll-checklist") do %>
<% @lists.each do |list| %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ herbarium_record. Fields hidden unless box checked. %>

<%= tag.div(id: "observation_specimen_section") do %>

<%= tag.div(class: "mt-3") do %>
<%= tag.div do %>
<%= check_box_with_label(
form: f, field: :specimen,
form: f, field: :specimen, class: "mt-0",
label: :form_observations_specimen_available.t,
help: :form_observations_specimen_available_help.t,
data: { toggle: "collapse", target: "#specimen_fields" },
Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/shared/_notes_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
indent = form.object_name == "observation" ? "" : "ml-5"
%>
<!-- NOTES -->
<%= tag.div(id: "#{form.object_name}_notes") do %>
<%= tag.div(id: "#{form.object_name}_notes_fields") do %>
<%= general_help %>
<%= tag.div(class: indent) do %>
<%= form.fields_for(:notes) do |f_n| %>
Expand Down
69 changes: 37 additions & 32 deletions test/system/observation_form_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ def test_create_minimal_observation
assert_field("observation_place_name", with: locations.first.name)

# Move to the next step, Identification
step_nav_1 = find("#step-nav-1")
scroll_to(step_nav_1, align: :top)
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)

fill_in("naming_name", with: "Elfin saddle")
# don't wait for the autocompleter - we know it's an elfin saddle!
Expand All @@ -50,9 +49,8 @@ def test_create_minimal_observation
assert_field("observation_place_name", with: locations.first.name)

# Move to the next step, Identification
step_nav_1 = find("#step-nav-1")
scroll_to(step_nav_1, align: :top)
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)

assert_selector("#name_messages", text: "MO does not recognize the name")
fill_in("naming_name", with: "Coprinus com")
Expand Down Expand Up @@ -105,9 +103,8 @@ def test_trying_to_create_duplicate_location_just_uses_existing_location
assert_field("observation_location_id", with: "", type: :hidden)

# Move to the next step, Identification
step_nav_1 = find("#step-nav-1")
scroll_to(step_nav_1, align: :top)
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)

within("#observation_form") { click_commit }

Expand Down Expand Up @@ -150,7 +147,9 @@ def test_autofill_location_from_geotagged_image_nothing_matches
assert_image_date_copied_to_obs(GEOTAGGED_EXIF)
sleep(0.5)
# we should have the new type of location_google autocompleter now
assert_selector("[data-type='location_google'][data-stimulus='connected']")
assert_selector(
"[data-type='location_google'][data-stimulus='autocompleter-connected']"
)
# Place name should now have been filled by Google, no MO locations match
assert_field("observation_place_name", with: UNIVERSITY_PARK[:name],
wait: 6)
Expand Down Expand Up @@ -248,9 +247,8 @@ def test_post_edit_and_destroy_with_details_and_location
assert_field("observation_place_name", with: last_obs.where)

# Move to the next step, Identification
step_nav_1 = find("#step-nav-1")
scroll_to(step_nav_1, align: :top)
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)

assert_field("naming_name", with: "")
assert(last_obs.is_collection_location)
Expand All @@ -259,9 +257,8 @@ def test_post_edit_and_destroy_with_details_and_location
assert_field(other_notes_id, with: "", visible: :all)

# Move to the previous step, Images/Details
step_nav_2 = find("#step-nav-2")
scroll_to(step_nav_2, align: :top)
within(step_nav_2) { click_on(:BACK.l) }
images_details = find("#observation_images_details")
scroll_to(images_details, align: :top)

# Add the images separately, so we can be sure of the order. Otherwise,
# images appear in the order each upload finishes, which is unpredictable.
Expand Down Expand Up @@ -367,7 +364,8 @@ def test_post_edit_and_destroy_with_details_and_location
uncheck("observation_is_collection_location", visible: :all)

# Move to the next step, Identification
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)
sleep(1)

specimen_section = find("#observation_specimen_section", visible: :all)
Expand All @@ -379,14 +377,15 @@ def test_post_edit_and_destroy_with_details_and_location
fill_in(other_notes_id, with: "Notes for observation", visible: :all)

# Move to the next step, Projects/Lists
within(step_nav_2) { click_on(:NEXT.l) }
projects = find("#observation_projects")
scroll_to(projects, align: :top)

# Inherited project constraints maybe messing with this observation - clear
all('[id^="project_id_"]', visible: :all).each do |project_checkbox|
project_checkbox.trigger("click") if project_checkbox.checked?
end
step_nav_3 = find("#step-nav-3")
within(step_nav_3) { click_on(:BACK.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)

# submit_observation_form_with_errors
within("#observation_form") { click_commit }
Expand Down Expand Up @@ -431,25 +430,30 @@ def test_post_edit_and_destroy_with_details_and_location
assert_image_exif_available(SO_PASA_EXIF)
end

fill_in("observation_place_name", with: "")
fill_in("observation_place_name", with: "south pas")
click_on(:form_observations_create_locality.l)
# lat/lng does not match Google's Pasadena, but does match South Pasadena
assert_selector("[data-type='location_google']")
find("#observation_place_name").trigger("focus")
# assert_selector(".auto_complete", wait: 6)
assert_selector(".dropdown-item a[data-id='-1']",
text: SOUTH_PASADENA[:name], visible: :all, wait: 6)
# assert_selector(".dropdown-item a[data-id='-1']",
# text: SOUTH_PASADENA[:name], visible: :all, wait: 6)
# There may be more than one of these, click the first
find(".dropdown-item a[data-id='-1']",
text: SOUTH_PASADENA[:name], visible: :all).trigger("click")

# find(".dropdown-item a[data-id='-1']",
# text: SOUTH_PASADENA[:name], visible: :all).trigger("click")
assert_field("observation_place_name", with: SOUTH_PASADENA[:name])
sleep(1)
# debugger
# Check the hidden fields returned by Google
assert_hidden_location_fields_filled(SOUTH_PASADENA)

# Move to the next step, Identification
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)

assert_selector("[data-type='name'][data-stimulus='connected']")
assert_selector(
"[data-type='name'][data-stimulus='autocompleter-connected']"
)
fill_in("naming_name", with: "Agaricus campestris")
assert_field("naming_name", with: "Agaricus campestris")
select(Vote.confidence(Vote.next_best_vote), from: "naming_vote_value")
Expand Down Expand Up @@ -523,7 +527,8 @@ def test_post_edit_and_destroy_with_details_and_location
sleep(1)

# Move to the next step, Identification
within(step_nav_1) { click_on(:NEXT.l) }
naming = find("#observation_naming_specimen")
scroll_to(naming, align: :top)
sleep(1)

obs_notes = find("#observation_notes")
Expand Down Expand Up @@ -636,9 +641,9 @@ def assert_date_is_now
end

def assert_geolocation_is_empty
assert_field("observation_lat", with: "")
assert_field("observation_lng", with: "")
assert_field("observation_alt", with: "")
assert_field("observation_lat", with: "", visible: :all)
assert_field("observation_lng", with: "", visible: :all)
assert_field("observation_alt", with: "", visible: :all)
end

def assert_image_exif_available(image_data)
Expand Down