Skip to content

Commit

Permalink
Fix bug in this branch where we would only list facilities with revie…
Browse files Browse the repository at this point in the history
…ws, instead of all relevant ones + fix a test
  • Loading branch information
DanielJackson-Oslo committed Feb 29, 2024
1 parent 0843090 commit 14c7d3f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
6 changes: 3 additions & 3 deletions app/models/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ def non_relevant_space_facilities(grouped: false)
def filtered_space_facilities(relevant: true, grouped: false, user: nil)
ungrouped_facilities = space_facilities.includes(facility: [:facilities_categories]).where(relevant:)
# If a user is defined, include facility reviews for that user
if user
if user.present?
ungrouped_facilities = ungrouped_facilities
.includes(facility: [:facility_reviews])
.where(relevant:, facility_reviews: { space: self })
.includes(facility: [:facilities_categories, :facility_reviews])
.where(relevant:)
end

return ungrouped_facilities unless grouped
Expand Down
31 changes: 15 additions & 16 deletions app/views/facility_reviews/_facility_with_edit_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<%# locals: (title:, tooltip:, space_id:, facility_review:, experience:, facility_category_id:, facility_id:, description: %>
<%= turbo_frame_tag dom_id(facility_review, "category_#{facility_category_id}__facility_#{facility_id}__") do %>
<div title="<%= tooltip %>">
<%= link_to new_facility_review_path(
space_id:,
facility_id:,
facility_category_id:,
), class: 'unstyled-link inline-flex gap-2 items-center collapsable-wrapper' do %>
<%= link_to new_facility_review_path(
space_id:,
facility_id:,
facility_category_id:,
),
title: tooltip,
class: 'unstyled-link inline-flex gap-2 items-center collapsable-wrapper' do %>

<h4 class="text-base <%= "line-through text-gray-600" if experience == "impossible" %>"><%= title %></h4>
<h4 class="text-base <%= "line-through text-gray-600" if experience == "impossible" %>"><%= title %></h4>

<%= inline_svg_tag "facility_status/#{experience}", class: "#{" text-black " if experience == "impossible" }" %>
<%= inline_svg_tag "facility_status/#{experience}", class: "#{" text-black " if experience == "impossible" }" %>

<span class="edit-button edit-button--small collapsable">
<span class="text">
<%= t('space_edit.edit') %>
</span>
<%= inline_svg_tag 'edit', alt: t('space_edit.edit'), title: t('space_edit.edit') %>
<span class="edit-button edit-button--small collapsable">
<span class="text">
<%= t('space_edit.edit') %>
</span>
<% end %>

</div>
<%= inline_svg_tag 'edit', alt: t('space_edit.edit'), title: t('space_edit.edit') %>
</span>
<% end %>
<% unless description.nil? %>
<div class="text-gray-400 mb-1.5">
Expand Down
40 changes: 15 additions & 25 deletions spec/support/user_creates_facility_reviews_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,44 +69,34 @@ def expect_to_add_multiple_facility_reviews(

def click_to_create_new_facility_review(facility:,
description_to_add: "")
open_form_modal

enter_data_about_facility(facility:, description_to_add:)

save_form_modal
end

def click_to_create_multiple_facility_reviews(facilities_to_review: [])
open_form_modal

facilities_to_review.each do |facility|
enter_data_about_facility(facility:)
end

save_form_modal
end

def open_form_modal
# Click the edit button
find("button[aria-label='Rediger fasiliteter']").click
end

def save_form_modal
click_on(I18n.t("facility_reviews.save"))

# Wait for the save to go through
expect(page).to have_text(I18n.t("reviews.added_review"))
end

def enter_data_about_facility(facility:, description_to_add: "")
fieldset = first("fieldset", text: facility.title)
within(fieldset) do
click_on("Rediger")
edit_button = first("a", text: facility.title)
edit_button.click

form = find("form", text: facility.title, wait: 10)
within(form) do
choose(I18n.t("reviews.form.facility_experience_particular_tense.was_allowed"), allow_label_click: true)

# Add a description
fill_in(I18n.t("simple_form.labels.space_facility.description"), with: description_to_add)

# And save
submit_button = find("button[type=submit]")
submit_button.click
end

# Then wait until the save is done and flash message is shown
expect(page).to have_text(I18n.t("reviews.added_review"))
end

# rubocop:disable Metrics/ParameterLists, Metrics/MethodLength, Metrics/AbcSize # This is a test helper, it's fine
Expand All @@ -131,8 +121,8 @@ def expect_changes_around_reviewing_facility(
count_of_visible_facilities - count_should_have_new_experience

# CSS selectors for reviewed and non reviewed facilities
no_reviews_selector = "li[title='#{I18n.t('tooltips.facility_aggregated_experience.unknown')}']"
reviewed_selector = "li[title='#{I18n.t("tooltips.facility_aggregated_experience.#{expected_new_experience}")}']"
no_reviews_selector = "a[title='#{I18n.t('tooltips.facility_aggregated_experience.unknown')}']"
reviewed_selector = "a[title='#{I18n.t("tooltips.facility_aggregated_experience.#{expected_new_experience}")}']"

relevant_space_facilities = space.relevant_space_facilities
space_facilities_matching_facility = relevant_space_facilities.where(facility:)
Expand Down Expand Up @@ -163,7 +153,7 @@ def expect_changes_around_reviewing_facility(
# Check that the reviewed facility changed in the model:
expect(
space_facilities_matching_facility.reload.all? do |space_facility|
space_facility.experience == expected_new_experience
space_facility.reload.experience == expected_new_experience
end
).to be(true)

Expand Down

0 comments on commit 14c7d3f

Please sign in to comment.