Skip to content

Commit

Permalink
Unstaged changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Dec 12, 2023
1 parent 17310dd commit ea8e312
Showing 1 changed file with 26 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ const testCases: TestCase[] = [
expectedText: "12:10:11",
expectedTooltip: "2020-01-01 12:10:11 (UTC+00:00)",
timeOnly: true,
},
{
name: "should use the correct tooltip when we know the offset, but not timezone",
value: DateTime.fromISO("2020-01-01T12:10:11.000Z"),
expectedText: "2020-01-01 12:10:11",
expectedTooltip: "2020-01-01 12:10:11 (UTC+00:00)",
explicitTimezone: "utc",
}
];

Expand Down Expand Up @@ -211,46 +218,6 @@ describe("ZonedDateTimeComponent", () => {
expect(spectator.element).toHaveExactTrimmedText(expectedDate);
});

// it("should not localize the date/time", () => {
// const expectedDate = "2020-01-01 12:10:11";
// spectator.detectChanges();

// expect(spectator.element).toHaveExactTrimmedText(expectedDate);
// });

// it("should only emit a non-localized date if the timezone is defined, and dateOnly is set", () => {
// const expectedDate = "2020-01-01";
// spectator.component.dateOnly = true;
// spectator.detectChanges();

// expect(spectator.element).toHaveExactTrimmedText(expectedDate);
// });

// it("should only emit a non-localized time if the timezone is defined, and timeOnly is set", () => {
// const expectedTime = "12:10:11";
// spectator.component.timeOnly = true;
// spectator.detectChanges();

// expect(spectator.element).toHaveExactTrimmedText(expectedTime);
// });

// if we are using UTC+0, we do not know the timezone, however, we know the offset
// we should therefore emit the offset in the tooltip, but not the timezone
it("should use the correct tooltip when we know the offset, but not timezone", () => {
const expectedTooltip = "2020-01-01 12:10:11 (UTC+00:00)";

spectator.component.timezone = "utc";
spectator.detectChanges();

assertTooltip(componentElement(), expectedTooltip);
});

it("should have a tooltip that displays the date/time and the timezone", () => {
const expectedTooltip =
"2020-01-01 12:10:11 (Australia/Darwin UTC+09:30)";
assertTooltip(componentElement(), expectedTooltip);
});

it("should update timezone correctly when assigned a new value", () => {
const expectedTooltip =
"2020-01-01 12:10:11 (Australia/Brisbane UTC+10:00)";
Expand All @@ -260,6 +227,25 @@ describe("ZonedDateTimeComponent", () => {

assertTooltip(componentElement(), expectedTooltip);
});

testCases.forEach((testCase) => {
const testFunction = () => {
spectator.component.value = testCase.value;
spectator.component.dateOnly = testCase.dateOnly;
spectator.component.timeOnly = testCase.timeOnly;

spectator.detectChanges();
spectator.component.ngOnChanges();
spectator.detectChanges();

expect(spectator.element).toHaveExactTrimmedText(
testCase.expectedText
);
assertTooltip(componentElement(), testCase.expectedTooltip);
};

it(testCase.name, testFunction);
})
});
});
});

0 comments on commit ea8e312

Please sign in to comment.