2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-03 14:15:57 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-11-22 11:19:24 -05:00
|
|
|
def generate_html(text, opts = {})
|
2018-11-26 08:20:32 -05:00
|
|
|
output = "<p><span"
|
2018-11-22 11:19:24 -05:00
|
|
|
output += " data-date=\"#{opts[:date]}\"" if opts[:date]
|
|
|
|
output += " data-time=\"#{opts[:time]}\"" if opts[:time]
|
2018-11-26 08:20:32 -05:00
|
|
|
output += " class=\"discourse-local-date\""
|
2019-01-16 06:53:41 -05:00
|
|
|
output += " data-timezones=\"#{opts[:timezones]}\"" if opts[:timezones]
|
|
|
|
output += " data-timezone=\"#{opts[:timezone]}\"" if opts[:timezone]
|
2018-11-22 11:19:24 -05: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 14:15:57 -04:00
|
|
|
describe PrettyText do
|
2018-11-22 11:19:24 -05:00
|
|
|
before do
|
2018-05-18 09:35:37 -04:00
|
|
|
freeze_time
|
2018-11-22 11:19:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'emails simplified rendering' do
|
|
|
|
it 'works with default markup' do
|
|
|
|
cooked = PrettyText.cook("[date=2018-05-08]")
|
2019-01-16 06:53:41 -05:00
|
|
|
cooked_mail = generate_html("2018-05-08T00:00:00Z UTC",
|
2018-11-22 11:19:24 -05:00
|
|
|
date: "2018-05-08",
|
2019-01-16 06:53:41 -05:00
|
|
|
email_preview: "2018-05-08T00:00:00Z UTC"
|
2018-11-22 11:19:24 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
|
|
|
|
2019-01-16 06:53:41 -05:00
|
|
|
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 UTC",
|
2018-11-22 11:19:24 -05:00
|
|
|
date: "2018-05-08",
|
2019-01-16 06:53:41 -05:00
|
|
|
email_preview: "2018-05-08T20:00:00Z UTC",
|
|
|
|
time: "20:00:00"
|
2018-11-22 11:19:24 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
|
|
|
|
2019-01-16 06:53:41 -05:00
|
|
|
it 'works with multiple timezones' do
|
|
|
|
cooked = PrettyText.cook('[date=2018-05-08 timezone="Europe/Paris" timezones="America/Los_Angeles|Pacific/Auckland"]')
|
|
|
|
cooked_mail = generate_html("2018-05-07T22:00:00Z UTC",
|
2018-11-22 11:19:24 -05:00
|
|
|
date: "2018-05-08",
|
2019-01-16 06:53:41 -05:00
|
|
|
email_preview: "2018-05-07T22:00:00Z UTC",
|
|
|
|
timezone: "Europe/Paris",
|
|
|
|
timezones: "America/Los_Angeles|Pacific/Auckland"
|
2018-11-22 11:19:24 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
2019-01-16 06:53:41 -05:00
|
|
|
|
|
|
|
describe 'discourse_local_dates_email_format' do
|
|
|
|
before do
|
|
|
|
SiteSetting.discourse_local_dates_email_format = "DD/MM"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the site setting' do
|
|
|
|
cooked = PrettyText.cook("[date=2018-05-08]")
|
|
|
|
cooked_mail = generate_html("08/05 UTC",
|
|
|
|
date: "2018-05-08",
|
|
|
|
email_preview: "08/05 UTC"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
|
|
|
end
|
|
|
|
end
|
2018-05-18 09:35:37 -04:00
|
|
|
end
|
2019-10-17 10:18:06 -04:00
|
|
|
|
|
|
|
context 'excerpt simplified rendering' do
|
|
|
|
let(:post) { Fabricate(:post, raw: '[date=2019-10-16 time=14:00:00 format="LLLL" timezone="America/New_York"]') }
|
|
|
|
|
|
|
|
it 'adds UTC' do
|
|
|
|
excerpt = PrettyText.excerpt(post.cooked, 200)
|
|
|
|
expect(excerpt).to eq("Wednesday, October 16, 2019 6:00 PM (UTC)")
|
|
|
|
end
|
|
|
|
end
|
2019-11-21 05:43:35 -05:00
|
|
|
|
|
|
|
context 'german quotes' do
|
|
|
|
let(:post) { Fabricate(:post, raw: '[date=2019-10-16 time=14:00:00 format="LLLL" timezone=„America/New_York“]') }
|
|
|
|
|
|
|
|
it 'converts german quotes to regular quotes' do
|
|
|
|
excerpt = PrettyText.excerpt(post.cooked, 200)
|
|
|
|
expect(excerpt).to eq('Wednesday, October 16, 2019 6:00 PM (UTC)')
|
|
|
|
end
|
|
|
|
end
|
2018-05-03 14:15:57 -04:00
|
|
|
end
|