Skip to content

Commit

Permalink
Set up failing test for facility reviews as well as fabricators for a…
Browse files Browse the repository at this point in the history
…ll the other stuff
  • Loading branch information
DanielJackson-Oslo committed Feb 15, 2024
1 parent 123fd5b commit d15f602
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/models/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ def relevant_space_facilities(grouped: false)
group_space_facilities(relevant)
end

# Facilities (not space facilities :P) that are relevant.
# Facilities (found through space facilities) that are relevant.
def relevant_facilities
space_facilities.where(relevant: true).map(&:facility)
space_facilities.includes(:facility).where(relevant: true).map(&:facility)
end

# Space Facilities that are typically NOT relevant for the space
Expand Down
5 changes: 0 additions & 5 deletions config/locales/nb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ nb:
delete_confirmation: "Er du sikker på at du vil slette?"
close_contact: "Lukk"
tooltips:
facility_single_experience:
was_allowed: 'Fikk bruke'
was_not_allowed: 'Fikk ikke bruke'
was_not_available: 'De har ikke'
havent_asked: 'Ikke spurt'
facility_aggregated_experience:
unknown: 'Usikkert. Ingen har spurt!'
impossible: 'De har ikke.'
Expand Down
27 changes: 27 additions & 0 deletions spec/fabricators/facilities_category_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

Fabricator(:facilities_category) do
facility
facility_category
end

# == Schema Information
#
# Table name: facilities_categories
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# facility_category_id :bigint not null
# facility_id :bigint not null
#
# Indexes
#
# index_facilities_categories_on_facility_category_id (facility_category_id)
# index_facilities_categories_on_facility_id (facility_id)
#
# Foreign Keys
#
# fk_rails_... (facility_category_id => facility_categories.id)
# fk_rails_... (facility_id => facilities.id)
#
4 changes: 4 additions & 0 deletions spec/fabricators/facility_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Fabricator(:facility) do
title { Faker::Name.first_name }
icon { Faker::Name.first_name }

after_create do |facility|
Fabricate(:facilities_category, facility:)
end
end

# == Schema Information
Expand Down
16 changes: 16 additions & 0 deletions spec/fabricators/image_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@
space
image { Rack::Test::UploadedFile.new(TestImageHelper.image_path, TestImageHelper.content_type) }
end

# == Schema Information
#
# Table name: images
#
# id :bigint not null, primary key
# caption :string
# credits :string
# created_at :datetime not null
# updated_at :datetime not null
# space_id :bigint
#
# Indexes
#
# index_images_on_space_id (space_id)
#
31 changes: 31 additions & 0 deletions spec/fabricators/space_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@
space_group
space_types { [Fabricate(:space_type)] }
star_rating { nil }

after_create do |space|
space_type = space.space_types.first

relevant_facility_one = Fabricate(:facility)
relevant_facility_two = Fabricate(:facility)

# Make them relevant:
Fabricate(:space_types_facility,
space_type:,
facility: relevant_facility_one)
Fabricate(:space_types_facility,
space_type:,
facility: relevant_facility_two)

# Then create two relevant space facilities:
Fabricate(:space_facility,
space:,
facility: relevant_facility_one)
Fabricate(:space_facility,
space:,
facility: relevant_facility_two)

# And four irrelevant ones:
Fabricate.times(4,
:space_facility,
space:)

# Then aggregate reviews
space.aggregate_facility_reviews
end
end

# == Schema Information
Expand Down
31 changes: 31 additions & 0 deletions spec/fabricators/space_facility_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

Fabricator(:space_facility) do
facility
relevant true
experience :unknown
end

# == Schema Information
#
# Table name: space_facilities
#
# id :bigint not null, primary key
# description :string
# experience :integer
# relevant :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# facility_id :bigint not null
# space_id :bigint not null
#
# Indexes
#
# index_space_facilities_on_facility_id (facility_id)
# index_space_facilities_on_space_id (space_id)
#
# Foreign Keys
#
# fk_rails_... (facility_id => facilities.id)
# fk_rails_... (space_id => spaces.id)
#
27 changes: 27 additions & 0 deletions spec/fabricators/space_types_facility_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

Fabricator(:space_types_facility) do
space_type
facility
end

# == Schema Information
#
# Table name: space_types_facilities
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# facility_id :bigint not null
# space_type_id :bigint not null
#
# Indexes
#
# index_space_types_facilities_on_facility_id (facility_id)
# index_space_types_facilities_on_space_type_id (space_type_id)
#
# Foreign Keys
#
# fk_rails_... (facility_id => facilities.id)
# fk_rails_... (space_type_id => space_types.id)
#
46 changes: 46 additions & 0 deletions spec/features/user_creates_facility_reviews_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require "rails_helper"

describe "User creates facility reviews", :js do
let!(:space) do
Fabricate(:space, address: "Ulefossvegen 32", post_number: 3730, post_address: "Skien", lat: 59.196, lng: 9.603)
end

before do
create_user!
end

it "User leaves facility reviews for both facilities" do
no_reviews_selector = "li[title='#{I18n.t('tooltips.facility_aggregated_experience.unknown')}']"
reviewed_selector = "li[title='#{I18n.t('tooltips.facility_aggregated_experience.likely')}']"

first_facility = space.space_facilities.first.facility
second_facility = space.space_facilities.second.facility

login_and_logout_with_warden do
visit space_path(space)

expect(page).to have_selector(no_reviews_selector)

find("button[aria-label='Rediger fasiliteter']").click

fieldset = find("fieldset", text: first_facility.title)
within(fieldset) do
click_on("Rediger")
choose(I18n.t("reviews.form.facility_experience_particular_tense.was_allowed"), allow_label_click: true)
end

second_fieldset = find("fieldset", text: second_facility.title)
within(second_fieldset) do
click_on("Rediger")
choose(I18n.t("reviews.form.facility_experience_particular_tense.was_allowed"), allow_label_click: true)
end

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

expect(page).to have_selector(reviewed_selector)
expect(page).to have_no_selector(no_reviews_selector)
end
end
end
4 changes: 0 additions & 4 deletions spec/features/user_views_homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
create_user!
login_with_warden!

category = Fabricate(:facility_category)
category.facilities << facility_toilet
category.facilities << facility_beds

Fabricate(:facility_review, space: space_one, facility: facility_toilet, experience: :was_allowed)
Fabricate(:facility_review, space: space_one, facility: facility_beds, experience: :was_not_allowed)

Expand Down

0 comments on commit d15f602

Please sign in to comment.