Skip to content

Commit

Permalink
Refactored zoned-datetime component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Dec 13, 2023
1 parent 7b47411 commit 3258630
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const testCases: TestCase[] = [
name: "should display the full date and time in the users local timezone by default",
value: DateTime.fromISO("2020-01-01T12:10:11.000Z"),
expectedText: "2020-01-01 20:10:11",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
},
{
Expand All @@ -35,7 +35,7 @@ const testCases: TestCase[] = [
"Australia/Perth",
),
expectedText: "2020-01-01 20:10:11",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
},
{
Expand All @@ -45,37 +45,37 @@ const testCases: TestCase[] = [
name: "should display the correct dateTime if the Luxon dateTime object is a different timezone to the users local timezone",
value: DateTime.fromISO("2020-01-01T12:10:11.000+02:00"),
expectedText: "2020-01-01 18:10:11",
expectedTooltip: "2020-01-01 18:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 18:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T18:10:11.000+08:00",
},
{
name: "should increment date if timezone localization causes the date to increment",
value: DateTime.fromISO("2020-01-01T23:10:11.000Z"),
expectedText: "2020-01-02 07:10:11",
expectedTooltip: "2020-01-02 07:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-02 07:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-02T07:10:11.000+08:00",
},
{
name: "should only display the date if dateOnly is set",
value: DateTime.fromISO("2020-01-01T12:10:11.000Z"),
expectedText: "2020-01-01",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
dateOnly: true,
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
},
{
name: "should only display the time if timeOnly is set",
value: DateTime.fromISO("2020-01-01T12:10:11.000Z"),
expectedText: "20:10:11",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
timeOnly: true,
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
},
{
name: "should display full datetime if both dateOnly and timeOnly are set",
value: DateTime.fromISO("2020-01-01T12:10:11.000Z"),
expectedText: "2020-01-01 20:10:11",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
dateOnly: true,
timeOnly: true,
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
Expand All @@ -84,35 +84,35 @@ const testCases: TestCase[] = [
name: "should have a tooltip that displays the full un-localized date, time and utc offset for a JavaScript date object",
value: new Date("2020-01-01T12:10:11.000Z"),
expectedText: "2020-01-01 20:10:11",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
},
{
name: "should have a tooltip that displays the full un-localized utc date, utc time, and utc offset for a Luxon DateTime object",
value: DateTime.fromISO("2020-01-01T12:10:11.000Z"),
expectedText: "2020-01-01 20:10:11",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 20:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T20:10:11.000+08:00",
},
{
name: "should localize an iso8601 date/time with an offset",
value: new Date("2020-01-01T12:10:11.000+01:00"),
expectedText: "2020-01-01 19:10:11",
expectedTooltip: "2020-01-01 19:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 19:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T19:10:11.000+08:00",
},
{
name: "should localize a Luxon DateTime object with a timezone offset",
value: DateTime.fromISO("2020-01-01T12:10:11.000+01:00"),
expectedText: "2020-01-01 19:10:11",
expectedTooltip: "2020-01-01 19:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 19:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T19:10:11.000+08:00",
},
{
name: "should have the correct tooltip for a Luxon DateTime object with an offset, but no timezone",
value: new Date("2020-01-01T12:10:11.000+01:00"),
expectedText: "2020-01-01 19:10:11",
expectedTooltip: "2020-01-01 19:10:11 Australia/Perth UTC+08:00",
expectedTooltip: "2020-01-01 19:10:11 Australia/Perth +08:00",
expectedDateTimeAttribute: "2020-01-01T19:10:11.000+08:00",
},
];
Expand Down Expand Up @@ -155,7 +155,7 @@ describe("DatetimeComponent", () => {
// we should therefore omit it from the tooltip
Settings.defaultZone = "UTC+08:00";

const expectedTooltip = "2020-01-01 20:10:11 UTC+08:00";
const expectedTooltip = "2020-01-01 20:10:11 +08:00";
const mockDateTime = DateTime.fromISO("2020-01-01T12:10:11.000Z");

spectator.component.value = mockDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ export class DatetimeComponent

// if we don't know the timezone name, timezoneName will be undefined, and we should just return the offset
if (!timezoneName || !this.isIanaTimezone(timezoneName)) {
return `UTC${offsetValue}`;
return offsetValue;
}

return `${timezoneName} UTC${offsetValue}`;
return `${timezoneName} ${offsetValue}`;
}

protected dateTimeFormat(): string {
Expand Down
Loading

0 comments on commit 3258630

Please sign in to comment.