diff --git a/app/components/avo/views/resource_index_component.html.erb b/app/components/avo/views/resource_index_component.html.erb index 5065694280..08437ed343 100644 --- a/app/components/avo/views/resource_index_component.html.erb +++ b/app/components/avo/views/resource_index_component.html.erb @@ -11,7 +11,7 @@ description: description, cover_photo: resource.cover_photo, data: {component: "resources-index"}, - display_breadcrumbs: @reflection.blank? + display_breadcrumbs: @reflection.blank? || (@reflection.present? && !helpers.turbo_frame_request?) ) do |c| %> <% c.with_name_slot do %> <%= render Avo::PanelNameComponent.new name: title, url: (params[:turbo_frame].present? && linkable?) ? field.frame_url(add_turbo_frame: false) : nil, target: :_blank do |panel_name_component| %> diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 45d116f484..965088d69f 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -18,6 +18,11 @@ class BaseController < ApplicationController def index @page_title = @resource.plural_name.humanize + + if @reflection.present? && !turbo_frame_request? + add_breadcrumb @record.class.to_s.pluralize, resources_path(resource: @parent_resource) + add_breadcrumb @parent_resource.record_title, resource_path(record: @record, resource: @parent_resource) + end add_breadcrumb @resource.plural_name.humanize set_index_params diff --git a/spec/features/avo/belongs_to_spec.rb b/spec/features/avo/belongs_to_spec.rb index aac173f084..f22d2e65af 100644 --- a/spec/features/avo/belongs_to_spec.rb +++ b/spec/features/avo/belongs_to_spec.rb @@ -154,7 +154,8 @@ expect(find("thead")).not_to have_text "User" expect(page).to have_text comment.id expect(page).to have_text "a comment" - expect(page).not_to have_text user.name + # breadcrumb contains the user's name + expect(page).to have_text user.name, count: 1 end end @@ -173,7 +174,8 @@ expect(page).to have_text comment.id expect(page).to have_text "a comment" expect(page).to have_text user.name - expect(page).not_to have_text project.name + # breadcrumb contains the project's name + expect(page).to have_text project.name, count: 1 end end @@ -192,7 +194,8 @@ expect(page).to have_text review.id expect(page).to have_text "a review" expect(page).to have_text user.name - expect(page).not_to have_text team.name + # breadcrumb contains the team's name + expect(page).to have_text team.name, count: 1 end end end diff --git a/spec/features/avo/breadcrumbs_spec.rb b/spec/features/avo/breadcrumbs_spec.rb index c8db0851ce..8b30e8ced1 100644 --- a/spec/features/avo/breadcrumbs_spec.rb +++ b/spec/features/avo/breadcrumbs_spec.rb @@ -21,4 +21,37 @@ it { is_expected.to have_css ".breadcrumbs" } it { is_expected.to have_text "Home\n" } end + + describe "on a has_and_belongs_to_many turbo frame" do + let!(:user) { create(:user) } + let!(:team) { create(:team) } + + it "displays breadcrumbs" do + url = "/admin/resources/users/#{user.slug}/teams?view=show" + visit url + + expect(page).to have_selector ".breadcrumbs" + expect(page.find(".breadcrumbs").text).to eq "Home Users #{user.name} Teams" + + breadcrumbs = find(".breadcrumbs") + expect(breadcrumbs).to have_link "Home" + expect(breadcrumbs).to have_link "Users" + expect(breadcrumbs).to have_link user.name.to_s + expect(breadcrumbs).to_not have_link "Teams" + end + + it "displays breadcrumbs" do + url = "/admin/resources/teams/#{team.id}/team_members?view=show" + visit url + + expect(page).to have_selector ".breadcrumbs" + expect(page.find(".breadcrumbs").text).to eq "Home Teams #{team.name} Users" + + breadcrumbs = find(".breadcrumbs") + expect(breadcrumbs).to have_link "Home" + expect(breadcrumbs).to have_link "Teams" + expect(breadcrumbs).to have_link team.name.to_s + expect(breadcrumbs).to_not have_link "Users" + end + end end