2015-04-06 14:14:00 -04:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2018-11-19 04:01:22 -05:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2018-05-09 11:27:59 -04:00
|
|
|
|
2020-04-27 20:13:59 -04:00
|
|
|
import pretender from "helpers/create-pretender";
|
|
|
|
import userFixtures from "fixtures/user_fixtures";
|
|
|
|
import User from "discourse/models/user";
|
|
|
|
|
|
|
|
acceptance("User Card - Show Local Time", {
|
|
|
|
loggedIn: true,
|
|
|
|
settings: { display_local_time_in_user_card: true }
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("user card local time", async assert => {
|
|
|
|
User.current().changeTimezone("Australia/Brisbane");
|
|
|
|
let cardResponse = _.clone(userFixtures["/u/eviltrout/card.json"]);
|
|
|
|
cardResponse.user.timezone = "Australia/Perth";
|
|
|
|
|
|
|
|
pretender.get("/u/eviltrout/card.json", () => [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/json" },
|
|
|
|
cardResponse
|
|
|
|
]);
|
|
|
|
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
assert.ok(invisible(".user-card"), "user card is invisible by default");
|
|
|
|
await click("a[data-user-card=eviltrout]:first");
|
|
|
|
|
2020-04-28 18:45:38 -04:00
|
|
|
let expectedTime = moment
|
|
|
|
.tz("Australia/Brisbane")
|
|
|
|
.add(-2, "hours")
|
|
|
|
.format("h:mm a");
|
2020-04-27 20:13:59 -04:00
|
|
|
|
|
|
|
assert.ok(visible(".user-card"), "card should appear");
|
|
|
|
assert.equal(
|
|
|
|
find(".user-card .local-time")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
expectedTime,
|
|
|
|
"user card contains the user's local time"
|
|
|
|
);
|
2020-04-27 23:23:43 -04:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2020-04-28 18:45:38 -04:00
|
|
|
expectedTime = moment
|
|
|
|
.tz("Australia/Brisbane")
|
|
|
|
.add(-14, "hours")
|
|
|
|
.format("h:mm a");
|
2020-04-27 23:23:43 -04:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".user-card .local-time")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
expectedTime,
|
|
|
|
"opening another user card updates the local time in the card (no caching)"
|
|
|
|
);
|
2020-04-27 20:13:59 -04:00
|
|
|
});
|
|
|
|
|
2020-05-10 21:01:47 -04:00
|
|
|
QUnit.test(
|
|
|
|
"user card local time - does not update timezone for another user",
|
|
|
|
async assert => {
|
|
|
|
User.current().changeTimezone("Australia/Brisbane");
|
|
|
|
let cardResponse = _.clone(userFixtures["/u/charlie/card.json"]);
|
|
|
|
delete cardResponse.user.timezone;
|
|
|
|
|
|
|
|
pretender.get("/u/charlie/card.json", () => [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/json" },
|
|
|
|
cardResponse
|
|
|
|
]);
|
|
|
|
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click("a[data-user-card=charlie]:first");
|
|
|
|
|
|
|
|
assert.not(
|
|
|
|
exists(".user-card .local-time"),
|
|
|
|
"it does not show the local time if the user card returns a null/undefined timezone for another user"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-08-30 13:40:12 -04:00
|
|
|
acceptance("User Card", { loggedIn: true });
|
2014-10-20 12:11:36 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("user card", async assert => {
|
2019-03-25 08:37:17 -04:00
|
|
|
await visit("/t/internationalization-localization/280");
|
2020-02-13 04:58:17 -05:00
|
|
|
assert.ok(invisible(".user-card"), "user card is invisible by default");
|
2014-10-20 12:11:36 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await click("a[data-user-card=eviltrout]:first");
|
2020-02-13 04:58:17 -05:00
|
|
|
assert.ok(visible(".user-card"), "card should appear");
|
2019-12-30 13:26:23 -05:00
|
|
|
assert.equal(
|
2020-02-13 04:58:17 -05:00
|
|
|
find(".user-card .username")
|
2019-12-30 13:26:23 -05:00
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"eviltrout",
|
|
|
|
"user card contains the data"
|
|
|
|
);
|
2018-11-19 04:01:22 -05:00
|
|
|
|
|
|
|
sandbox.stub(DiscourseURL, "routeTo");
|
2019-03-25 08:37:17 -04:00
|
|
|
await click(".card-content a.user-profile-link");
|
|
|
|
assert.ok(
|
|
|
|
DiscourseURL.routeTo.calledWith("/u/eviltrout"),
|
|
|
|
"it should navigate to the user profile"
|
|
|
|
);
|
2019-08-30 13:40:12 -04:00
|
|
|
|
|
|
|
await click("a[data-user-card=charlie]:first");
|
2020-02-13 04:58:17 -05:00
|
|
|
assert.ok(visible(".user-card"), "card should appear");
|
2019-12-30 13:26:23 -05:00
|
|
|
assert.equal(
|
2020-02-13 04:58:17 -05:00
|
|
|
find(".user-card .username")
|
2019-12-30 13:26:23 -05:00
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"charlie",
|
|
|
|
"user card contains the data"
|
|
|
|
);
|
2019-08-30 13:40:12 -04:00
|
|
|
|
2020-04-27 20:13:59 -04:00
|
|
|
assert.ok(
|
|
|
|
!visible(".user-card .local-time"),
|
|
|
|
"local time with zone does not show by default"
|
|
|
|
);
|
|
|
|
|
2019-08-30 13:40:12 -04:00
|
|
|
await click(".card-content .compose-pm button");
|
|
|
|
assert.ok(
|
2020-02-13 04:58:17 -05:00
|
|
|
invisible(".user-card"),
|
2019-08-30 13:40:12 -04:00
|
|
|
"user card dismissed after hitting Message button"
|
|
|
|
);
|
2019-12-30 13:26:23 -05:00
|
|
|
|
|
|
|
const mention = find("a.mention");
|
|
|
|
const icon = document.createElement("span");
|
|
|
|
icon.classList.add("icon");
|
|
|
|
mention.append(icon);
|
|
|
|
await click("a.mention .icon");
|
2020-02-13 04:58:17 -05:00
|
|
|
assert.ok(visible(".user-card"), "card should appear");
|
2019-12-30 13:26:23 -05:00
|
|
|
assert.equal(
|
2020-02-13 04:58:17 -05:00
|
|
|
find(".user-card .username")
|
2019-12-30 13:26:23 -05:00
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"eviltrout",
|
|
|
|
"user card contains the data"
|
|
|
|
);
|
2018-04-17 18:52:23 -04:00
|
|
|
});
|