discourse/test/javascripts/acceptance/preferences-test.js.es6

217 lines
5.6 KiB
Plaintext
Raw Normal View History

import { acceptance } from "helpers/qunit-helpers";
acceptance("User Preferences", {
loggedIn: true,
beforeEach() {
2018-06-15 23:03:24 +08:00
const response = object => {
return [200, { "Content-Type": "application/json" }, object];
};
2018-06-16 00:18:45 +08:00
// prettier-ignore
server.post("/u/second_factors.json", () => { //eslint-disable-line
return response({
key: "rcyryaqage3jexfj",
qr: '<div id="test-qr">qr-code</div>'
});
});
2018-06-16 00:18:45 +08:00
// prettier-ignore
server.put("/u/second_factor.json", () => { //eslint-disable-line
2018-06-15 23:03:24 +08:00
return response({ error: "invalid token" });
});
2018-06-28 16:12:32 +08:00
// prettier-ignore
server.put("/u/second_factors_backup.json", () => { //eslint-disable-line
return response({ backup_codes: ["dsffdsd", "fdfdfdsf", "fddsds"] });
});
}
});
2017-06-15 01:57:58 +08:00
QUnit.test("update some fields", assert => {
2017-03-29 02:27:54 +08:00
visit("/u/eviltrout/preferences");
andThen(() => {
2018-06-15 23:03:24 +08:00
assert.ok($("body.user-preferences-page").length, "has the body class");
assert.equal(
currentURL(),
"/u/eviltrout/preferences/account",
"defaults to account tab"
);
assert.ok(exists(".user-preferences"), "it shows the preferences");
});
2017-05-04 01:49:16 +08:00
const savePreferences = () => {
2018-06-15 23:03:24 +08:00
click(".save-user");
assert.ok(!exists(".saved-user"), "it hasn't been saved yet");
2017-05-04 01:49:16 +08:00
andThen(() => {
2018-06-15 23:03:24 +08:00
assert.ok(exists(".saved-user"), "it displays the saved message");
2017-05-04 01:49:16 +08:00
});
};
fillIn(".pref-name input[type=text]", "Jon Snow");
savePreferences();
2017-05-04 01:49:16 +08:00
click(".preferences-nav .nav-profile a");
fillIn("#edit-location", "Westeros");
2017-05-04 01:49:16 +08:00
savePreferences();
2017-05-04 01:49:16 +08:00
click(".preferences-nav .nav-emails a");
click(".pref-activity-summary input[type=checkbox]");
savePreferences();
click(".preferences-nav .nav-notifications a");
2018-06-15 23:03:24 +08:00
selectKit(".control-group.notifications .combo-box.duration")
.expand()
.selectRowByValue(1440);
2017-05-04 01:49:16 +08:00
savePreferences();
click(".preferences-nav .nav-categories a");
2018-06-15 23:03:24 +08:00
fillIn(".category-controls .category-selector", "faq");
2017-05-04 01:49:16 +08:00
savePreferences();
2018-06-15 23:03:24 +08:00
assert.ok(
!exists(".preferences-nav .nav-tags a"),
"tags tab isn't there when tags are disabled"
);
2017-05-04 01:49:16 +08:00
2017-05-04 03:33:25 +08:00
// Error: Unhandled request in test environment: /themes/assets/10d71596-7e4e-4dc0-b368-faa3b6f1ce6d?_=1493833562388 (GET)
// click(".preferences-nav .nav-interface a");
// click('.control-group.other input[type=checkbox]:first');
// savePreferences();
2017-05-04 01:49:16 +08:00
2018-06-15 23:03:24 +08:00
assert.ok(
!exists(".preferences-nav .nav-apps a"),
"apps tab isn't there when you have no authorized apps"
);
});
2017-06-15 01:57:58 +08:00
QUnit.test("username", assert => {
2017-03-29 02:27:54 +08:00
visit("/u/eviltrout/preferences/username");
andThen(() => {
2017-06-15 01:57:58 +08:00
assert.ok(exists("#change_username"), "it has the input element");
});
});
2017-06-15 01:57:58 +08:00
QUnit.test("about me", assert => {
2017-03-29 02:27:54 +08:00
visit("/u/eviltrout/preferences/about-me");
andThen(() => {
2017-06-15 01:57:58 +08:00
assert.ok(exists(".raw-bio"), "it has the input element");
});
});
2017-06-15 01:57:58 +08:00
QUnit.test("email", assert => {
2017-03-29 02:27:54 +08:00
visit("/u/eviltrout/preferences/email");
2016-11-11 05:20:31 +08:00
andThen(() => {
2017-06-15 01:57:58 +08:00
assert.ok(exists("#change-email"), "it has the input element");
});
2018-06-15 23:03:24 +08:00
fillIn("#change-email", "invalidemail");
andThen(() => {
2018-06-15 23:03:24 +08:00
assert.equal(
find(".tip.bad")
.text()
.trim(),
I18n.t("user.email.invalid"),
"it should display invalid email tip"
);
2016-11-11 05:20:31 +08:00
});
});
QUnit.test("second factor", assert => {
visit("/u/eviltrout/preferences/second-factor");
andThen(() => {
assert.ok(exists("#password"), "it has a password input");
});
2018-06-15 23:03:24 +08:00
fillIn("#password", "secrets");
2018-06-29 04:14:04 +08:00
click(".user-preferences .btn-primary");
andThen(() => {
assert.ok(exists("#test-qr"), "shows qr code");
assert.notOk(exists("#password"), "it hides the password input");
});
2018-06-15 23:03:24 +08:00
fillIn("#second-factor-token", "111111");
click(".btn-primary");
andThen(() => {
assert.ok(
2018-06-15 23:03:24 +08:00
find(".alert-error")
.html()
.indexOf("invalid token") > -1,
"shows server validation error message"
);
});
});
2018-06-28 16:12:32 +08:00
QUnit.test("second factor backup", assert => {
visit("/u/eviltrout/preferences/second-factor-backup");
andThen(() => {
assert.ok(
exists("#second-factor-token"),
"it has a authentication token input"
);
});
fillIn("#second-factor-token", "111111");
2018-06-29 04:14:04 +08:00
click(".user-preferences .btn-primary");
2018-06-28 16:12:32 +08:00
andThen(() => {
assert.ok(exists(".backup-codes-area"), "shows backup codes");
});
});
2018-07-18 18:57:43 +08:00
QUnit.test("default avatar selector", assert => {
visit("/u/eviltrout/preferences");
click(".pref-avatar .btn");
andThen(() => {
assert.ok(exists(".avatar-choice", "opens the avatar selection modal"));
});
});
acceptance("Avatar selector when selectable avatars is enabled", {
loggedIn: true,
2018-07-18 18:57:43 +08:00
settings: { selectable_avatars_enabled: true },
beforeEach() {
// prettier-ignore
server.get("/site/selectable-avatars.json", () => { //eslint-disable-line
return [200, { "Content-Type": "application/json" }, [
"https://www.discourse.org",
"https://meta.discourse.org",
]];
});
}
});
2018-07-18 18:57:43 +08:00
QUnit.test("selectable avatars", assert => {
visit("/u/eviltrout/preferences");
click(".pref-avatar .btn");
andThen(() => {
2018-07-18 19:09:16 +08:00
assert.ok(
exists(".selectable-avatars", "opens the avatar selection modal")
);
2018-07-18 18:57:43 +08:00
});
});
acceptance("User Preferences when badges are disabled", {
loggedIn: true,
settings: { enable_badges: false }
});
QUnit.test("visit my preferences", assert => {
visit("/u/eviltrout/preferences");
andThen(() => {
2018-06-15 23:03:24 +08:00
assert.ok($("body.user-preferences-page").length, "has the body class");
assert.equal(
currentURL(),
"/u/eviltrout/preferences/account",
"defaults to account tab"
);
assert.ok(exists(".user-preferences"), "it shows the preferences");
});
2018-06-15 23:03:24 +08:00
});