Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
|
import { visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
import userFixtures from "discourse/tests/fixtures/user-fixtures";
|
|
import User from "discourse/models/user";
|
|
import { click } from "@ember/test-helpers";
|
|
|
|
acceptance("User Card - Show Local Time", function (needs) {
|
|
needs.user();
|
|
needs.settings({ display_local_time_in_user_card: true });
|
|
needs.pretender((server, helper) => {
|
|
let cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
|
|
delete cardResponse.user.timezone;
|
|
server.get("/u/charlie/card.json", () => helper.response(cardResponse));
|
|
});
|
|
|
|
test("user card local time - does not update timezone for another user", async function (assert) {
|
|
User.current().changeTimezone("Australia/Brisbane");
|
|
|
|
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"
|
|
);
|
|
});
|
|
});
|