2018-05-03 13:15:57 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-11-22 10:19:24 -06:00
|
|
|
def generate_html(text, opts = {})
|
2018-11-26 07:20:32 -06:00
|
|
|
output = "<p><span"
|
2018-11-22 10:19:24 -06:00
|
|
|
output += " data-date=\"#{opts[:date]}\"" if opts[:date]
|
|
|
|
output += " data-time=\"#{opts[:time]}\"" if opts[:time]
|
2018-11-26 07:20:32 -06:00
|
|
|
output += " class=\"discourse-local-date\""
|
2018-11-22 10:19:24 -06:00
|
|
|
output += " data-format=\"#{opts[:format]}\"" if opts[:format]
|
|
|
|
output += " data-email-preview=\"#{opts[:email_preview]}\"" if opts[:email_preview]
|
|
|
|
output += ">"
|
|
|
|
output += text
|
|
|
|
output + "</span></p>"
|
|
|
|
end
|
|
|
|
|
2018-05-03 13:15:57 -05:00
|
|
|
describe PrettyText do
|
2018-11-22 10:19:24 -06:00
|
|
|
before do
|
2018-05-18 08:35:37 -05:00
|
|
|
freeze_time
|
2018-11-22 10:19:24 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'emails simplified rendering' do
|
|
|
|
it 'works with default markup' do
|
|
|
|
cooked = PrettyText.cook("[date=2018-05-08]")
|
|
|
|
cooked_mail = generate_html("2018-05-08T00:00:00Z (Etc: UTC)",
|
|
|
|
date: "2018-05-08",
|
|
|
|
email_preview: "2018-05-08T00:00:00Z (Etc: UTC)"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with format' do
|
|
|
|
cooked = PrettyText.cook("[date=2018-05-08 format=LLLL]")
|
|
|
|
cooked_mail = generate_html("Tuesday, May 8, 2018 12:00 AM (Etc: UTC)",
|
|
|
|
date: "2018-05-08",
|
|
|
|
email_preview: "Tuesday, May 8, 2018 12:00 AM (Etc: UTC)",
|
|
|
|
format: "LLLL"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'works with time' do
|
|
|
|
cooked = PrettyText.cook("[date=2018-05-08 time=20:00:00]")
|
|
|
|
cooked_mail = generate_html("2018-05-08T20:00:00Z (Etc: UTC)",
|
|
|
|
date: "2018-05-08",
|
|
|
|
email_preview: "2018-05-08T20:00:00Z (Etc: UTC)",
|
|
|
|
time: "20:00:00"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
2018-05-18 08:35:37 -05:00
|
|
|
end
|
2018-05-03 13:15:57 -05:00
|
|
|
end
|