discourse/spec/helpers/embed_helper_spec.rb
Isaac Janzen b1f4499768
DEV: Extract embed post date title into i18n-aware helper (#38594)
Replaces the hardcoded `strftime` format in the embed comments view with
a helper method that uses the localized `datetime_formats.formats.long`
key.
2026-03-17 09:12:21 -05:00

33 lines
1.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe EmbedHelper do
describe "#embed_post_date_title" do
it "returns localized long format" do
date = Time.zone.local(2026, 5, 15, 14, 30)
expected_format = I18n.t("datetime_formats.formats.long")
expect(helper.embed_post_date_title(date)).to eq(date.strftime(expected_format))
end
end
describe "#embed_post_date" do
it "returns relative time for dates within the last day" do
freeze_time
expect(helper.embed_post_date(12.hours.ago)).to eq(
distance_of_time_in_words(12.hours.ago, Time.now),
)
end
it "returns localized format for dates in the current year" do
freeze_time DateTime.parse("2026-06-15")
date = 2.months.ago
expected_format = I18n.t("datetime_formats.formats.short_no_year")
expect(helper.embed_post_date(date)).to eq(date.strftime(expected_format))
end
it "returns localized format for dates in a previous year" do
date = 2.years.ago
expected_format = I18n.t("datetime_formats.formats.no_day")
expect(helper.embed_post_date(date)).to eq(date.strftime(expected_format))
end
end
end