Skip to content

Commit

Permalink
Add system spec for SectionNavigation
Browse files Browse the repository at this point in the history
  • Loading branch information
zspencer committed Dec 4, 2023
1 parent 8209187 commit 4c0b8ec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/furniture/section_navigation/section_navigation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SectionNavigation
class SectionNavigation < Furniture
location(parent: :room)
default_scope { where(furniture_kind: "section_navigation") }

def rooms
space.rooms.where.not(id: space.entrance_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<div class="mt-3 grid grid-cols-1 gap-5 sm:gap-6 sm:grid-cols-2 lg:grid-cols-4 items-center">
<% policy_scope(section_navigation.rooms).each do |room| %>
<%= link_to [room.space, room], class: "no-underline" do %>
<%= render CardComponent.new(
data: { access_level: room.access_level, slug: room.slug, model: "room", id: room.id },
classes: "group self-stretch hover:bg-orange-50"
) do %>
<%= link_to polymorphic_path(room.location), class: "no-underline" do %>
<%= render CardComponent.new(classes: "group self-stretch hover:bg-orange-50") do %>
<div class="px-4 py-5 flex items-center justify-between">
<h3 class="text-base font-semibold text-orange-500 group-hover:text-orange-400">
<%= room.name %>
Expand Down
5 changes: 5 additions & 0 deletions spec/furniture/section_navigation/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :section_navigation, class: "SectionNavigation::SectionNavigation" do
room
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "rails_helper"
require_relative "factories"

RSpec.describe SectionNavigation, type: :system do
it "includes a link to every section except the entrance" do
space = create(:space, :with_entrance)
rooms = create_list(:room, 2, space:)
create(:section_navigation, room: space.entrance)

visit polymorphic_path(space.entrance.location)

expect(page).to have_link(rooms.first.name, href: polymorphic_path(rooms.first.location))
expect(page).to have_link(rooms.last.name, href: polymorphic_path(rooms.last.location))
expect(page).not_to have_link(space.entrance.name, href: polymorphic_path(space.entrance.location))
end
end

0 comments on commit 4c0b8ec

Please sign in to comment.