From 8da11d5af17c8cb3e7a7b84c2e3c5d6f71f73c39 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Tue, 23 Feb 2021 16:13:36 +0000 Subject: [PATCH 1/2] test(all): split up tests for clarity --- test/components/component_test.rb | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/test/components/component_test.rb b/test/components/component_test.rb index 18ff1a63e4..aa011746d5 100644 --- a/test/components/component_test.rb +++ b/test/components/component_test.rb @@ -61,28 +61,43 @@ def test_registered_components assert_equal primer_component_files_count, COMPONENTS_WITH_ARGS.length + ignored_components.count, "Primer component added. Please update this test with an entry for your new component <3" end - def test_primer_components_provide_a_consistent_interface + def test_all_components_support_system_arguments COMPONENTS_WITH_ARGS.each do |component, args, proc| - # component renders hash arguments render_component(component, { my: 4 }.merge(args), proc) assert_selector(".my-4") + end + end - # component passes through class_names + def test_all_components_pass_through_classes + COMPONENTS_WITH_ARGS.each do |component, args, proc| render_component(component, { classes: "foo" }.merge(args), proc) assert_selector(".foo") + end + end - # component supports inline styles + def test_all_components_support_inline_styles + COMPONENTS_WITH_ARGS.each do |component, args, proc| render_component(component, { style: "width: 100%;" }.merge(args), proc) assert_selector("[style='width: 100%;']") + end + end - # component supports basic content_tag arguments + def test_all_components_support_content_tag_arguments + COMPONENTS_WITH_ARGS.each do |component, args, proc| render_component(component, { hidden: true }.merge(args), proc) assert_selector("[hidden]", visible: false) + end + end + def test_all_components_support_data_tag_arguments + COMPONENTS_WITH_ARGS.each do |component, args, proc| render_component(component, { "data-ga-click": "Foo,bar" }.merge(args), proc) assert_selector("[data-ga-click='Foo,bar']", visible: false) + end + end - # Ensure all slots accept Primer system_arguments + def test_all_slots_support_system_arguments + COMPONENTS_WITH_ARGS.each do |component, args, proc| next unless component.respond_to?(:slots) && component.slots.any? result = render_inline(component.new(**args)) do |c| From 1e9ea798c63bdfcfe5c913b8b01f296817549612 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Tue, 23 Feb 2021 16:38:35 +0000 Subject: [PATCH 2/2] style: fix rubocop errors --- test/components/component_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/components/component_test.rb b/test/components/component_test.rb index aa011746d5..e8a07be86b 100644 --- a/test/components/component_test.rb +++ b/test/components/component_test.rb @@ -97,7 +97,7 @@ def test_all_components_support_data_tag_arguments end def test_all_slots_support_system_arguments - COMPONENTS_WITH_ARGS.each do |component, args, proc| + COMPONENTS_WITH_ARGS.each do |component, args| next unless component.respond_to?(:slots) && component.slots.any? result = render_inline(component.new(**args)) do |c|