This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/account-created-test.js
Jarek Radosz a17d54d0bf
DEV: De-arrowify tests (#11068)
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)
2020-10-30 17:37:32 +01:00

93 lines
2.9 KiB
JavaScript

import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers";
import { visit, click, fillIn } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import PreloadStore from "discourse/lib/preload-store";
acceptance("Account Created", function () {
test("account created - message", async function (assert) {
PreloadStore.store("accountCreated", {
message: "Hello World",
});
await visit("/u/account-created");
assert.ok(exists(".account-created"));
assert.equal(
queryAll(".account-created .ac-message").text().trim(),
"Hello World",
"it displays the message"
);
assert.notOk(exists(".activation-controls"));
});
test("account created - resend email", async function (assert) {
PreloadStore.store("accountCreated", {
message: "Hello World",
username: "eviltrout",
email: "eviltrout@example.com",
show_controls: true,
});
await visit("/u/account-created");
assert.ok(exists(".account-created"));
assert.equal(
queryAll(".account-created .ac-message").text().trim(),
"Hello World",
"it displays the message"
);
await click(".activation-controls .resend");
assert.equal(currentPath(), "account-created.resent");
const email = queryAll(".account-created .ac-message b").text();
assert.equal(email, "eviltrout@example.com");
});
test("account created - update email - cancel", async function (assert) {
PreloadStore.store("accountCreated", {
message: "Hello World",
username: "eviltrout",
email: "eviltrout@example.com",
show_controls: true,
});
await visit("/u/account-created");
await click(".activation-controls .edit-email");
assert.equal(currentPath(), "account-created.edit-email");
assert.ok(queryAll(".activation-controls .btn-primary:disabled").length);
await click(".activation-controls .edit-cancel");
assert.equal(currentPath(), "account-created.index");
});
test("account created - update email - submit", async function (assert) {
PreloadStore.store("accountCreated", {
message: "Hello World",
username: "eviltrout",
email: "eviltrout@example.com",
show_controls: true,
});
await visit("/u/account-created");
await click(".activation-controls .edit-email");
assert.ok(queryAll(".activation-controls .btn-primary:disabled").length);
await fillIn(".activate-new-email", "newemail@example.com");
assert.notOk(queryAll(".activation-controls .btn-primary:disabled").length);
await click(".activation-controls .btn-primary");
assert.equal(currentPath(), "account-created.resent");
const email = queryAll(".account-created .ac-message b").text();
assert.equal(email, "newemail@example.com");
});
});