mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 10:54:50 +08:00
test format_notifications
This commit is contained in:
@ -16,6 +16,14 @@ describe Email::Styles do
|
|||||||
Nokogiri::HTML(styler.to_html)
|
Nokogiri::HTML(styler.to_html)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notification_doc(html)
|
||||||
|
styler = Email::Styles.new(html)
|
||||||
|
styler.format_basic
|
||||||
|
styler.format_notification
|
||||||
|
styler.format_html
|
||||||
|
Nokogiri::HTML(styler.to_html)
|
||||||
|
end
|
||||||
|
|
||||||
context "basic formatter" do
|
context "basic formatter" do
|
||||||
|
|
||||||
it "works with an empty string" do
|
it "works with an empty string" do
|
||||||
@ -24,12 +32,16 @@ describe Email::Styles do
|
|||||||
expect(style.to_html).to be_blank
|
expect(style.to_html).to be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
# Pending due to email effort @coding-horror made in d2fb2bc4c
|
it "adds a max-width to big images" do
|
||||||
skip "adds a max-width to images" do
|
doc = basic_doc("<img src='gigantic.jpg' width='1230' height='720'>")
|
||||||
doc = basic_doc("<img src='gigantic.jpg'>")
|
|
||||||
expect(doc.at("img")["style"]).to match("max-width")
|
expect(doc.at("img")["style"]).to match("max-width")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn't add a maz-width to small images" do
|
||||||
|
doc = basic_doc("<img src='gigantic.jpg' width='120' height='80'>")
|
||||||
|
expect(doc.at("img")["style"]).not_to match("max-width")
|
||||||
|
end
|
||||||
|
|
||||||
it "adds a width and height to images with an emoji path" do
|
it "adds a width and height to images with an emoji path" do
|
||||||
doc = basic_doc("<img src='/images/emoji/fish.png' class='emoji'>")
|
doc = basic_doc("<img src='/images/emoji/fish.png' class='emoji'>")
|
||||||
expect(doc.at("img")["width"]).to eq("20")
|
expect(doc.at("img")["width"]).to eq("20")
|
||||||
@ -97,6 +109,19 @@ describe Email::Styles do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "format notifications" do
|
||||||
|
it "adds both styles and attributes" do
|
||||||
|
doc = notification_doc("<table><tr><td class='body'>hello</td></tr></table>")
|
||||||
|
expect(doc.at('td')['style']).to eq('padding-top:5px;')
|
||||||
|
expect(doc.at('td')['colspan']).to eq('2')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "adds attributes when no styles are present" do
|
||||||
|
doc = notification_doc("<div class='user-avatar'><img src='/some-image.png'></div>")
|
||||||
|
expect(doc.at('img')['width']).to eq('45')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "rewriting protocol relative URLs to the forum" do
|
context "rewriting protocol relative URLs to the forum" do
|
||||||
it "doesn't rewrite a url to another site" do
|
it "doesn't rewrite a url to another site" do
|
||||||
doc = html_doc('<a href="//youtube.com/discourse">hello</a>')
|
doc = html_doc('<a href="//youtube.com/discourse">hello</a>')
|
||||||
@ -163,5 +188,4 @@ describe Email::Styles do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user