Skip to content

Commit

Permalink
integration test for text filters
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Feb 28, 2024
1 parent 0ea071d commit 2abc26c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
19 changes: 16 additions & 3 deletions test/html_pipeline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
],
Expand All @@ -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 <marquee>yah</marquee>!"

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("<p>!&gt;eeuqram/eeuqram&lt; ees ot evoL .yllib@ ,ereht <strong>yeH</strong></p>", result)
end
end
11 changes: 8 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2abc26c

Please sign in to comment.