FIX: Local time not updating between user cards (#9564)

The local time was not updating between user cards because the computed property was not used correctly.

There's an old saying in Tennessee — I know it's in Texas, probably in Tennessee — that says, fool me once computed properties, shame on — shame on you. Fool me — you can't get fooled again.
This commit is contained in:
Martin Brennan 2020-04-28 13:23:43 +10:00 committed by GitHub
parent f9a44488e9
commit 66b5b8cf29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -75,9 +75,8 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
return user.resolvedTimezone();
},
@discourseComputed()
formattedUserLocalTime() {
const timezone = this.userTimezone;
@discourseComputed("userTimezone")
formattedUserLocalTime(timezone) {
return moment.tz(timezone).format(I18n.t("dates.time_with_zone"));
},

View File

@ -39,6 +39,31 @@ QUnit.test("user card local time", async assert => {
expectedTime,
"user card contains the user's local time"
);
cardResponse = _.clone(userFixtures["/u/charlie/card.json"]);
cardResponse.user.timezone = "America/New_York";
pretender.get("/u/charlie/card.json", () => [
200,
{ "Content-Type": "application/json" },
cardResponse
]);
await click("a[data-user-card=charlie]:first");
expectedTime =
moment
.tz("Australia/Brisbane")
.add(-14, "hours")
.format("hh:mm a") + " (EDT)";
assert.equal(
find(".user-card .local-time")
.text()
.trim(),
expectedTime,
"opening another user card updates the local time in the card (no caching)"
);
});
acceptance("User Card", { loggedIn: true });