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

Update Turbo Drive <meta> across navigations #550

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions test/dummy/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PagesController < ApplicationController
end
16 changes: 16 additions & 0 deletions test/dummy/app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= turbo_refreshes_with method: params.fetch(:turbo_refresh_method, :replace).to_sym, scroll: params.fetch(:turbo_refresh_scroll, :reset).to_sym %>

<h1><%= params[:id].titleize %></h1>

<% {
classic: {
turbo_refresh_method: :replace,
turbo_refresh_scroll: :reset,
},
morph: {
turbo_refresh_method: :morph,
turbo_refresh_scroll: :preserve,
}
}.each do |id, refresh| %>
<%= link_to_unless_current id.to_s.titleize, page_path(id, refresh) %>
<% end %>
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :pages, only: :show
resources :articles do
delete :destroy_all, on: :collection
end
Expand Down
26 changes: 26 additions & 0 deletions test/system/navigations_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "application_system_test_case"

class NavigationsTest < ApplicationSystemTestCase
test "navigation updates Turbo Refresh meta tags" do
visit page_path(:classic)

within "head", visible: false do
assert_selector :element, "meta", name: "turbo-refresh-method", content: "replace", visible: false, count: 1
assert_selector :element, "meta", name: "turbo-refresh-scroll", content: "reset", visible: false, count: 1
end

click_link "Morph"

within "head", visible: false do
assert_selector :element, "meta", name: "turbo-refresh-method", content: "morph", visible: false, count: 1
assert_selector :element, "meta", name: "turbo-refresh-scroll", content: "preserve", visible: false, count: 1
end

click_link "Classic"

within "head", visible: false do
assert_selector :element, "meta", name: "turbo-refresh-method", content: "replace", visible: false, count: 1
assert_selector :element, "meta", name: "turbo-refresh-scroll", content: "reset", visible: false, count: 1
end
end
end