2019-05-02 18:17:27 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2018-09-12 09:54:36 -04:00
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe "Local Dates" do
|
|
|
|
|
before do
|
2018-11-22 11:19:24 -05:00
|
|
|
|
freeze_time DateTime.parse('2018-11-10 12:00')
|
2018-09-12 09:54:36 -04:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-09 10:45:32 -04:00
|
|
|
|
it "should work without timezone" do
|
2018-11-22 11:19:24 -05:00
|
|
|
|
post = Fabricate(:post, raw: <<~TXT)
|
2018-10-09 10:45:32 -04:00
|
|
|
|
[date=2018-05-08 time=22:00 format="L LTS" timezones="Europe/Paris|America/Los_Angeles"]
|
2018-11-22 11:19:24 -05:00
|
|
|
|
TXT
|
2018-09-12 09:54:36 -04:00
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).to include('class="discourse-local-date"')
|
|
|
|
|
expect(cooked).to include('data-date="2018-05-08"')
|
|
|
|
|
expect(cooked).to include('data-format="L LTS"')
|
2018-10-15 19:34:55 -04:00
|
|
|
|
expect(cooked).not_to include('data-timezone=')
|
2018-09-12 09:54:36 -04:00
|
|
|
|
|
|
|
|
|
expect(cooked).to include(
|
|
|
|
|
'data-timezones="Europe/Paris|America/Los_Angeles"'
|
|
|
|
|
)
|
|
|
|
|
|
2019-01-16 06:53:41 -05:00
|
|
|
|
expect(cooked).to include('data-email-preview="2018-05-08T22:00:00Z UTC"')
|
2018-10-09 18:19:49 -04:00
|
|
|
|
expect(cooked).to include('05/08/2018 10:00:00 PM')
|
2018-09-12 09:54:36 -04:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-09 10:45:32 -04:00
|
|
|
|
it "should work with timezone" do
|
2018-11-22 11:19:24 -05:00
|
|
|
|
post = Fabricate(:post, raw: <<~TXT)
|
2018-10-09 10:45:32 -04:00
|
|
|
|
[date=2018-05-08 time=22:00 format="L LTS" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]
|
2018-11-22 11:19:24 -05:00
|
|
|
|
TXT
|
2018-10-09 10:45:32 -04:00
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
2018-10-15 19:34:55 -04:00
|
|
|
|
expect(cooked).to include('data-timezone="Asia/Calcutta"')
|
2018-10-09 18:19:49 -04:00
|
|
|
|
expect(cooked).to include('05/08/2018 4:30:00 PM')
|
2018-10-09 10:45:32 -04:00
|
|
|
|
end
|
|
|
|
|
|
2018-09-12 09:54:36 -04:00
|
|
|
|
it 'requires the right attributes to convert to a local date' do
|
2018-11-22 11:19:24 -05:00
|
|
|
|
post = Fabricate(:post, raw: <<~TXT)
|
2018-09-12 09:54:36 -04:00
|
|
|
|
[date]
|
2018-11-22 11:19:24 -05:00
|
|
|
|
TXT
|
2018-09-12 09:54:36 -04:00
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
|
|
|
|
expect(post.cooked).to include("<p>[date]</p>")
|
2018-10-09 10:45:32 -04:00
|
|
|
|
expect(cooked).to_not include('data-date=')
|
2018-09-12 09:54:36 -04:00
|
|
|
|
end
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
|
|
|
|
it 'requires the right attributes to convert to a local date' do
|
|
|
|
|
post = Fabricate(:post, raw: <<~TXT)
|
|
|
|
|
[date]
|
|
|
|
|
TXT
|
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
|
|
|
|
expect(post.cooked).to include("<p>[date]</p>")
|
|
|
|
|
expect(cooked).to_not include('data-date=')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'it works with only a date and time' do
|
|
|
|
|
raw = "[date=2018-11-01 time=12:00]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
expect(cooked).to include('data-date="2018-11-01"')
|
|
|
|
|
expect(cooked).to include('data-time="12:00"')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'doesn’t include format by default' do
|
|
|
|
|
raw = "[date=2018-11-01 time=12:00]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
expect(cooked).not_to include('data-format=')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'doesn’t include timezone by default' do
|
|
|
|
|
raw = "[date=2018-11-01 time=12:00]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).not_to include("data-timezone=")
|
|
|
|
|
end
|
2019-08-24 12:39:20 -04:00
|
|
|
|
|
|
|
|
|
it 'supports countdowns' do
|
|
|
|
|
raw = "[date=2018-11-01 time=12:00 countdown=true]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).to include("data-countdown=")
|
|
|
|
|
end
|
2018-09-12 09:54:36 -04:00
|
|
|
|
end
|