-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add docs and test for trix post processor
- Loading branch information
1 parent
c21e3cf
commit 51f3f13
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Frameworks.Pixel.TrixPostProcessorTest do | ||
use ExUnit.Case | ||
alias Frameworks.Pixel.TrixPostProcessor | ||
|
||
describe "add_target_blank/1" do | ||
test "adds target=_blank to <a> tags without target attribute" do | ||
html_content = "<a href=\"http://example.com\">Example</a>" | ||
expected = "<a href=\"http://example.com\" target=\"_blank\">Example</a>" | ||
assert TrixPostProcessor.add_target_blank(html_content) == expected | ||
end | ||
|
||
test "does not modify <a> tags with existing target attribute" do | ||
html_content = "<a href=\"http://example.com\" target=\"_self\">Example</a>" | ||
expected = "<a href=\"http://example.com\" target=\"_self\">Example</a>" | ||
assert TrixPostProcessor.add_target_blank(html_content) == expected | ||
end | ||
|
||
test "adds target=_blank to multiple <a> tags without target attribute" do | ||
html_content = | ||
"<a href=\"http://example1.com\">Example1</a> <a href=\"http://example2.com\">Example2</a>" | ||
|
||
expected = | ||
"<a href=\"http://example1.com\" target=\"_blank\">Example1</a> <a href=\"http://example2.com\" target=\"_blank\">Example2</a>" | ||
|
||
assert TrixPostProcessor.add_target_blank(html_content) == expected | ||
end | ||
|
||
test "handles nested <a> tags correctly" do | ||
html_content = "<div><a href=\"http://example.com\">Example</a></div>" | ||
expected = "<div><a href=\"http://example.com\" target=\"_blank\">Example</a></div>" | ||
assert TrixPostProcessor.add_target_blank(html_content) == expected | ||
end | ||
|
||
test "returns the same content if no <a> tags are present" do | ||
html_content = "<p>No links here</p>" | ||
expected = "<p>No links here</p>" | ||
assert TrixPostProcessor.add_target_blank(html_content) == expected | ||
end | ||
end | ||
end |