diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 53b69b5e..6cd14e1b 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -6,4 +6,5 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase Capybara.configure do |config| config.server = :puma, { Silent: true } + config.match = :prefer_exact end diff --git a/test/dummy/app/controllers/messages_controller.rb b/test/dummy/app/controllers/messages_controller.rb index 8ec60d44..7f68989e 100644 --- a/test/dummy/app/controllers/messages_controller.rb +++ b/test/dummy/app/controllers/messages_controller.rb @@ -1,4 +1,6 @@ class MessagesController < ApplicationController + before_action { sleep params.fetch(:sleep, 0).to_f } + def show @message = Message.new(id: 1, content: "My message") end @@ -17,4 +19,8 @@ def create def update @message = Message.new(id: 1, content: "My message") end + + def new + @message = Message.new + end end diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index 3d26ca03..dbd0158b 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -7,6 +7,35 @@ <%= stylesheet_link_tag 'application', media: 'all' %> <%= yield :head %> <%= javascript_importmap_tags %> + diff --git a/test/dummy/app/views/messages/new.html.erb b/test/dummy/app/views/messages/new.html.erb new file mode 100644 index 00000000..5b44a910 --- /dev/null +++ b/test/dummy/app/views/messages/new.html.erb @@ -0,0 +1,75 @@ + + +

a[data-disable-with]

+ +Page: Visit + +Frame: Visit + +
+ +

form[method="get"]

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ +

form[method="post"]

+ +<%= form_with model: @message do %> + + +<% end %> + +<%= form_with model: @message, data: { turbo_frame: "frame" } do |form| %> + + +<% end %> + +<%= form_with model: @message do |form| %> + + +<% end %> + +<%= form_with model: @message do %> + + +<% end %> + +<%= form_with model: @message, data: { turbo_frame: "frame" } do |form| %> + + +<% end %> + +<%= form_with model: @message do |form| %> + + +<% end %> diff --git a/test/system/ujs/disable_test.rb b/test/system/ujs/disable_test.rb new file mode 100644 index 00000000..5006893e --- /dev/null +++ b/test/system/ujs/disable_test.rb @@ -0,0 +1,153 @@ +require "application_system_test_case" + +class UjsHTMLAnchorElementTest < ApplicationSystemTestCase + test "supports with a[data-disable-with]" do + visit new_message_path + + click_link "Page: Visit" + + assert_link "Page: Visiting" + assert_link "Frame: Visit" + assert_no_link "Page: Visiting" + end + + test "supports a[data-turbo-frame][data-disable-with]" do + visit new_message_path + + click_link "Frame: Visit" + + assert_link "Frame: Visiting" + assert_link "Frame: Visit" + assert_no_link "Frame: Visiting" + end +end + +class UjsHTMLButtonElementTest < ApplicationSystemTestCase + # test "supports form[method=get] button[data-disable-with]" do + # visit new_message_path + # + # click_button "Page: Submit GET form button" + # + # assert_button "Page: Submitting GET form button", disabled: true + # assert_no_button "Page: Submit GET form button" + # assert_button "Page: Submit GET form button" + # assert_no_button "Page: Submitting GET form button" + # end + # + # test "supports form[method=get][data-turbo-frame] button[data-disable-with]" do + # visit new_message_path + # + # click_button "Frame: Submit GET form[data-turbo-frame] button" + # + # assert_button "Frame: Submitting GET form[data-turbo-frame] button", disabled: true + # assert_no_button "Frame: Submitting GET form[data-turbo-frame] button" + # assert_button "Frame: Submit GET form[data-turbo-frame] button" + # assert_no_button "Frame: Submitting GET form[data-turbo-frame] button" + # end + # + # test "supports form[method=get] button[data-disable-with][data-turbo-frame]" do + # visit new_message_path + # + # click_button "Frame: Submit GET form button[data-turbo-frame]" + # + # assert_button "Frame: Submitting GET form button[data-turbo-frame]", disabled: true + # assert_no_button "Frame: Submitting GET form button[data-turbo-frame]" + # assert_button "Frame: Submitting GET form button[data-turbo-frame]" + # assert_no_button "Frame: Submitting GET form button[data-turbo-frame]" + # end + # + test "supports form[method=post] button[data-disable-with]" do + visit new_message_path + + click_button "Submit POST form button" + + assert_button "Submitting POST form button", disabled: true + assert_button "Submit POST form button" + assert_no_button "Submitting POST form button" + end + + test "supports form[method=post] button[data-turbo-frame][data-disable-with]" do + visit new_message_path + + click_button "Submit POST form button[data-turbo-frame]" + + assert_button "Submitting POST form button[data-turbo-frame]", disabled: true + assert_button "Submit POST form button[data-turbo-frame]" + assert_no_button "Submitting POST form button[data-turbo-frame]" + end + + test "supports form[method=post][data-turbo-frame] button[data-disable-with]" do + visit new_message_path + + click_button "Submit POST form[data-turbo-frame] button" + + assert_button "Submitting POST form[data-turbo-frame] button", disabled: true + assert_button "Submit POST form[data-turbo-frame] button" + assert_no_button "Submitting POST form[data-turbo-frame] button" + end +end + +class UjsHTMLInputElementTest < ApplicationSystemTestCase + # test "supports form[method=get] input[data-disable-with]" do + # visit new_message_path + # + # click_button "Page: Submit GET form input" + # + # assert_button "Page: Submitting GET form input", disabled: true + # assert_no_button "Page: Submit GET form input" + # assert_button "Page: Submit GET form input" + # assert_no_button "Page: Submitting GET form input" + # end + # + # test "supports form[method=get][data-turbo-frame] input[data-disable-with]" do + # visit new_message_path + # + # click_button "Frame: Submit GET form[data-turbo-frame] input" + # + # assert_button "Frame: Submitting GET form input", disabled: true + # assert_no_button "Frame: Submitting GET form[data-turbo-frame] input" + # assert_button "Frame: Submit GET form[data-turbo-frame] input" + # assert_no_button "Frame: Submitting GET form[data-turbo-frame] input" + # end + # + # test "supports form[method=get] input[data-disable-with][data-turbo-frame]" do + # visit new_message_path + # + # click_button "Frame: Submit GET form input[data-turbo-frame]" + # + # assert_button "Frame: Submitting GET form input[data-turbo-frame]", disabled: true + # assert_no_button "Frame: Submitting GET form input[data-turbo-frame]" + # assert_button "Frame: Submitting GET form input[data-turbo-frame]" + # assert_no_button "Frame: Submitting GET form input[data-turbo-frame]" + # end + + test "supports form[method=post] input[data-disable-with]" do + visit new_message_path + + click_button "Submit POST form input" + + assert_button "Submitting POST form input", disabled: true + assert_button "Submit POST form input" + assert_no_button "Submitting POST form input" + end + + test "supports form[method=post] input[data-turbo-frame][data-disable-with]" do + visit new_message_path + + click_button "Submit POST form input[data-turbo-frame]" + + assert_button "Submitting POST form input[data-turbo-frame]", disabled: true + assert_button "Submit POST form input[data-turbo-frame]" + assert_no_button "Submitting POST form input[data-turbo-frame]" + end + + test "supports form[method=post][data-turbo-frame] input[data-disable-with]" do + visit new_message_path + + click_button "Submit POST form[data-turbo-frame] input" + + assert_button "Submitting POST form[data-turbo-frame] input", disabled: true + assert_button "Submit POST form[data-turbo-frame] input" + assert_no_button "Submitting POST form[data-turbo-frame] input" + end +end