From 105c86ea587008802430b34ae5d97a5d81c14822 Mon Sep 17 00:00:00 2001 From: Cameron Dutro Date: Fri, 17 May 2024 11:50:55 -0700 Subject: [PATCH] Fix linting and test failures --- demo/config/environments/test.rb | 2 -- test/components/alpha/toggle_switch_test.rb | 2 +- test/lib/primer/forms/integration_forms_test.rb | 13 +++---------- test/lib/primer/forms/toggle_switch_form_test.rb | 13 +++++++++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/demo/config/environments/test.rb b/demo/config/environments/test.rb index 15c23e8a85..a2317052cc 100644 --- a/demo/config/environments/test.rb +++ b/demo/config/environments/test.rb @@ -48,9 +48,7 @@ config.autoload_paths << Rails.root.join("..", "test", "forms") config.view_component.preview_paths << Rails.root.join("..", "test", "previews") - # rubocop:disable Style/IfUnlessModifier if ENV.fetch("VC_COMPAT_PATCH_ENABLED", "false") == "true" config.view_component.capture_compatibility_patch_enabled = true end - # rubocop:enable Style/IfUnlessModifier end diff --git a/test/components/alpha/toggle_switch_test.rb b/test/components/alpha/toggle_switch_test.rb index b49f5d3d87..30a2d9fe1d 100644 --- a/test/components/alpha/toggle_switch_test.rb +++ b/test/components/alpha/toggle_switch_test.rb @@ -66,7 +66,7 @@ def test_small def test_csrf_token render_inline(Primer::Alpha::ToggleSwitch.new(src: "/foo", csrf_token: "abc123")) - assert_selector("[csrf]") + assert_selector("[data-csrf]") end end end diff --git a/test/lib/primer/forms/integration_forms_test.rb b/test/lib/primer/forms/integration_forms_test.rb index 936b0926c3..f6bea52321 100644 --- a/test/lib/primer/forms/integration_forms_test.rb +++ b/test/lib/primer/forms/integration_forms_test.rb @@ -47,19 +47,12 @@ def test_toggle_switch_form_errors wait_for_toggle_switch_spinner assert_selector("#error-toggle [data-target='toggle-switch.errorIcon']") - assert_selector(".FormControl-inlineValidation", text: "Bad CSRF token") + assert_selector(".FormControl-inlineValidation", text: "Something went wrong.") - page.evaluate_script(<<~JAVASCRIPT) - document - .querySelector('toggle-switch#error-toggle') - .setAttribute('csrf', 'let_me_in'); - JAVASCRIPT - - find("#error-toggle").click + find("#success-toggle").click wait_for_toggle_switch_spinner - refute_selector("#error-toggle [data-target='toggle-switch.errorIcon']") - refute_selector("#error-toggle", text: "Bad CSRF token") + refute_selector("#success-toggle [data-target='toggle-switch.errorIcon']") end def test_action_menu_form_input diff --git a/test/lib/primer/forms/toggle_switch_form_test.rb b/test/lib/primer/forms/toggle_switch_form_test.rb index 9c62d760e9..80fc31b149 100644 --- a/test/lib/primer/forms/toggle_switch_form_test.rb +++ b/test/lib/primer/forms/toggle_switch_form_test.rb @@ -5,14 +5,19 @@ class Primer::Forms::ToggleSwitchFormTest < Minitest::Test include Primer::ComponentTestHelpers - def test_it_renders_with_a_name - bogus_csrf = "let me in" - render_inline(ExampleToggleSwitchForm.new(csrf: bogus_csrf, src: "/toggle_switch")) + def test_it_renders + render_inline(ExampleToggleSwitchForm.new(src: "/toggle_switch")) - assert_selector "toggle-switch[src='/toggle_switch'][csrf='#{bogus_csrf}']" + assert_selector "toggle-switch[src='/toggle_switch']" assert_selector "em", text: "favorite" end + def test_accepts_custom_csrf_token + bogus_csrf = "let me in" + render_inline(ExampleToggleSwitchForm.new(csrf: bogus_csrf, src: "/toggle_switch")) + assert_selector "toggle-switch[data-csrf='#{bogus_csrf}']" + end + def test_can_render_without_subclass render_inline( Primer::Forms::ToggleSwitchForm.new(