Skip to content

Commit

Permalink
fix: no link on breadcrumb when visiting from an association (#3226)
Browse files Browse the repository at this point in the history
* fix: breadcrumb when visit show from association

* approach 1

* coherence

* tests
  • Loading branch information
Paul-Bob authored Sep 12, 2024
1 parent 5f37ee4 commit 4e38e0d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
11 changes: 9 additions & 2 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ def show

add_breadcrumb via_resource.plural_name, resources_path(resource: via_resource)
add_breadcrumb via_resource.record_title, resource_path(record: via_record, resource: via_resource)

add_breadcrumb @resource.plural_name.humanize
else
add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
end

add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)

add_breadcrumb @resource.record_title
add_breadcrumb I18n.t("avo.details").upcase_first
Expand Down Expand Up @@ -120,9 +123,12 @@ def new

add_breadcrumb via_resource.plural_name, resources_path(resource: via_resource)
add_breadcrumb via_resource.record_title, resource_path(record: via_record, resource: via_resource)

add_breadcrumb @resource.plural_name.humanize
else
add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
end

add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
add_breadcrumb t("avo.new").humanize

set_component_for __method__, fallback_view: :edit
Expand Down Expand Up @@ -440,6 +446,7 @@ def set_edit_title_and_breadcrumbs
via_resource_class: params[:via_resource_class],
via_record_id: params[:via_record_id]
}
add_breadcrumb @resource.plural_name.humanize
else
add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource)
end
Expand Down
49 changes: 48 additions & 1 deletion spec/features/avo/breadcrumbs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.feature "Breadcrumbs", type: :feature do
let!(:project) { create :project }
let!(:project) { create :project, users: [admin] }
let!(:url) { "/admin/resources/projects/#{project.id}/edit" }

before do
Expand Down Expand Up @@ -101,4 +101,51 @@
end
end
end

describe "on associations" do
it "show" do
url = avo.resources_project_path(project, via_record_id: admin, via_resource_class: Avo::Resources::User)
visit url

breadcrumbs = find(".breadcrumbs")
expect(breadcrumbs).to have_link "Home"
expect(breadcrumbs).to have_link "Users"
expect(breadcrumbs).to have_link admin.name
expect(breadcrumbs).to_not have_link "Projects"
expect(breadcrumbs).to have_text "Projects"
expect(breadcrumbs).to_not have_link project.name
expect(breadcrumbs).to have_text project.name
expect(breadcrumbs).to_not have_link "Details"
expect(breadcrumbs).to have_text "Details"
end

it "edit" do
url = avo.edit_resources_project_path(project, via_record_id: admin, via_resource_class: Avo::Resources::User)
visit url

breadcrumbs = find(".breadcrumbs")
expect(breadcrumbs).to have_link "Home"
expect(breadcrumbs).to have_link "Users"
expect(breadcrumbs).to have_link admin.name
expect(breadcrumbs).to_not have_link "Projects"
expect(breadcrumbs).to have_text "Projects"
expect(breadcrumbs).to have_link project.name
expect(breadcrumbs).to_not have_link "Edit"
expect(breadcrumbs).to have_text "Edit"
end

it "new" do
url = avo.new_resources_project_path(via_record_id: admin, via_resource_class: Avo::Resources::User, via_relation: :users, via_relation_class: "User")
visit url

breadcrumbs = find(".breadcrumbs")
expect(breadcrumbs).to have_link "Home"
expect(breadcrumbs).to have_link "Users"
expect(breadcrumbs).to have_link admin.name
expect(breadcrumbs).to_not have_link "Projects"
expect(breadcrumbs).to have_text "Projects"
expect(breadcrumbs).to_not have_link "New"
expect(breadcrumbs).to have_text "New"
end
end
end

0 comments on commit 4e38e0d

Please sign in to comment.