2019-05-03 06:17:27 +08:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2018-09-12 21:54:36 +08:00
|
|
|
|
RSpec.describe "Local Dates" do
|
2018-11-23 00:19:24 +08:00
|
|
|
|
before { freeze_time DateTime.parse("2018-11-10 12:00") }
|
2018-09-12 21:54:36 +08:00
|
|
|
|
|
2018-10-09 22:45:32 +08:00
|
|
|
|
it "should work without timezone" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
post = Fabricate(:post, raw: <<~MD)
|
2018-10-09 22:45:32 +08:00
|
|
|
|
[date=2018-05-08 time=22:00 format="L LTS" timezones="Europe/Paris|America/Los_Angeles"]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
MD
|
2018-09-12 21:54:36 +08: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-16 07:34:55 +08:00
|
|
|
|
expect(cooked).not_to include("data-timezone=")
|
2018-09-12 21:54:36 +08:00
|
|
|
|
|
|
|
|
|
expect(cooked).to include('data-timezones="Europe/Paris|America/Los_Angeles"')
|
|
|
|
|
|
2019-01-16 19:53:41 +08:00
|
|
|
|
expect(cooked).to include('data-email-preview="2018-05-08T22:00:00Z UTC"')
|
2018-10-10 06:19:49 +08:00
|
|
|
|
expect(cooked).to include("05/08/2018 10:00:00 PM")
|
2018-09-12 21:54:36 +08:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-09 22:45:32 +08:00
|
|
|
|
it "should work with timezone" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
post = Fabricate(:post, raw: <<~MD)
|
2018-10-09 22:45:32 +08:00
|
|
|
|
[date=2018-05-08 time=22:00 format="L LTS" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
MD
|
2018-10-09 22:45:32 +08:00
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
2018-10-16 07:34:55 +08:00
|
|
|
|
expect(cooked).to include('data-timezone="Asia/Calcutta"')
|
2018-10-10 06:19:49 +08:00
|
|
|
|
expect(cooked).to include("05/08/2018 4:30:00 PM")
|
2024-03-20 08:28:45 +08:00
|
|
|
|
|
|
|
|
|
post = Fabricate(:post, raw: <<~MD)
|
|
|
|
|
[date=2018-05-08 time=22:00 format="L LTS" timezone="IST"]
|
|
|
|
|
MD
|
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).to include('data-timezone="IST"')
|
|
|
|
|
expect(cooked).to include("05/08/2018 4:30:00 PM")
|
2018-10-09 22:45:32 +08:00
|
|
|
|
end
|
|
|
|
|
|
2018-09-12 21:54:36 +08:00
|
|
|
|
it "requires the right attributes to convert to a local date" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
post = Fabricate(:post, raw: <<~MD)
|
2018-09-12 21:54:36 +08:00
|
|
|
|
[date]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
MD
|
2018-09-12 21:54:36 +08:00
|
|
|
|
|
|
|
|
|
cooked = post.cooked
|
|
|
|
|
|
|
|
|
|
expect(post.cooked).to include("<p>[date]</p>")
|
2018-10-09 22:45:32 +08:00
|
|
|
|
expect(cooked).to_not include("data-date=")
|
2018-09-12 21:54:36 +08:00
|
|
|
|
end
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
|
|
|
|
it "requires the right attributes to convert to a local date" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
post = Fabricate(:post, raw: <<~MD)
|
2018-11-23 00:19:24 +08:00
|
|
|
|
[date]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
|
MD
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
|
|
|
|
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-25 00:39:20 +08: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
|
2022-01-10 15:02:36 +08:00
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
|
describe "ranges" do
|
2022-01-10 15:02:36 +08:00
|
|
|
|
it "generates ranges without time" do
|
|
|
|
|
raw = "[date-range from=2022-01-06 to=2022-01-08]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).to include('data-date="2022-01-06')
|
2022-10-07 09:39:41 +08:00
|
|
|
|
expect(cooked).to include('data-range="from"')
|
|
|
|
|
expect(cooked).to include('data-range="to"')
|
2022-01-10 15:02:36 +08:00
|
|
|
|
expect(cooked).not_to include("data-time=")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "supports time and timezone" do
|
|
|
|
|
raw = "[date-range from=2022-01-06T13:00 to=2022-01-08 timezone=Australia/Sydney]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).to include('data-date="2022-01-06')
|
2022-10-07 09:39:41 +08:00
|
|
|
|
expect(cooked).to include('data-range="to"')
|
|
|
|
|
expect(cooked).to include('data-range="from"')
|
2022-01-10 15:02:36 +08:00
|
|
|
|
expect(cooked).to include('data-time="13:00"')
|
|
|
|
|
expect(cooked).to include('data-timezone="Australia/Sydney"')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "generates single date when range without end date" do
|
|
|
|
|
raw = "[date-range from=2022-01-06T13:00]"
|
|
|
|
|
cooked = Fabricate(:post, raw: raw).cooked
|
|
|
|
|
|
|
|
|
|
expect(cooked).to include('data-date="2022-01-06')
|
|
|
|
|
expect(cooked).to include('data-time="13:00"')
|
2022-10-07 09:39:41 +08:00
|
|
|
|
expect(cooked).not_to include('data-range="to"')
|
2022-01-10 15:02:36 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-09-12 21:54:36 +08:00
|
|
|
|
end
|