From ba2c7b8f3508fbb6d55e9618c32859999063c499 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 20 Jun 2022 15:42:10 +0200 Subject: [PATCH] DEV: Use the block form of `module()` (#17151) --- .../discourse/tests/unit/models/theme-test.js | 34 +- .../javascripts/lib/details-cooked-test.js | 36 +- .../lib/date-with-zone-helper-test.js | 298 ++--- .../lib/local-date-builder-test.js | 1054 ++++++++--------- 4 files changed, 713 insertions(+), 709 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/unit/models/theme-test.js b/app/assets/javascripts/discourse/tests/unit/models/theme-test.js index 1d3f2e49fcf..c01ecd59db5 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/theme-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/theme-test.js @@ -1,22 +1,26 @@ import { module, test } from "qunit"; import Theme from "admin/models/theme"; -module("Unit | Model | theme"); +module("Unit | Model | theme", function () { + test("can add an upload correctly", function (assert) { + let theme = Theme.create(); -test("can add an upload correctly", function (assert) { - let theme = Theme.create(); + assert.strictEqual( + theme.get("uploads.length"), + 0, + "uploads should be an empty array" + ); - assert.strictEqual( - theme.get("uploads.length"), - 0, - "uploads should be an empty array" - ); + theme.setField("common", "bob", "", 999, 2); + let fields = theme.get("theme_fields"); + assert.strictEqual(fields.length, 1, "expecting 1 theme field"); + assert.strictEqual( + fields[0].upload_id, + 999, + "expecting upload id to be set" + ); + assert.strictEqual(fields[0].type_id, 2, "expecting type id to be set"); - theme.setField("common", "bob", "", 999, 2); - let fields = theme.get("theme_fields"); - assert.strictEqual(fields.length, 1, "expecting 1 theme field"); - assert.strictEqual(fields[0].upload_id, 999, "expecting upload id to be set"); - assert.strictEqual(fields[0].type_id, 2, "expecting type id to be set"); - - assert.strictEqual(theme.get("uploads.length"), 1, "expecting an upload"); + assert.strictEqual(theme.get("uploads.length"), 1, "expecting an upload"); + }); }); diff --git a/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js b/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js index d8a9ff3687c..a436ce76df2 100644 --- a/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js +++ b/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js @@ -1,8 +1,6 @@ import PrettyText, { buildOptions } from "pretty-text/pretty-text"; import { module, test } from "qunit"; -module("lib:details-cooked-test"); - const defaultOpts = buildOptions({ siteSettings: { enable_emoji: true, @@ -14,26 +12,28 @@ const defaultOpts = buildOptions({ getURL: (url) => url, }); -test("details", function (assert) { - const cooked = (input, expected, text) => { - assert.strictEqual( - new PrettyText(defaultOpts).cook(input), - expected.replace(/\/>/g, ">"), - text +module("lib:details-cooked-test", function () { + test("details", function (assert) { + const cooked = (input, expected, text) => { + assert.strictEqual( + new PrettyText(defaultOpts).cook(input), + expected.replace(/\/>/g, ">"), + text + ); + }; + cooked( + `
Infocoucou
`, + `
Infocoucou
`, + "manual HTML for details" ); - }; - cooked( - `
Infocoucou
`, - `
Infocoucou
`, - "manual HTML for details" - ); - cooked( - "[details=testing]\ntest\n[/details]", - `
+ cooked( + "[details=testing]\ntest\n[/details]", + `
testing

test

` - ); + ); + }); }); diff --git a/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js b/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js index 7257cd88627..39f44834865 100644 --- a/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js +++ b/plugins/discourse-local-dates/test/javascripts/lib/date-with-zone-helper-test.js @@ -4,8 +4,6 @@ import { module, test } from "qunit"; const PARIS = "Europe/Paris"; const SYDNEY = "Australia/Sydney"; -module("lib:date-with-zone-helper"); - function buildDateHelper(params = {}) { return new DateWithZoneHelper({ year: params.year || 2020, @@ -18,152 +16,154 @@ function buildDateHelper(params = {}) { }); } -test("#format", function (assert) { - let date = buildDateHelper({ - day: 15, - month: 2, - hour: 15, - minute: 36, - timezone: PARIS, +module("lib:date-with-zone-helper", function () { + test("#format", function (assert) { + let date = buildDateHelper({ + day: 15, + month: 2, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.strictEqual(date.format(), "2020-03-15T15:36:00.000+01:00"); + }); + + test("#unitRepetitionsBetweenDates", function (assert) { + let date; + + date = buildDateHelper({ + day: 15, + month: 1, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.strictEqual( + date.unitRepetitionsBetweenDates( + "1.hour", + moment.tz("2020-02-15 15:36", SYDNEY) + ), + 10, + "it correctly finds difference between timezones" + ); + + date = buildDateHelper({ + day: 15, + month: 1, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.strictEqual( + date.unitRepetitionsBetweenDates( + "1.minute", + moment.tz("2020-02-15 15:36", PARIS) + ), + 0, + "it correctly finds no difference" + ); + + date = buildDateHelper({ + day: 15, + month: 1, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.strictEqual( + date.unitRepetitionsBetweenDates( + "1.minute", + moment.tz("2020-02-15 15:37", PARIS) + ), + 1, + "it correctly finds no difference" + ); + + date = buildDateHelper({ + day: 15, + month: 1, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.strictEqual( + date.unitRepetitionsBetweenDates( + "2.minutes", + moment.tz("2020-02-15 15:41", PARIS) + ), + 6, + "it correctly finds difference with a multiplicator" + ); + }); + + test("#add", function (assert) { + let date; + let futureLocalDate; + + date = buildDateHelper({ + day: 19, + month: 2, + hour: 15, + minute: 36, + timezone: PARIS, + }); + + assert.notOk(date.isDST()); + futureLocalDate = date.add(8, "months"); + assert.notOk(futureLocalDate.isDST()); + assert.strictEqual( + futureLocalDate.format(), + "2020-11-19T15:36:00.000+01:00", + "it correctly adds from a !isDST date to a !isDST date" + ); + + date = buildDateHelper({ + day: 25, + month: 3, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.ok(date.isDST()); + futureLocalDate = date.add(1, "year"); + assert.ok(futureLocalDate.isDST()); + assert.strictEqual( + futureLocalDate.format(), + "2021-04-25T15:36:00.000+02:00", + "it correctly adds from a isDST date to a isDST date" + ); + + date = buildDateHelper({ + day: 25, + month: 2, + hour: 15, + minute: 36, + timezone: PARIS, + }); + assert.notOk(date.isDST()); + futureLocalDate = date.add(1, "week"); + assert.ok(futureLocalDate.isDST()); + assert.strictEqual( + futureLocalDate.format(), + "2020-04-01T15:36:00.000+02:00", + "it correctly adds from a !isDST date to a isDST date" + ); + + date = buildDateHelper({ + day: 1, + month: 3, + hour: 15, + minute: 36, + timezone: PARIS, + }); + + assert.ok(date.isDST()); + futureLocalDate = date.add(8, "months"); + assert.notOk(futureLocalDate.isDST()); + assert.strictEqual( + futureLocalDate.format(), + "2020-12-01T15:36:00.000+01:00", + "it correctly adds from a isDST date to a !isDST date" + ); }); - assert.strictEqual(date.format(), "2020-03-15T15:36:00.000+01:00"); -}); - -test("#unitRepetitionsBetweenDates", function (assert) { - let date; - - date = buildDateHelper({ - day: 15, - month: 1, - hour: 15, - minute: 36, - timezone: PARIS, - }); - assert.strictEqual( - date.unitRepetitionsBetweenDates( - "1.hour", - moment.tz("2020-02-15 15:36", SYDNEY) - ), - 10, - "it correctly finds difference between timezones" - ); - - date = buildDateHelper({ - day: 15, - month: 1, - hour: 15, - minute: 36, - timezone: PARIS, - }); - assert.strictEqual( - date.unitRepetitionsBetweenDates( - "1.minute", - moment.tz("2020-02-15 15:36", PARIS) - ), - 0, - "it correctly finds no difference" - ); - - date = buildDateHelper({ - day: 15, - month: 1, - hour: 15, - minute: 36, - timezone: PARIS, - }); - assert.strictEqual( - date.unitRepetitionsBetweenDates( - "1.minute", - moment.tz("2020-02-15 15:37", PARIS) - ), - 1, - "it correctly finds no difference" - ); - - date = buildDateHelper({ - day: 15, - month: 1, - hour: 15, - minute: 36, - timezone: PARIS, - }); - assert.strictEqual( - date.unitRepetitionsBetweenDates( - "2.minutes", - moment.tz("2020-02-15 15:41", PARIS) - ), - 6, - "it correctly finds difference with a multiplicator" - ); -}); - -test("#add", function (assert) { - let date; - let futureLocalDate; - - date = buildDateHelper({ - day: 19, - month: 2, - hour: 15, - minute: 36, - timezone: PARIS, - }); - - assert.notOk(date.isDST()); - futureLocalDate = date.add(8, "months"); - assert.notOk(futureLocalDate.isDST()); - assert.strictEqual( - futureLocalDate.format(), - "2020-11-19T15:36:00.000+01:00", - "it correctly adds from a !isDST date to a !isDST date" - ); - - date = buildDateHelper({ - day: 25, - month: 3, - hour: 15, - minute: 36, - timezone: PARIS, - }); - assert.ok(date.isDST()); - futureLocalDate = date.add(1, "year"); - assert.ok(futureLocalDate.isDST()); - assert.strictEqual( - futureLocalDate.format(), - "2021-04-25T15:36:00.000+02:00", - "it correctly adds from a isDST date to a isDST date" - ); - - date = buildDateHelper({ - day: 25, - month: 2, - hour: 15, - minute: 36, - timezone: PARIS, - }); - assert.notOk(date.isDST()); - futureLocalDate = date.add(1, "week"); - assert.ok(futureLocalDate.isDST()); - assert.strictEqual( - futureLocalDate.format(), - "2020-04-01T15:36:00.000+02:00", - "it correctly adds from a !isDST date to a isDST date" - ); - - date = buildDateHelper({ - day: 1, - month: 3, - hour: 15, - minute: 36, - timezone: PARIS, - }); - - assert.ok(date.isDST()); - futureLocalDate = date.add(8, "months"); - assert.notOk(futureLocalDate.isDST()); - assert.strictEqual( - futureLocalDate.format(), - "2020-12-01T15:36:00.000+01:00", - "it correctly adds from a isDST date to a !isDST date" - ); }); diff --git a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js index 86414743b20..a95bb74fa5a 100644 --- a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js +++ b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js @@ -11,8 +11,6 @@ const PARIS = "Europe/Paris"; const LAGOS = "Africa/Lagos"; const LONDON = "Europe/London"; -module("lib:local-date-builder"); - function freezeTime({ date, timezone }, cb) { date = date || "2020-01-22 10:34"; const newTimezone = timezone || PARIS; @@ -50,7 +48,7 @@ QUnit.assert.buildsCorrectDate = function (options, expected, message) { this.test.assert.strictEqual( localDateBuilder.build().formated, expected.formated, - message || "it formates the date correctly" + message || "it formats the date correctly" ); } @@ -58,535 +56,537 @@ QUnit.assert.buildsCorrectDate = function (options, expected, message) { this.test.assert.deepEqual( localDateBuilder.build().previews, expected.previews, - message || "it formates the previews correctly" + message || "it formats the previews correctly" ); } }; -test("date", function (assert) { - freezeTime({ date: "2020-03-11" }, () => { +module("lib:local-date-builder", function () { + test("date", function (assert) { + freezeTime({ date: "2020-03-11" }, () => { + assert.buildsCorrectDate( + { date: "2020-03-22", timezone: PARIS }, + { formated: "March 22, 2020" }, + "it displays the date without time" + ); + }); + }); + + test("date and time", function (assert) { assert.buildsCorrectDate( - { date: "2020-03-22", timezone: PARIS }, - { formated: "March 22, 2020" }, - "it displays the date without time" - ); - }); -}); - -test("date and time", function (assert) { - assert.buildsCorrectDate( - { date: "2020-04-11", time: "11:00" }, - { formated: "April 11, 2020 1:00 PM" }, - "it displays the date with time" - ); - - assert.buildsCorrectDate( - { date: "2020-04-11", time: "11:05:12", format: "LTS" }, - { formated: "1:05:12 PM" }, - "it displays full time (hours, minutes, seconds)" - ); -}); - -test("option[format]", function (assert) { - freezeTime({ date: "2020-03-11" }, () => { - assert.buildsCorrectDate( - { format: "YYYY" }, - { formated: "2020 (UTC)" }, - "it uses custom format" - ); - }); -}); - -test("option[displayedTimezone]", function (assert) { - freezeTime({}, () => { - assert.buildsCorrectDate( - { displayedTimezone: SYDNEY }, - { formated: "March 22, 2020 (Sydney)" }, - "it displays the timezone if the timezone is different from the date" - ); - }); - - freezeTime({}, () => { - assert.buildsCorrectDate( - { displayedTimezone: PARIS, timezone: PARIS }, - { formated: "March 22, 2020" }, - "it doesn't display the timezone if the timezone is the same than the date" - ); - }); - - freezeTime({}, () => { - assert.buildsCorrectDate( - { timezone: UTC, displayedTimezone: UTC }, - { formated: "March 22, 2020 (UTC)" }, - "it replaces `Etc/`" - ); - }); - - freezeTime({}, () => { - assert.buildsCorrectDate( - { timezone: LOS_ANGELES, displayedTimezone: LOS_ANGELES }, - { formated: "March 22, 2020 (Los Angeles)" }, - "it removes prefix and replaces `_`" - ); - }); -}); - -test("option[timezone]", function (assert) { - freezeTime({}, () => { - assert.buildsCorrectDate( - { timezone: SYDNEY, displayedTimezone: PARIS }, - { formated: "March 21, 2020" }, - "it correctly parses a date with the given timezone context" - ); - }); -}); - -test("option[recurring]", function (assert) { - freezeTime({ date: "2020-04-06 06:00", timezone: LAGOS }, () => { - assert.buildsCorrectDate( - { - date: "2019-11-25", - time: "11:00", - timezone: PARIS, - displayedTimezone: LAGOS, - recurring: "1.weeks", - }, - { - formated: "April 6, 2020 10:00 AM (Lagos)", - }, - "it correctly formats a recurring date starting from a !isDST timezone to a isDST timezone date when displayed to a user using a timezone with no DST" - ); - }); - - freezeTime({ date: "2020-04-06 01:00", timezone: SYDNEY }, () => { - assert.buildsCorrectDate( - { - date: "2020-03-09", - time: "02:00", - timezone: UTC, - recurring: "1.weeks", - calendar: false, - displayedTimezone: SYDNEY, - }, - { - formated: "April 6, 2020 12:00 PM (Sydney)", - }, - "it correctly formats a recurring date spanning over weeks" - ); - }); - - freezeTime({ date: "2020-04-07 22:00" }, () => { - assert.buildsCorrectDate( - { - date: "2019-11-25", - time: "11:00", - recurring: "1.weeks", - timezone: PARIS, - }, - { - formated: "April 13, 2020 11:00 AM", - }, - "it correctly adds from a !isDST date to a isDST date" - ); - }); - - freezeTime({ date: "2020-04-06 10:59" }, () => { - assert.buildsCorrectDate( - { - date: "2020-03-30", - time: "11:00", - recurring: "1.weeks", - timezone: PARIS, - }, - { - formated: "Today 11:00 AM", - }, - "it works to the minute" - ); - }); - - freezeTime({ date: "2020-04-06 11:01" }, () => { - assert.buildsCorrectDate( - { - date: "2020-03-30", - time: "11:00", - recurring: "1.weeks", - timezone: PARIS, - }, - { - formated: "April 13, 2020 11:00 AM", - }, - "it works to the minute" - ); - }); - - freezeTime({ date: "2020-12-28 09:16" }, () => { - assert.buildsCorrectDate( - { - date: "2021-01-24", - time: "08:30", - recurring: "1.weeks", - timezone: NEW_YORK, - }, - { - formated: "January 24, 2021 2:30 PM", - }, - "it works for a future date" - ); - }); - - freezeTime({ date: "2021-01-08 11:16" }, () => { - assert.buildsCorrectDate( - { - date: "2021-01-05", - time: "14:00", - recurring: "2.hours", - timezone: NEW_YORK, - }, - { - formated: "Today 12:00 PM", - }, - "it works with hours" - ); - }); -}); - -test("option[countown]", function (assert) { - freezeTime({ date: "2020-03-21 23:59" }, () => { - assert.buildsCorrectDate( - { - countdown: true, - timezone: PARIS, - }, - { formated: "a minute" }, - "it shows the time remaining" - ); - }); - - freezeTime({ date: "2020-03-22 00:01" }, () => { - assert.buildsCorrectDate( - { - countdown: true, - timezone: PARIS, - }, - { - formated: I18n.t( - "discourse_local_dates.relative_dates.countdown.passed" - ), - }, - "it shows the date has passed" - ); - }); -}); - -test("option[calendar]", function (assert) { - freezeTime({ date: "2020-03-23 23:00" }, () => { - assert.buildsCorrectDate( - { date: "2020-03-22", time: "23:59", timezone: PARIS }, - { formated: "Yesterday 11:59 PM" }, - "it drops calendar mode when event date is more than one day before current date" - ); - }); - - freezeTime({ date: "2020-03-20 23:59" }, () => - assert.buildsCorrectDate( - { date: "2020-03-21", time: "01:00", timezone: PARIS }, - { formated: "Tomorrow 1:00 AM" } - ) - ); - - freezeTime({ date: "2020-03-20 23:59" }, () => - assert.buildsCorrectDate( - { date: "2020-03-21", time: "00:00", timezone: PARIS }, - { formated: "Saturday" }, - "it displays the day with no time when the time in the displayed timezone is 00:00" - ) - ); - - freezeTime({ date: "2020-03-20 23:59" }, () => { - assert.buildsCorrectDate( - { date: "2020-03-21", time: "23:59", timezone: PARIS }, - { formated: "Tomorrow 11:59 PM" } - ); - }); - - freezeTime({ date: "2020-03-21 00:00" }, () => - assert.buildsCorrectDate( - { date: "2020-03-21", time: "23:00", timezone: PARIS }, - { formated: "Today 11:00 PM" } - ) - ); - - freezeTime({ date: "2020-03-22 23:59" }, () => - assert.buildsCorrectDate( - { date: "2020-03-21", time: "23:59", timezone: PARIS }, - { formated: "Yesterday 11:59 PM" } - ) - ); - - freezeTime({ date: "2020-03-22 23:59" }, () => - assert.buildsCorrectDate( - { date: "2020-03-21", time: "23:59", timezone: PARIS }, - { formated: "Yesterday 11:59 PM" } - ) - ); - - freezeTime({ date: "2020-03-22 23:59" }, () => - assert.buildsCorrectDate( - { calendar: false, date: "2020-03-21", time: "23:59", timezone: PARIS }, - { formated: "March 21, 2020 11:59 PM" }, - "it doesn't use calendar when disabled" - ) - ); - - freezeTime({ date: "2020-03-24 01:00" }, () => - assert.buildsCorrectDate( - { date: "2020-03-21", timezone: PARIS }, - { formated: "March 21, 2020" }, - "it stops formating out of calendar range" - ) - ); - - freezeTime({ date: "2020-05-12", timezone: LOS_ANGELES }, () => { - assert.buildsCorrectDate( - { - date: "2020-05-13", - time: "18:00", - localTimezone: LOS_ANGELES, - }, - { formated: "Tomorrow 11:00 AM" }, - "it correctly displays a different local timezone" - ); - }); -}); - -test("previews", function (assert) { - freezeTime({ date: "2020-03-22" }, () => { - assert.buildsCorrectDate( - { timezone: PARIS }, - { - previews: [ - { - current: true, - formated: - "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { timezone: PARIS, timezones: [SYDNEY] }, - { - previews: [ - { - current: true, - formated: - "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", - timezone: "Paris", - }, - { - formated: - "Sunday, March 22, 2020 10:00 AM → Monday, March 23, 2020 10:00 AM", - timezone: "Sydney", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { timezone: PARIS, displayedTimezone: LOS_ANGELES }, - { - previews: [ - { - current: true, - formated: - "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { timezone: PARIS, isplayedTimezone: PARIS }, - { - previews: [ - { - current: true, - formated: - "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { timezone: PARIS, timezones: [PARIS] }, - { - previews: [ - { - current: true, - formated: - "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { duration: 90, timezone: PARIS, timezones: [PARIS] }, - { - previews: [ - { - current: true, - formated: - 'Sunday, March 22, 2020
12:00 AM → 1:30 AM', - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { duration: 1440, timezone: PARIS, timezones: [PARIS] }, - { - previews: [ - { - current: true, - formated: - "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { time: "11:34", timezone: PARIS, timezones: [PARIS] }, - { - previews: [ - { - current: true, - formated: - 'Sunday, March 22, 2020
11:34 AM', - timezone: "Paris", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-04-06", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { - timezone: PARIS, - date: "2020-04-07", - timezones: [LONDON, LAGOS, SYDNEY], - }, - { - previews: [ - { - current: true, - formated: - "Tuesday, April 7, 2020 12:00 AM → Wednesday, April 8, 2020 12:00 AM", - timezone: "Paris", - }, - { - formated: - "Monday, April 6, 2020 11:00 PM → Tuesday, April 7, 2020 11:00 PM", - timezone: "London", - }, - { - formated: - "Monday, April 6, 2020 11:00 PM → Tuesday, April 7, 2020 11:00 PM", - timezone: "Lagos", - }, - { - formated: - "Tuesday, April 7, 2020 8:00 AM → Wednesday, April 8, 2020 8:00 AM", - timezone: "Sydney", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-04-06", timezone: PARIS }, () => { - assert.buildsCorrectDate( - { - timezone: PARIS, - date: "2020-04-07", - time: "14:54", - timezones: [LONDON, LAGOS, SYDNEY], - }, - { - previews: [ - { - current: true, - formated: - 'Tuesday, April 7, 2020
2:54 PM', - timezone: "Paris", - }, - { - formated: - 'Tuesday, April 7, 2020
1:54 PM', - timezone: "London", - }, - { - formated: - 'Tuesday, April 7, 2020
1:54 PM', - timezone: "Lagos", - }, - { - formated: - 'Tuesday, April 7, 2020
10:54 PM', - timezone: "Sydney", - }, - ], - } - ); - }); - - freezeTime({ date: "2020-05-12", timezone: LOS_ANGELES }, () => { - assert.buildsCorrectDate( - { - date: "2020-05-13", - time: "18:00", - localTimezone: LOS_ANGELES, - }, - { - previews: [ - { - current: true, - formated: - 'Wednesday, May 13, 2020
11:00 AM', - timezone: "Los Angeles", - }, - { - formated: - 'Wednesday, May 13, 2020
6:00 PM', - timezone: "UTC", - }, - ], - } + { date: "2020-04-11", time: "11:00" }, + { formated: "April 11, 2020 1:00 PM" }, + "it displays the date with time" ); + + assert.buildsCorrectDate( + { date: "2020-04-11", time: "11:05:12", format: "LTS" }, + { formated: "1:05:12 PM" }, + "it displays full time (hours, minutes, seconds)" + ); + }); + + test("option[format]", function (assert) { + freezeTime({ date: "2020-03-11" }, () => { + assert.buildsCorrectDate( + { format: "YYYY" }, + { formated: "2020 (UTC)" }, + "it uses custom format" + ); + }); + }); + + test("option[displayedTimezone]", function (assert) { + freezeTime({}, () => { + assert.buildsCorrectDate( + { displayedTimezone: SYDNEY }, + { formated: "March 22, 2020 (Sydney)" }, + "it displays the timezone if the timezone is different from the date" + ); + }); + + freezeTime({}, () => { + assert.buildsCorrectDate( + { displayedTimezone: PARIS, timezone: PARIS }, + { formated: "March 22, 2020" }, + "it doesn't display the timezone if the timezone is the same than the date" + ); + }); + + freezeTime({}, () => { + assert.buildsCorrectDate( + { timezone: UTC, displayedTimezone: UTC }, + { formated: "March 22, 2020 (UTC)" }, + "it replaces `Etc/`" + ); + }); + + freezeTime({}, () => { + assert.buildsCorrectDate( + { timezone: LOS_ANGELES, displayedTimezone: LOS_ANGELES }, + { formated: "March 22, 2020 (Los Angeles)" }, + "it removes prefix and replaces `_`" + ); + }); + }); + + test("option[timezone]", function (assert) { + freezeTime({}, () => { + assert.buildsCorrectDate( + { timezone: SYDNEY, displayedTimezone: PARIS }, + { formated: "March 21, 2020" }, + "it correctly parses a date with the given timezone context" + ); + }); + }); + + test("option[recurring]", function (assert) { + freezeTime({ date: "2020-04-06 06:00", timezone: LAGOS }, () => { + assert.buildsCorrectDate( + { + date: "2019-11-25", + time: "11:00", + timezone: PARIS, + displayedTimezone: LAGOS, + recurring: "1.weeks", + }, + { + formated: "April 6, 2020 10:00 AM (Lagos)", + }, + "it correctly formats a recurring date starting from a !isDST timezone to a isDST timezone date when displayed to a user using a timezone with no DST" + ); + }); + + freezeTime({ date: "2020-04-06 01:00", timezone: SYDNEY }, () => { + assert.buildsCorrectDate( + { + date: "2020-03-09", + time: "02:00", + timezone: UTC, + recurring: "1.weeks", + calendar: false, + displayedTimezone: SYDNEY, + }, + { + formated: "April 6, 2020 12:00 PM (Sydney)", + }, + "it correctly formats a recurring date spanning over weeks" + ); + }); + + freezeTime({ date: "2020-04-07 22:00" }, () => { + assert.buildsCorrectDate( + { + date: "2019-11-25", + time: "11:00", + recurring: "1.weeks", + timezone: PARIS, + }, + { + formated: "April 13, 2020 11:00 AM", + }, + "it correctly adds from a !isDST date to a isDST date" + ); + }); + + freezeTime({ date: "2020-04-06 10:59" }, () => { + assert.buildsCorrectDate( + { + date: "2020-03-30", + time: "11:00", + recurring: "1.weeks", + timezone: PARIS, + }, + { + formated: "Today 11:00 AM", + }, + "it works to the minute" + ); + }); + + freezeTime({ date: "2020-04-06 11:01" }, () => { + assert.buildsCorrectDate( + { + date: "2020-03-30", + time: "11:00", + recurring: "1.weeks", + timezone: PARIS, + }, + { + formated: "April 13, 2020 11:00 AM", + }, + "it works to the minute" + ); + }); + + freezeTime({ date: "2020-12-28 09:16" }, () => { + assert.buildsCorrectDate( + { + date: "2021-01-24", + time: "08:30", + recurring: "1.weeks", + timezone: NEW_YORK, + }, + { + formated: "January 24, 2021 2:30 PM", + }, + "it works for a future date" + ); + }); + + freezeTime({ date: "2021-01-08 11:16" }, () => { + assert.buildsCorrectDate( + { + date: "2021-01-05", + time: "14:00", + recurring: "2.hours", + timezone: NEW_YORK, + }, + { + formated: "Today 12:00 PM", + }, + "it works with hours" + ); + }); + }); + + test("option[countdown]", function (assert) { + freezeTime({ date: "2020-03-21 23:59" }, () => { + assert.buildsCorrectDate( + { + countdown: true, + timezone: PARIS, + }, + { formated: "a minute" }, + "it shows the time remaining" + ); + }); + + freezeTime({ date: "2020-03-22 00:01" }, () => { + assert.buildsCorrectDate( + { + countdown: true, + timezone: PARIS, + }, + { + formated: I18n.t( + "discourse_local_dates.relative_dates.countdown.passed" + ), + }, + "it shows the date has passed" + ); + }); + }); + + test("option[calendar]", function (assert) { + freezeTime({ date: "2020-03-23 23:00" }, () => { + assert.buildsCorrectDate( + { date: "2020-03-22", time: "23:59", timezone: PARIS }, + { formated: "Yesterday 11:59 PM" }, + "it drops calendar mode when event date is more than one day before current date" + ); + }); + + freezeTime({ date: "2020-03-20 23:59" }, () => + assert.buildsCorrectDate( + { date: "2020-03-21", time: "01:00", timezone: PARIS }, + { formated: "Tomorrow 1:00 AM" } + ) + ); + + freezeTime({ date: "2020-03-20 23:59" }, () => + assert.buildsCorrectDate( + { date: "2020-03-21", time: "00:00", timezone: PARIS }, + { formated: "Saturday" }, + "it displays the day with no time when the time in the displayed timezone is 00:00" + ) + ); + + freezeTime({ date: "2020-03-20 23:59" }, () => { + assert.buildsCorrectDate( + { date: "2020-03-21", time: "23:59", timezone: PARIS }, + { formated: "Tomorrow 11:59 PM" } + ); + }); + + freezeTime({ date: "2020-03-21 00:00" }, () => + assert.buildsCorrectDate( + { date: "2020-03-21", time: "23:00", timezone: PARIS }, + { formated: "Today 11:00 PM" } + ) + ); + + freezeTime({ date: "2020-03-22 23:59" }, () => + assert.buildsCorrectDate( + { date: "2020-03-21", time: "23:59", timezone: PARIS }, + { formated: "Yesterday 11:59 PM" } + ) + ); + + freezeTime({ date: "2020-03-22 23:59" }, () => + assert.buildsCorrectDate( + { date: "2020-03-21", time: "23:59", timezone: PARIS }, + { formated: "Yesterday 11:59 PM" } + ) + ); + + freezeTime({ date: "2020-03-22 23:59" }, () => + assert.buildsCorrectDate( + { calendar: false, date: "2020-03-21", time: "23:59", timezone: PARIS }, + { formated: "March 21, 2020 11:59 PM" }, + "it doesn't use calendar when disabled" + ) + ); + + freezeTime({ date: "2020-03-24 01:00" }, () => + assert.buildsCorrectDate( + { date: "2020-03-21", timezone: PARIS }, + { formated: "March 21, 2020" }, + "it stops formatting out of calendar range" + ) + ); + + freezeTime({ date: "2020-05-12", timezone: LOS_ANGELES }, () => { + assert.buildsCorrectDate( + { + date: "2020-05-13", + time: "18:00", + localTimezone: LOS_ANGELES, + }, + { formated: "Tomorrow 11:00 AM" }, + "it correctly displays a different local timezone" + ); + }); + }); + + test("previews", function (assert) { + freezeTime({ date: "2020-03-22" }, () => { + assert.buildsCorrectDate( + { timezone: PARIS }, + { + previews: [ + { + current: true, + formated: + "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { timezone: PARIS, timezones: [SYDNEY] }, + { + previews: [ + { + current: true, + formated: + "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", + timezone: "Paris", + }, + { + formated: + "Sunday, March 22, 2020 10:00 AM → Monday, March 23, 2020 10:00 AM", + timezone: "Sydney", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { timezone: PARIS, displayedTimezone: LOS_ANGELES }, + { + previews: [ + { + current: true, + formated: + "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { timezone: PARIS, displayedTimezone: PARIS }, + { + previews: [ + { + current: true, + formated: + "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { timezone: PARIS, timezones: [PARIS] }, + { + previews: [ + { + current: true, + formated: + "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { duration: 90, timezone: PARIS, timezones: [PARIS] }, + { + previews: [ + { + current: true, + formated: + 'Sunday, March 22, 2020
12:00 AM → 1:30 AM', + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { duration: 1440, timezone: PARIS, timezones: [PARIS] }, + { + previews: [ + { + current: true, + formated: + "Sunday, March 22, 2020 12:00 AM → Monday, March 23, 2020 12:00 AM", + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-03-22", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { time: "11:34", timezone: PARIS, timezones: [PARIS] }, + { + previews: [ + { + current: true, + formated: + 'Sunday, March 22, 2020
11:34 AM', + timezone: "Paris", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-04-06", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { + timezone: PARIS, + date: "2020-04-07", + timezones: [LONDON, LAGOS, SYDNEY], + }, + { + previews: [ + { + current: true, + formated: + "Tuesday, April 7, 2020 12:00 AM → Wednesday, April 8, 2020 12:00 AM", + timezone: "Paris", + }, + { + formated: + "Monday, April 6, 2020 11:00 PM → Tuesday, April 7, 2020 11:00 PM", + timezone: "London", + }, + { + formated: + "Monday, April 6, 2020 11:00 PM → Tuesday, April 7, 2020 11:00 PM", + timezone: "Lagos", + }, + { + formated: + "Tuesday, April 7, 2020 8:00 AM → Wednesday, April 8, 2020 8:00 AM", + timezone: "Sydney", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-04-06", timezone: PARIS }, () => { + assert.buildsCorrectDate( + { + timezone: PARIS, + date: "2020-04-07", + time: "14:54", + timezones: [LONDON, LAGOS, SYDNEY], + }, + { + previews: [ + { + current: true, + formated: + 'Tuesday, April 7, 2020
2:54 PM', + timezone: "Paris", + }, + { + formated: + 'Tuesday, April 7, 2020
1:54 PM', + timezone: "London", + }, + { + formated: + 'Tuesday, April 7, 2020
1:54 PM', + timezone: "Lagos", + }, + { + formated: + 'Tuesday, April 7, 2020
10:54 PM', + timezone: "Sydney", + }, + ], + } + ); + }); + + freezeTime({ date: "2020-05-12", timezone: LOS_ANGELES }, () => { + assert.buildsCorrectDate( + { + date: "2020-05-13", + time: "18:00", + localTimezone: LOS_ANGELES, + }, + { + previews: [ + { + current: true, + formated: + 'Wednesday, May 13, 2020
11:00 AM', + timezone: "Los Angeles", + }, + { + formated: + 'Wednesday, May 13, 2020
6:00 PM', + timezone: "UTC", + }, + ], + } + ); + }); }); });