-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
create-account-test.js
81 lines (66 loc) · 2.68 KB
/
create-account-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import sinon from "sinon";
import LoginMethod from "discourse/models/login-method";
import pretender, {
parsePostData,
response,
} from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
acceptance("Create Account", function () {
test("create an account", async function (assert) {
await visit("/");
await click("header .sign-up-button");
assert.dom(".create-account").exists("it shows the create account modal");
await fillIn("#new-account-name", "Dr. Good Tuna");
await fillIn("#new-account-password", "cool password bro");
// without this double fill, field will sometimes being empty
// got consistent repro by having browser search bar focused when starting test
await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-email", "good.tuna@test.com");
// Check username
await fillIn("#new-account-username", "taken");
assert
.dom("#username-validation.bad")
.exists("the username validation is bad");
await click(".modal-footer .btn-primary");
await fillIn("#new-account-username", "good-tuna");
assert
.dom("#username-validation.good")
.exists("the username validation is good");
pretender.post("/u", (request) => {
assert.step("request");
const data = parsePostData(request.requestBody);
assert.strictEqual(data.name, "Dr. Good Tuna");
assert.strictEqual(data.password, "cool password bro");
assert.strictEqual(data.email, "good.tuna@test.com");
assert.strictEqual(data.username, "good-tuna");
return response({ success: true });
});
await click(".modal-footer .btn-primary");
assert
.dom(".modal-footer .btn-primary:disabled")
.exists("create account is disabled");
assert.verifySteps(["request"]);
});
test("validate username", async function (assert) {
await visit("/");
await click("header .sign-up-button");
await fillIn("#new-account-email", "z@z.co");
await click(".modal-footer .btn-primary");
assert
.dom("#username-validation")
.hasText(I18n.t("user.username.required"), "shows signup error");
});
test("can sign in using a third-party auth", async function (assert) {
sinon.stub(LoginMethod, "buildPostForm").callsFake((url) => {
assert.step("buildPostForm");
assert.strictEqual(url, "/auth/facebook?signup=true");
});
await visit("/");
await click("header .sign-up-button");
await click("#login-buttons button");
assert.verifySteps(["buildPostForm"]);
});
});