From 2abc26ccf4524f32ef1ec09a8bd6389daf3b8fb2 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Wed, 28 Feb 2024 17:26:14 -0500 Subject: [PATCH] integration test for text filters --- test/html_pipeline_test.rb | 19 ++++++++++++++++--- test/test_helper.rb | 11 ++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/test/html_pipeline_test.rb b/test/html_pipeline_test.rb index 792788fc..cdaf4b48 100644 --- a/test/html_pipeline_test.rb +++ b/test/html_pipeline_test.rb @@ -9,7 +9,7 @@ class HTMLPipelineTest < Minitest::Test def setup @default_context = {} - @pipeline = HTMLPipeline.new(text_filters: [TestTextFilter.new], default_context: @default_context) + @pipeline = HTMLPipeline.new(text_filters: [TestReverseFilter.new], default_context: @default_context) end def test_filter_instrumentation @@ -22,7 +22,7 @@ def test_filter_instrumentation assert(event, "event expected") assert_equal("call_filter.html_pipeline", event) - assert_equal(TestTextFilter.name, payload[:filter]) + assert_equal(TestReverseFilter.name, payload[:filter]) assert_equal(@pipeline.class.name, payload[:pipeline]) assert_equal(body.reverse, payload[:result][:output]) end @@ -89,7 +89,7 @@ def test_incorrect_convert_filter def test_convert_filter_needed_for_text_and_html_filters assert_raises(HTMLPipeline::InvalidFilterError) do HTMLPipeline.new( - text_filters: [TestTextFilter.new], + text_filters: [TestReverseFilter.new], node_filters: [ HTMLPipeline::NodeFilter::MentionFilter.new, ], @@ -103,4 +103,17 @@ def test_incorrect_node_filters HTMLPipeline.new(node_filters: [HTMLPipeline::ConvertFilter::MarkdownFilter], default_context: @default_context) end end + + def test_kitchen_sink + text = "Hey there, @billy. Love to see yah!" + + pipeline = HTMLPipeline.new( + text_filters: [TestReverseFilter.new, YehBolderFilter.new], + convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new, + node_filters: [HTMLPipeline::NodeFilter::MentionFilter.new], + ) + result = pipeline.call(text)[:output] + + assert_equal("

!>eeuqram/eeuqram< ees ot evoL .yllib@ ,ereht yeH

", result) + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bacb149..8c801f0d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,10 +16,15 @@ module TestHelpers Minitest::Test.include(TestHelpers) -class TestTextFilter < HTMLPipeline::TextFilter - # class << self +class TestReverseFilter < HTMLPipeline::TextFilter def call(input, context: {}, result: {}) input.reverse end - # end +end + +# bolds any instance of the word yeH +class YehBolderFilter < HTMLPipeline::TextFilter + def call(input, context: {}, result: {}) + input.gsub("yeH", "**yeH**") + end end