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

🥗🧹 Gizmo: System Spec to Add and Remove Gizmo #1588

Merged
merged 2 commits into from
Jun 25, 2023
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
3 changes: 2 additions & 1 deletion app/assets/stylesheets/components/button.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* @todo DELETE ME */
@layer components {
[type="reset"],
[type="button"],
[type="submit"],
button,
.button {
@apply font-bold py-2 px-4 my-1 rounded bg-primary-500 text-white text-center transition ease-in-out duration-150;
@apply font-bold py-2 px-4 rounded bg-primary-500 text-white text-center transition ease-in-out duration-150;

&:hover {
@apply bg-primary-700;
Expand Down
1 change: 1 addition & 0 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Room < ApplicationRecord

has_many :furnitures, dependent: :destroy, inverse_of: :room
accepts_nested_attributes_for :furnitures
alias_method :gizmos, :furnitures

def full_slug
"#{space.slug}--#{slug}"
Expand Down
11 changes: 7 additions & 4 deletions app/views/furnitures/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<section id="<%= dom_id(furniture) %>">
<%- if policy(furniture).edit? %>
<%= form_with(model: [furniture.room.space, furniture.room, furniture], local: true) do |form| %>
<%= form_with(model: [furniture.room.space, furniture.room, furniture]) do |form| %>
<div>
<%= render partial: furniture.furniture.form_template, locals: { form: form } %>
</div>
<footer>
<%- if policy(furniture).destroy? %>
<%= form.button name: "_method", value: "delete", class: "--danger" do %>
<%=t('.destroy')%>
<%- end %>
<%= render ButtonComponent.new(
label: t('.destroy', name: furniture.furniture.model_name.human.titleize),
href: [furniture.room.space, furniture.room, furniture],
title: t('.destroy', name: furniture.furniture.model_name.human.titleize),
method: :delete,
scheme: :danger) %>
<%- end %>

<%- if furniture.furniture.attribute_names.present? %>
Expand Down
1 change: 1 addition & 0 deletions app/views/furnitures/_furniture.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
label: t('icons.edit'),
href: edit_href,
method: :get,
turbo_stream: true,
title: t('.edit_title', name: furniture.furniture.model_name.human.titleize),
scheme: :secondary) %>
<%- end %>
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
factory :space do
sequence(:name) { |n| "#{Faker::Book.title} #{n}" }

trait :with_entrance do
entrance { association(:room, space: instance) }
end

trait :with_members do
transient do
member_count { 4 }
Expand Down
41 changes: 41 additions & 0 deletions spec/system/furniture_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "rails_helper"

# @see https://github.com/zinc-collective/convene/issues/709
describe "Furniture" do
include ActiveJob::TestHelper
it "Managing Furniture" do
space = create(:space, :with_entrance, :with_members, member_count: 1)
sign_in(space.members.first, space)

add_gizmo("Markdown Text Block", room: space.entrance)
remove_gizmo("Markdown Text Block", room: space.entrance)

visit(polymorphic_path(space.entrance.location(:edit)))
expect(page).to have_text("No gizmos yet.")
end

def sign_in(user, space)
visit(polymorphic_path(space.location))
click_link_or_button("Sign in")
fill_in("authenticated_session[contact_location]", with: user.email)
find('input[type="submit"]').click
perform_enqueued_jobs

visit(URI.parse(URI.extract(ActionMailer::Base.deliveries.first.body.to_s)[1]).request_uri)
end

def add_gizmo(type, room:)
visit(polymorphic_path(room.location(:edit)))
select(type, from: "Type of gizmo")
click_link_or_button("Add Gizmo")
end

def remove_gizmo(type, room:)
visit(polymorphic_path(room.location(:edit)))
expect(page).to have_text("Markdown Text Block")
within("##{ActionView::RecordIdentifier.dom_id(room.gizmos.first)}") do
click_link_or_button "Configure Markdown Text Block"
end
click_link_or_button "Remove Gizmo"
end
end