DEV: migrate acceptance tests to async/await

This commit is contained in:
Maja Komel
2018-07-26 12:16:32 +02:00
parent 88241f57a3
commit a89dd51cae
20 changed files with 1046 additions and 1286 deletions

View File

@ -50,8 +50,8 @@ QUnit.test("suspend, then unsuspend a user", async assert => {
"disabled by default" "disabled by default"
); );
suspendUntilCombobox.expandAwait(); await suspendUntilCombobox.expandAwait();
suspendUntilCombobox.selectRowByValueAwait("tomorrow"); await suspendUntilCombobox.selectRowByValueAwait("tomorrow");
await fillIn(".suspend-reason", "for breaking the rules"); await fillIn(".suspend-reason", "for breaking the rules");
await fillIn(".suspend-message", "this is an email reason why"); await fillIn(".suspend-message", "this is an email reason why");

View File

@ -13,7 +13,7 @@ QUnit.test("does not display uncategorized if not allowed", async assert => {
await visit("/"); await visit("/");
await click("#create-topic"); await click("#create-topic");
categoryChooser.expandAwait(); await categoryChooser.expandAwait();
assert.ok(categoryChooser.rowByIndex(0).name() !== "uncategorized"); assert.ok(categoryChooser.rowByIndex(0).name() !== "uncategorized");
}); });

View File

@ -33,7 +33,7 @@ QUnit.test("removing a permission", async assert => {
await click(".edit-category"); await click(".edit-category");
await click("li.edit-category-security a"); await click("li.edit-category-security a");
await click(".edit-category-tab-security .edit-permission"); await click(".edit-category-tab-security .edit-permission");
availableGroups.expand(); await availableGroups.expandAwait();
assert.notOk( assert.notOk(
availableGroups.rowByValue("everyone").exists(), availableGroups.rowByValue("everyone").exists(),
@ -43,7 +43,7 @@ QUnit.test("removing a permission", async assert => {
await click( await click(
".edit-category-tab-security .permission-list li:first-of-type .remove-permission" ".edit-category-tab-security .permission-list li:first-of-type .remove-permission"
); );
availableGroups.expand(); await availableGroups.expandAwait();
assert.ok( assert.ok(
availableGroups.rowByValue("everyone").exists(), availableGroups.rowByValue("everyone").exists(),
@ -60,8 +60,10 @@ QUnit.test("adding a permission", async assert => {
await click(".edit-category"); await click(".edit-category");
await click("li.edit-category-security a"); await click("li.edit-category-security a");
await click(".edit-category-tab-security .edit-permission"); await click(".edit-category-tab-security .edit-permission");
availableGroups.expand().selectRowByValue("staff"); await availableGroups.expandAwait();
permissionSelector.expand().selectRowByValue("2"); await availableGroups.selectRowByValueAwait("staff");
await permissionSelector.expandAwait();
await permissionSelector.selectRowByValueAwait("2");
await click(".edit-category-tab-security .add-permission"); await click(".edit-category-tab-security .add-permission");
const $addedPermissionItem = find( const $addedPermissionItem = find(
@ -93,7 +95,8 @@ QUnit.test("adding a previously removed permission", async assert => {
"it removes the permission from the list" "it removes the permission from the list"
); );
availableGroups.expand().selectRowByValue("everyone"); await availableGroups.expandAwait();
await availableGroups.selectRowByValueAwait("everyone");
await click(".edit-category-tab-security .add-permission"); await click(".edit-category-tab-security .add-permission");
assert.equal( assert.equal(

View File

@ -78,7 +78,8 @@ QUnit.test("Subcategory list settings", async assert => {
); );
await click(".edit-category-general"); await click(".edit-category-general");
categoryChooser.expand().selectRowByValue(3); await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait(3);
await click(".edit-category-settings a"); await click(".edit-category-settings a");

View File

@ -419,7 +419,7 @@ QUnit.test("Disable body until category is selected", async assert => {
await fillIn(".d-editor-input", "Now I can type stuff"); await fillIn(".d-editor-input", "Now I can type stuff");
await categoryChooser.expandAwait(); await categoryChooser.expandAwait();
await categoryChooser.selectRowByValue("__none__"); await categoryChooser.selectRowByValueAwait("__none__");
assert.ok( assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0, find(".d-editor-textarea-wrapper.disabled").length === 0,

View File

@ -3,35 +3,29 @@ import { acceptance } from "helpers/qunit-helpers";
let userFound = false; let userFound = false;
acceptance("Forgot password", { acceptance("Forgot password", {
beforeEach() { pretend(server, helper) {
const response = object => { server.post("/session/forgot_password", () => {
return [200, { "Content-Type": "application/json" }, object]; return helper.response({
}; user_found: userFound
});
// prettier-ignore
server.post("/session/forgot_password", () => { // eslint-disable-line no-undef
return response({ user_found: userFound });
}); });
} }
}); });
QUnit.test("requesting password reset", assert => { QUnit.test("requesting password reset", async assert => {
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
click("#forgot-password-link"); await click("#forgot-password-link");
andThen(() => {
assert.equal( assert.equal(
find(".forgot-password-reset").attr("disabled"), find(".forgot-password-reset").attr("disabled"),
"disabled", "disabled",
"it should disable the button until the field is filled" "it should disable the button until the field is filled"
); );
});
fillIn("#username-or-email", "someuser"); await fillIn("#username-or-email", "someuser");
click(".forgot-password-reset"); await click(".forgot-password-reset");
andThen(() => {
assert.equal( assert.equal(
find(".alert-error") find(".alert-error")
.html() .html()
@ -41,12 +35,10 @@ QUnit.test("requesting password reset", assert => {
}), }),
"it should display an error for an invalid username" "it should display an error for an invalid username"
); );
});
fillIn("#username-or-email", "someuser@gmail.com"); await fillIn("#username-or-email", "someuser@gmail.com");
click(".forgot-password-reset"); await click(".forgot-password-reset");
andThen(() => {
assert.equal( assert.equal(
find(".alert-error") find(".alert-error")
.html() .html()
@ -56,17 +48,13 @@ QUnit.test("requesting password reset", assert => {
}), }),
"it should display an error for an invalid email" "it should display an error for an invalid email"
); );
});
fillIn("#username-or-email", "someuser"); await fillIn("#username-or-email", "someuser");
andThen(() => {
userFound = true; userFound = true;
});
click(".forgot-password-reset"); await click(".forgot-password-reset");
andThen(() => {
assert.notOk( assert.notOk(
exists(find(".alert-error")), exists(find(".alert-error")),
"it should remove the flash error when succeeding" "it should remove the flash error when succeeding"
@ -81,15 +69,13 @@ QUnit.test("requesting password reset", assert => {
}), }),
"it should display a success message for a valid username" "it should display a success message for a valid username"
); );
});
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
click("#forgot-password-link"); await click("#forgot-password-link");
fillIn("#username-or-email", "someuser@gmail.com"); await fillIn("#username-or-email", "someuser@gmail.com");
click(".forgot-password-reset"); await click(".forgot-password-reset");
andThen(() => {
assert.equal( assert.equal(
find(".modal-body") find(".modal-body")
.html() .html()
@ -99,5 +85,4 @@ QUnit.test("requesting password reset", assert => {
}), }),
"it should display a success message for a valid email" "it should display a success message for a valid email"
); );
});
}); });

View File

@ -2,14 +2,9 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Group logs", { acceptance("Group logs", {
loggedIn: true, loggedIn: true,
beforeEach() { pretend(server, helper) {
const response = object => { server.get("/groups/snorlax.json", () => {
return [200, { "Content-Type": "application/json" }, object]; return helper.response({
};
// prettier-ignore
server.get("/groups/snorlax.json", () => { // eslint-disable-line no-undef
return response({
group: { group: {
id: 41, id: 41,
automatic: false, automatic: false,
@ -37,10 +32,9 @@ acceptance("Group logs", {
}); });
// Workaround while awaiting https://github.com/tildeio/route-recognizer/issues/53 // Workaround while awaiting https://github.com/tildeio/route-recognizer/issues/53
// prettier-ignore server.get("/groups/snorlax/logs.json", request => {
server.get("/groups/snorlax/logs.json", request => { // eslint-disable-line no-undef
if (request.queryParams["filters[action]"]) { if (request.queryParams["filters[action]"]) {
return response({ return helper.response({
logs: [ logs: [
{ {
action: "change_group_setting", action: "change_group_setting",
@ -59,7 +53,7 @@ acceptance("Group logs", {
all_loaded: true all_loaded: true
}); });
} else { } else {
return response({ return helper.response({
logs: [ logs: [
{ {
action: "change_group_setting", action: "change_group_setting",
@ -99,21 +93,16 @@ acceptance("Group logs", {
} }
}); });
QUnit.test("Browsing group logs", assert => { QUnit.test("Browsing group logs", async assert => {
visit("/groups/snorlax/manage/logs"); await visit("/groups/snorlax/manage/logs");
andThen(() => {
assert.ok( assert.ok(
find("tr.group-manage-logs-row").length === 2, find("tr.group-manage-logs-row").length === 2,
"it should display the right number of logs" "it should display the right number of logs"
); );
click(find(".group-manage-logs-row button")[0]);
});
andThen(() => { await click(find(".group-manage-logs-row button")[0]);
assert.ok( assert.ok(
find("tr.group-manage-logs-row").length === 1, find("tr.group-manage-logs-row").length === 1,
"it should display the right number of logs" "it should display the right number of logs"
); );
});
}); });

View File

@ -3,6 +3,13 @@ import { acceptance, logIn } from "helpers/qunit-helpers";
acceptance("Group", { acceptance("Group", {
settings: { settings: {
enable_group_directory: true enable_group_directory: true
},
pretend(server, helper) {
server.post("/groups/Macdonald/request_membership", () => {
return helper.response({
relative_url: "/t/internationalization-localization/280"
});
});
} }
}); });
@ -72,35 +79,23 @@ QUnit.test("Anonymous Viewing Group", async assert => {
); );
}); });
QUnit.test("Anonymous Viewing Automatic Group", assert => { QUnit.test("Anonymous Viewing Automatic Group", async assert => {
visit("/groups/moderators"); await visit("/groups/moderators");
andThen(() => {
assert.equal( assert.equal(
count(".nav-pills li a[title='Manage']"), count(".nav-pills li a[title='Manage']"),
0, 0,
"it deos not show group messages navigation link" "it deos not show group messages navigation link"
); );
});
}); });
QUnit.test("User Viewing Group", assert => { QUnit.test("User Viewing Group", async assert => {
logIn(); logIn();
Discourse.reset(); Discourse.reset();
visit("/groups"); await visit("/groups");
click(".group-index-request"); await click(".group-index-request");
// prettier-ignore
server.post("/groups/Macdonald/request_membership", () => { // eslint-disable-line no-undef
return [
200,
{ "Content-Type": "application/json" },
{ relative_url: "/t/internationalization-localization/280" }
];
});
andThen(() => {
assert.equal( assert.equal(
find(".modal-header") find(".modal-header")
.text() .text()
@ -112,36 +107,31 @@ QUnit.test("User Viewing Group", assert => {
find(".request-group-membership-form textarea").val(), find(".request-group-membership-form textarea").val(),
"Please add me" "Please add me"
); );
});
click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
andThen(() => {
assert.equal( assert.equal(
find(".fancy-title") find(".fancy-title")
.text() .text()
.trim(), .trim(),
"Internationalization / localization" "Internationalization / localization"
); );
});
visit("/groups/discourse"); await visit("/groups/discourse");
click(".group-message-button"); await click(".group-message-button");
andThen(() => {
assert.ok(count("#reply-control") === 1, "it opens the composer"); assert.ok(count("#reply-control") === 1, "it opens the composer");
assert.equal( assert.equal(
find(".ac-wrap .item").text(), find(".ac-wrap .item").text(),
"discourse", "discourse",
"it prefills the group name" "it prefills the group name"
); );
});
}); });
QUnit.test( QUnit.test(
"Admin viewing group messages when there are no messages", "Admin viewing group messages when there are no messages",
assert => { async assert => {
// prettier-ignore // prettier-ignore
server.get("/topics/private-messages-group/eviltrout/discourse.json", () => { // eslint-disable-line no-undef server.get("/topics/private-messages-group/eviltrout/discourse.json", () => { // eslint-disable-line no-undef
return response({ topic_list: { topics: [] } }); return response({ topic_list: { topics: [] } });
@ -150,11 +140,10 @@ QUnit.test(
logIn(); logIn();
Discourse.reset(); Discourse.reset();
visit("/groups/discourse"); await visit("/groups/discourse");
click(".nav-pills li a[title='Messages']"); await click(".nav-pills li a[title='Messages']");
andThen(() => {
assert.equal( assert.equal(
find(".alert") find(".alert")
.text() .text()
@ -162,11 +151,10 @@ QUnit.test(
I18n.t("choose_topic.none_found"), I18n.t("choose_topic.none_found"),
"it should display the right alert" "it should display the right alert"
); );
});
} }
); );
QUnit.test("Admin viewing group messages", assert => { QUnit.test("Admin viewing group messages", async assert => {
// prettier-ignore // prettier-ignore
server.get("/topics/private-messages-group/eviltrout/discourse.json", () => { // eslint-disable-line no-undef server.get("/topics/private-messages-group/eviltrout/discourse.json", () => { // eslint-disable-line no-undef
return response({ return response({
@ -252,10 +240,9 @@ QUnit.test("Admin viewing group messages", assert => {
logIn(); logIn();
Discourse.reset(); Discourse.reset();
visit("/groups/discourse"); await visit("/groups/discourse");
click(".nav-pills li a[title='Messages']"); await click(".nav-pills li a[title='Messages']");
andThen(() => {
assert.equal( assert.equal(
find(".topic-list-item .link-top-line") find(".topic-list-item .link-top-line")
.text() .text()
@ -263,16 +250,14 @@ QUnit.test("Admin viewing group messages", assert => {
"This is a private message 1", "This is a private message 1",
"it should display the list of group topics" "it should display the list of group topics"
); );
});
}); });
QUnit.test("Admin Viewing Group", assert => { QUnit.test("Admin Viewing Group", async assert => {
logIn(); logIn();
Discourse.reset(); Discourse.reset();
visit("/groups/discourse"); await visit("/groups/discourse");
andThen(() => {
assert.ok( assert.ok(
find(".nav-pills li a[title='Manage']").length === 1, find(".nav-pills li a[title='Manage']").length === 1,
"it should show manage group tab if user is admin" "it should show manage group tab if user is admin"
@ -288,5 +273,4 @@ QUnit.test("Admin Viewing Group", assert => {
"Awesome Team", "Awesome Team",
"it should display the group name" "it should display the group name"
); );
});
}); });

View File

@ -17,13 +17,12 @@ acceptance("Login with email - hide email address taken", {
} }
}); });
QUnit.test("with hide_email_address_taken enabled", assert => { QUnit.test("with hide_email_address_taken enabled", async assert => {
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
fillIn("#login-account-name", "someuser@example.com"); await fillIn("#login-account-name", "someuser@example.com");
click(".login-with-email-button"); await click(".login-with-email-button");
andThen(() => {
assert.equal( assert.equal(
find(".alert-success") find(".alert-success")
.html() .html()
@ -33,5 +32,4 @@ QUnit.test("with hide_email_address_taken enabled", assert => {
}), }),
"it should display the success message for any email address" "it should display the success message for any email address"
); );
});
}); });

View File

@ -4,32 +4,21 @@ acceptance("Login with email - no social logins", {
settings: { settings: {
enable_local_logins_via_email: true enable_local_logins_via_email: true
}, },
beforeEach() { pretend(server, helper) {
const response = object => { server.post("/u/email-login", () => helper.response({ success: "OK" }));
return [200, { "Content-Type": "application/json" }, object];
};
// prettier-ignore
server.post("/u/email-login", () => { // eslint-disable-line no-undef
return response({ success: "OK" });
});
} }
}); });
QUnit.test("with login with email enabled", assert => { QUnit.test("with login with email enabled", async assert => {
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
andThen(() => {
assert.ok(exists(".login-with-email-button")); assert.ok(exists(".login-with-email-button"));
});
}); });
QUnit.test("with login with email disabled", assert => { QUnit.test("with login with email disabled", async assert => {
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
andThen(() => {
assert.notOk(find(".login-buttons").is(":visible")); assert.notOk(find(".login-buttons").is(":visible"));
});
}); });

View File

@ -7,23 +7,17 @@ acceptance("Login with email", {
enable_local_logins_via_email: true, enable_local_logins_via_email: true,
enable_facebook_logins: true enable_facebook_logins: true
}, },
beforeEach() { pretend(server, helper) {
const response = object => { server.post("/u/email-login", () =>
return [200, { "Content-Type": "application/json" }, object]; helper.response({ success: "OK", user_found: userFound })
}; );
// prettier-ignore
server.post("/u/email-login", () => { // eslint-disable-line no-undef
return response({ success: "OK", user_found: userFound });
});
} }
}); });
QUnit.test("with email button", assert => { QUnit.test("with email button", async assert => {
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
andThen(() => {
assert.ok( assert.ok(
exists(".btn-social.facebook"), exists(".btn-social.facebook"),
"it displays the facebook login button" "it displays the facebook login button"
@ -33,12 +27,10 @@ QUnit.test("with email button", assert => {
exists(".login-with-email-button"), exists(".login-with-email-button"),
"it displays the login with email button" "it displays the login with email button"
); );
});
fillIn("#login-account-name", "someuser"); await fillIn("#login-account-name", "someuser");
click(".login-with-email-button"); await click(".login-with-email-button");
andThen(() => {
assert.equal( assert.equal(
find(".alert-error").html(), find(".alert-error").html(),
I18n.t("email_login.complete_username_not_found", { I18n.t("email_login.complete_username_not_found", {
@ -46,12 +38,10 @@ QUnit.test("with email button", assert => {
}), }),
"it should display an error for an invalid username" "it should display an error for an invalid username"
); );
});
fillIn("#login-account-name", "someuser@gmail.com"); await fillIn("#login-account-name", "someuser@gmail.com");
click(".login-with-email-button"); await click(".login-with-email-button");
andThen(() => {
assert.equal( assert.equal(
find(".alert-error").html(), find(".alert-error").html(),
I18n.t("email_login.complete_email_not_found", { I18n.t("email_login.complete_email_not_found", {
@ -59,17 +49,13 @@ QUnit.test("with email button", assert => {
}), }),
"it should display an error for an invalid email" "it should display an error for an invalid email"
); );
});
fillIn("#login-account-name", "someuser"); await fillIn("#login-account-name", "someuser");
andThen(() => {
userFound = true; userFound = true;
});
click(".login-with-email-button"); await click(".login-with-email-button");
andThen(() => {
assert.equal( assert.equal(
find(".alert-success") find(".alert-success")
.html() .html()
@ -77,14 +63,12 @@ QUnit.test("with email button", assert => {
I18n.t("email_login.complete_username_found", { username: "someuser" }), I18n.t("email_login.complete_username_found", { username: "someuser" }),
"it should display a success message for a valid username" "it should display a success message for a valid username"
); );
});
visit("/"); await visit("/");
click("header .login-button"); await click("header .login-button");
fillIn("#login-account-name", "someuser@gmail.com"); await fillIn("#login-account-name", "someuser@gmail.com");
click(".login-with-email-button"); await click(".login-with-email-button");
andThen(() => {
assert.equal( assert.equal(
find(".alert-success") find(".alert-success")
.html() .html()
@ -94,9 +78,6 @@ QUnit.test("with email button", assert => {
}), }),
"it should display a success message for a valid email" "it should display a success message for a valid email"
); );
});
andThen(() => {
userFound = false; userFound = false;
});
}); });

View File

@ -3,52 +3,47 @@ import PreloadStore from "preload-store";
import { parsePostData } from "helpers/create-pretender"; import { parsePostData } from "helpers/create-pretender";
acceptance("Password Reset", { acceptance("Password Reset", {
beforeEach() { pretend(server, helper) {
const response = object => { server.get("/u/confirm-email-token/myvalidtoken.json", () =>
return [200, { "Content-Type": "application/json" }, object]; helper.response(200, { success: "OK" })
}; );
// prettier-ignore server.get("/u/confirm-email-token/requiretwofactor.json", () =>
server.get("/u/confirm-email-token/myvalidtoken.json", () => { //eslint-disable-line helper.response(200, { success: "OK" })
return response({ success: "OK" }); );
});
// prettier-ignore server.put("/u/password-reset/myvalidtoken.json", request => {
server.put("/u/password-reset/myvalidtoken.json", request => { //eslint-disable-line
const body = parsePostData(request.requestBody); const body = parsePostData(request.requestBody);
if (body.password === "jonesyAlienSlayer") { if (body.password === "jonesyAlienSlayer") {
return response({ return helper.response(200, {
success: false, success: false,
errors: { password: ["is the name of your cat"] } errors: { password: ["is the name of your cat"] }
}); });
} else { } else {
return response({ return helper.response(200, {
success: "OK", success: "OK",
message: I18n.t("password_reset.success") message: I18n.t("password_reset.success")
}); });
} }
}); });
// prettier-ignore server.put("/u/password-reset/requiretwofactor.json", request => {
server.get("/u/confirm-email-token/requiretwofactor.json", () => { //eslint-disable-line
return response({ success: "OK" });
});
// prettier-ignore
server.put("/u/password-reset/requiretwofactor.json", request => { //eslint-disable-line
const body = parsePostData(request.requestBody); const body = parsePostData(request.requestBody);
if ( if (
body.password === "perf3ctly5ecur3" && body.password === "perf3ctly5ecur3" &&
body.second_factor_token === "123123" body.second_factor_token === "123123"
) { ) {
return response({ return helper.response(200, {
success: "OK", success: "OK",
message: I18n.t("password_reset.success") message: I18n.t("password_reset.success")
}); });
} else if (body.second_factor_token === "123123") { } else if (body.second_factor_token === "123123") {
return response({ success: false, errors: { password: ["invalid"] } }); return helper.response(200, {
success: false,
errors: { password: ["invalid"] }
});
} else { } else {
return response({ return helper.response(200, {
success: false, success: false,
message: "invalid token", message: "invalid token",
errors: { user_second_factors: ["invalid token"] } errors: { user_second_factors: ["invalid token"] }
@ -58,21 +53,16 @@ acceptance("Password Reset", {
} }
}); });
QUnit.test("Password Reset Page", assert => { QUnit.test("Password Reset Page", async assert => {
PreloadStore.store("password_reset", { is_developer: false }); PreloadStore.store("password_reset", { is_developer: false });
visit("/u/password-reset/myvalidtoken"); await visit("/u/password-reset/myvalidtoken");
andThen(() => {
assert.ok(exists(".password-reset input"), "shows the input"); assert.ok(exists(".password-reset input"), "shows the input");
});
fillIn(".password-reset input", "perf3ctly5ecur3"); await fillIn(".password-reset input", "perf3ctly5ecur3");
andThen(() => {
assert.ok(exists(".password-reset .tip.good"), "input looks good"); assert.ok(exists(".password-reset .tip.good"), "input looks good");
});
fillIn(".password-reset input", "123"); await fillIn(".password-reset input", "123");
andThen(() => {
assert.ok(exists(".password-reset .tip.bad"), "input is not valid"); assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
assert.ok( assert.ok(
find(".password-reset .tip.bad") find(".password-reset .tip.bad")
@ -80,11 +70,9 @@ QUnit.test("Password Reset Page", assert => {
.indexOf(I18n.t("user.password.too_short")) > -1, .indexOf(I18n.t("user.password.too_short")) > -1,
"password too short" "password too short"
); );
});
fillIn(".password-reset input", "jonesyAlienSlayer"); await fillIn(".password-reset input", "jonesyAlienSlayer");
click(".password-reset form button"); await click(".password-reset form button");
andThen(() => {
assert.ok(exists(".password-reset .tip.bad"), "input is not valid"); assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
assert.ok( assert.ok(
find(".password-reset .tip.bad") find(".password-reset .tip.bad")
@ -92,32 +80,26 @@ QUnit.test("Password Reset Page", assert => {
.indexOf("is the name of your cat") > -1, .indexOf("is the name of your cat") > -1,
"server validation error message shows" "server validation error message shows"
); );
});
fillIn(".password-reset input", "perf3ctly5ecur3"); await fillIn(".password-reset input", "perf3ctly5ecur3");
click(".password-reset form button"); await click(".password-reset form button");
andThen(() => {
assert.ok(!exists(".password-reset form"), "form is gone"); assert.ok(!exists(".password-reset form"), "form is gone");
});
}); });
QUnit.test("Password Reset Page With Second Factor", assert => { QUnit.test("Password Reset Page With Second Factor", async assert => {
PreloadStore.store("password_reset", { PreloadStore.store("password_reset", {
is_developer: false, is_developer: false,
second_factor_required: true second_factor_required: true
}); });
visit("/u/password-reset/requiretwofactor"); await visit("/u/password-reset/requiretwofactor");
andThen(() => {
assert.notOk(exists("#new-account-password"), "does not show the input"); assert.notOk(exists("#new-account-password"), "does not show the input");
assert.ok(exists("#second-factor"), "shows the second factor prompt"); assert.ok(exists("#second-factor"), "shows the second factor prompt");
});
fillIn("input#second-factor", "0000"); await fillIn("input#second-factor", "0000");
click(".password-reset form button"); await click(".password-reset form button");
andThen(() => {
assert.ok(exists(".alert-error"), "shows 2 factor error"); assert.ok(exists(".alert-error"), "shows 2 factor error");
assert.ok( assert.ok(
@ -126,20 +108,15 @@ QUnit.test("Password Reset Page With Second Factor", assert => {
.indexOf("invalid token") > -1, .indexOf("invalid token") > -1,
"shows server validation error message" "shows server validation error message"
); );
});
fillIn("input#second-factor", "123123"); await fillIn("input#second-factor", "123123");
click(".password-reset form button"); await click(".password-reset form button");
andThen(() => {
assert.notOk(exists(".alert-error"), "hides error"); assert.notOk(exists(".alert-error"), "hides error");
assert.ok(exists("#new-account-password"), "shows the input"); assert.ok(exists("#new-account-password"), "shows the input");
});
fillIn(".password-reset input", "perf3ctly5ecur3"); await fillIn(".password-reset input", "perf3ctly5ecur3");
click(".password-reset form button"); await click(".password-reset form button");
andThen(() => {
assert.ok(!exists(".password-reset form"), "form is gone"); assert.ok(!exists(".password-reset form"), "form is gone");
});
}); });

View File

@ -166,13 +166,11 @@ QUnit.test("second factor backup", async assert => {
assert.ok(exists(".backup-codes-area"), "shows backup codes"); assert.ok(exists(".backup-codes-area"), "shows backup codes");
}); });
QUnit.test("default avatar selector", assert => { QUnit.test("default avatar selector", async assert => {
visit("/u/eviltrout/preferences"); await visit("/u/eviltrout/preferences");
click(".pref-avatar .btn"); await click(".pref-avatar .btn");
andThen(() => {
assert.ok(exists(".avatar-choice", "opens the avatar selection modal")); assert.ok(exists(".avatar-choice", "opens the avatar selection modal"));
});
}); });
acceptance("Avatar selector when selectable avatars is enabled", { acceptance("Avatar selector when selectable avatars is enabled", {
@ -202,9 +200,8 @@ acceptance("User Preferences when badges are disabled", {
settings: { enable_badges: false } settings: { enable_badges: false }
}); });
QUnit.test("visit my preferences", assert => { QUnit.test("visit my preferences", async assert => {
visit("/u/eviltrout/preferences"); await visit("/u/eviltrout/preferences");
andThen(() => {
assert.ok($("body.user-preferences-page").length, "has the body class"); assert.ok($("body.user-preferences-page").length, "has the body class");
assert.equal( assert.equal(
currentURL(), currentURL(),
@ -212,5 +209,4 @@ QUnit.test("visit my preferences", assert => {
"defaults to account tab" "defaults to account tab"
); );
assert.ok(exists(".user-preferences"), "it shows the preferences"); assert.ok(exists(".user-preferences"), "it shows the preferences");
});
}); });

View File

@ -2,18 +2,10 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Queued Posts", { acceptance("Queued Posts", {
loggedIn: true, loggedIn: true,
settings: { tagging_enabled: true } settings: { tagging_enabled: true },
}); pretend(server, helper) {
server.get("/queued_posts", () => {
QUnit.test( return helper.response({
"For topics: body of post, title, category and tags are all editbale",
assert => {
// prettier-ignore
server.get("/queued_posts", () => { //eslint-disable-line no-undef
return [
200,
{ "Content-Type": "application/json" },
{
users: [ users: [
{ {
id: 3, id: 3,
@ -75,26 +67,28 @@ QUnit.test(
], ],
__rest_serializer: "1", __rest_serializer: "1",
refresh_queued_posts: "/queued_posts?status=new" refresh_queued_posts: "/queued_posts?status=new"
}
];
}); });
});
}
});
visit("/queued-posts"); QUnit.test(
click(".queued-posts .queued-post button.edit"); "For topics: body of post, title, category and tags are all editable",
async assert => {
await visit("/queued-posts");
await click(".queued-posts .queued-post button.edit");
andThen(() => {
assert.ok(exists(".d-editor-container"), "the body should be editable"); assert.ok(exists(".d-editor-container"), "the body should be editable");
assert.ok( assert.ok(
exists(".edit-title .ember-text-field"), exists(".edit-title .ember-text-field"),
"the title should be editable" "the title should be editable"
); );
assert.ok(exists(".category-chooser"), "category should be editbale"); assert.ok(exists(".category-chooser"), "category should be editable");
assert.ok(exists(".tag-chooser"), "tags should be editable"); assert.ok(exists(".tag-chooser"), "tags should be editable");
});
} }
); );
QUnit.test("For replies: only the body of post is editbale", assert => { QUnit.test("For replies: only the body of post is editable", async assert => {
// prettier-ignore // prettier-ignore
server.get("/queued_posts", () => { //eslint-disable-line no-undef server.get("/queued_posts", () => { //eslint-disable-line no-undef
return [ return [
@ -176,19 +170,14 @@ QUnit.test("For replies: only the body of post is editbale", assert => {
]; ];
}); });
visit("/queued-posts"); await visit("/queued-posts");
click(".queued-posts .queued-post button.edit"); await click(".queued-posts .queued-post button.edit");
andThen(() => {
assert.ok(exists(".d-editor-container"), "the body should be editable"); assert.ok(exists(".d-editor-container"), "the body should be editable");
assert.notOk( assert.notOk(
exists(".edit-title .ember-text-field"), exists(".edit-title .ember-text-field"),
"title should not be editbale" "title should not be editbale"
); );
assert.notOk( assert.notOk(exists(".category-chooser"), "category should not be editable");
exists(".category-chooser"),
"category should not be editable"
);
assert.notOk(exists("div.tag-chooser"), "tags should not be editable"); assert.notOk(exists("div.tag-chooser"), "tags should not be editable");
});
}); });

View File

@ -2,19 +2,13 @@ import { acceptance, waitFor } from "helpers/qunit-helpers";
acceptance("Search - Full Page", { acceptance("Search - Full Page", {
settings: { tagging_enabled: true }, settings: { tagging_enabled: true },
loggedIn: true, loggedIn: true,
beforeEach() { pretend(server, helper) {
const response = object => { server.get("/tags/filter/search", () => {
return [200, { "Content-Type": "application/json" }, object]; return helper.response({ results: [{ text: "monkey", count: 1 }] });
};
// prettier-ignore
server.get("/tags/filter/search", () => { //eslint-disable-line
return response({ results: [{ text: "monkey", count: 1 }] });
}); });
// prettier-ignore server.get("/u/search/users", () => {
server.get("/u/search/users", () => { //eslint-disable-line return helper.response({
return response({
users: [ users: [
{ {
username: "admin", username: "admin",
@ -25,10 +19,8 @@ acceptance("Search - Full Page", {
}); });
}); });
// prettier-ignore server.get("/admin/groups.json", () => {
server.get("/admin/groups.json", () => { //eslint-disable-line return helper.response({
return response([
{
id: 2, id: 2,
automatic: true, automatic: true,
name: "moderators", name: "moderators",
@ -48,13 +40,11 @@ acceptance("Search - Full Page", {
flair_url: null, flair_url: null,
flair_bg_color: null, flair_bg_color: null,
flair_color: null flair_color: null
} });
]);
}); });
// prettier-ignore server.get("/badges.json", () => {
server.get("/badges.json", () => { //eslint-disable-line return helper.response({
return response({
badge_types: [{ id: 3, name: "Bronze", sort_order: 7 }], badge_types: [{ id: 3, name: "Bronze", sort_order: 7 }],
badge_groupings: [ badge_groupings: [
{ {
@ -92,53 +82,46 @@ acceptance("Search - Full Page", {
} }
}); });
QUnit.test("perform various searches", assert => { QUnit.test("perform various searches", async assert => {
visit("/search"); await visit("/search");
andThen(() => {
assert.ok($("body.search-page").length, "has body class"); assert.ok($("body.search-page").length, "has body class");
assert.ok(exists(".search-container"), "has container class"); assert.ok(exists(".search-container"), "has container class");
assert.ok(find(".search-query").length > 0); assert.ok(find(".search-query").length > 0);
assert.ok(find(".fps-topic").length === 0); assert.ok(find(".fps-topic").length === 0);
});
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
click(".search-cta"); await click(".search-cta");
andThen(() => {
assert.ok(find(".fps-topic").length === 0, "has no results"); assert.ok(find(".fps-topic").length === 0, "has no results");
assert.ok(find(".no-results-suggestion .google-search-form")); assert.ok(find(".no-results-suggestion .google-search-form"));
});
fillIn(".search-query", "posts"); await fillIn(".search-query", "posts");
click(".search-cta"); await click(".search-cta");
andThen(() => assert.ok(find(".fps-topic").length === 1, "has one post")); assert.ok(find(".fps-topic").length === 1, "has one post");
}); });
QUnit.test("escape search term", assert => { QUnit.test("escape search term", async assert => {
visit("/search"); await visit("/search");
fillIn(".search-query", "@<script>prompt(1337)</script>gmail.com"); await fillIn(".search-query", "@<script>prompt(1337)</script>gmail.com");
andThen(() => {
assert.ok( assert.ok(
exists( exists(
'.search-advanced-options span:contains("<script>prompt(1337)</script>gmail.com")' '.search-advanced-options span:contains("<script>prompt(1337)</script>gmail.com")'
), ),
"it escapes search term" "it escapes search term"
); );
});
}); });
QUnit.test("update username through advanced search ui", assert => { QUnit.test("update username through advanced search ui", async assert => {
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
fillIn(".search-advanced-options .user-selector", "admin"); await fillIn(".search-advanced-options .user-selector", "admin");
click(".search-advanced-options .user-selector"); await click(".search-advanced-options .user-selector");
keyEvent(".search-advanced-options .user-selector", "keydown", 8); await keyEvent(".search-advanced-options .user-selector", "keydown", 8);
andThen(() => { waitFor(assert, async () => {
waitFor(assert, () => {
assert.ok( assert.ok(
visible(".search-advanced-options .autocomplete"), visible(".search-advanced-options .autocomplete"),
'"autocomplete" popup is visible' '"autocomplete" popup is visible'
@ -150,9 +133,8 @@ QUnit.test("update username through advanced search ui", assert => {
'"autocomplete" popup has an entry for "admin"' '"autocomplete" popup has an entry for "admin"'
); );
click(".search-advanced-options .autocomplete ul li a:first"); await click(".search-advanced-options .autocomplete ul li a:first");
andThen(() => {
assert.ok( assert.ok(
exists('.search-advanced-options span:contains("admin")'), exists('.search-advanced-options span:contains("admin")'),
'has "admin" pre-populated' 'has "admin" pre-populated'
@ -163,24 +145,21 @@ QUnit.test("update username through advanced search ui", assert => {
'has updated search term to "none user:admin"' 'has updated search term to "none user:admin"'
); );
}); });
});
});
}); });
QUnit.test("update category through advanced search ui", assert => { QUnit.test("update category through advanced search ui", async assert => {
const categoryChooser = selectKit( const categoryChooser = selectKit(
".search-advanced-options .category-chooser" ".search-advanced-options .category-chooser"
); );
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
categoryChooser
.expand() await categoryChooser.expandAwait();
.fillInFilter("faq") await categoryChooser.fillInFilter("faq");
.selectRowByValue(4); await categoryChooser.selectRowByValueAwait(4);
andThen(() => {
assert.ok( assert.ok(
exists('.search-advanced-options .badge-category:contains("faq")'), exists('.search-advanced-options .badge-category:contains("faq")'),
'has "faq" populated' 'has "faq" populated'
@ -190,7 +169,6 @@ QUnit.test("update category through advanced search ui", assert => {
"none #faq", "none #faq",
'has updated search term to "none #faq"' 'has updated search term to "none #faq"'
); );
});
}); });
// test("update group through advanced search ui", assert => { // test("update group through advanced search ui", assert => {
@ -297,12 +275,13 @@ QUnit.test(
} }
); );
QUnit.test("update in:private filter through advanced search ui", assert => { QUnit.test(
visit("/search"); "update in:private filter through advanced search ui",
fillIn(".search-query", "none"); async assert => {
click(".search-advanced-options .in-private"); await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-private");
andThen(() => {
assert.ok( assert.ok(
exists(".search-advanced-options .in-private:checked"), exists(".search-advanced-options .in-private:checked"),
'has "are in my messages" populated' 'has "are in my messages" populated'
@ -312,15 +291,14 @@ QUnit.test("update in:private filter through advanced search ui", assert => {
"none in:private", "none in:private",
'has updated search term to "none in:private"' 'has updated search term to "none in:private"'
); );
}); }
}); );
QUnit.test("update in:seen filter through advanced search ui", assert => { QUnit.test("update in:seen filter through advanced search ui", async assert => {
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
click(".search-advanced-options .in-seen"); await click(".search-advanced-options .in-seen");
andThen(() => {
assert.ok( assert.ok(
exists(".search-advanced-options .in-seen:checked"), exists(".search-advanced-options .in-seen:checked"),
"it should check the right checkbox" "it should check the right checkbox"
@ -331,18 +309,17 @@ QUnit.test("update in:seen filter through advanced search ui", assert => {
"none in:seen", "none in:seen",
"it should update the search term" "it should update the search term"
); );
});
}); });
QUnit.test("update in filter through advanced search ui", assert => { QUnit.test("update in filter through advanced search ui", async assert => {
const inSelector = selectKit(".search-advanced-options .select-kit#in"); const inSelector = selectKit(".search-advanced-options .select-kit#in");
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
inSelector.expand().selectRowByValue("bookmarks"); await inSelector.expandAwait();
await inSelector.selectRowByValueAwait("bookmarks");
andThen(() => {
assert.ok( assert.ok(
inSelector.rowByName("I bookmarked").exists(), inSelector.rowByName("I bookmarked").exists(),
'has "I bookmarked" populated' 'has "I bookmarked" populated'
@ -352,20 +329,19 @@ QUnit.test("update in filter through advanced search ui", assert => {
"none in:bookmarks", "none in:bookmarks",
'has updated search term to "none in:bookmarks"' 'has updated search term to "none in:bookmarks"'
); );
});
}); });
QUnit.test("update status through advanced search ui", assert => { QUnit.test("update status through advanced search ui", async assert => {
const statusSelector = selectKit( const statusSelector = selectKit(
".search-advanced-options .select-kit#status" ".search-advanced-options .select-kit#status"
); );
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
statusSelector.expand().selectRowByValue("closed"); await statusSelector.expandAwait();
await statusSelector.selectRowByValueAwait("closed");
andThen(() => {
assert.ok( assert.ok(
statusSelector.rowByName("are closed").exists(), statusSelector.rowByName("are closed").exists(),
'has "are closed" populated' 'has "are closed" populated'
@ -375,21 +351,20 @@ QUnit.test("update status through advanced search ui", assert => {
"none status:closed", "none status:closed",
'has updated search term to "none status:closed"' 'has updated search term to "none status:closed"'
); );
});
}); });
QUnit.test("update post time through advanced search ui", assert => { QUnit.test("update post time through advanced search ui", async assert => {
const postTimeSelector = selectKit( const postTimeSelector = selectKit(
".search-advanced-options .select-kit#postTime" ".search-advanced-options .select-kit#postTime"
); );
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
fillIn("#search-post-date .date-picker", "2016-10-05"); await fillIn("#search-post-date .date-picker", "2016-10-05");
postTimeSelector.expand().selectRowByValue("after"); await postTimeSelector.expandAwait();
await postTimeSelector.selectRowByValueAwait("after");
andThen(() => {
assert.ok( assert.ok(
postTimeSelector.rowByName("after").exists(), postTimeSelector.rowByName("after").exists(),
'has "after" populated' 'has "after" populated'
@ -399,15 +374,13 @@ QUnit.test("update post time through advanced search ui", assert => {
"none after:2016-10-05", "none after:2016-10-05",
'has updated search term to "none after:2016-10-05"' 'has updated search term to "none after:2016-10-05"'
); );
});
}); });
QUnit.test("update min post count through advanced search ui", assert => { QUnit.test("update min post count through advanced search ui", async assert => {
visit("/search"); await visit("/search");
fillIn(".search-query", "none"); await fillIn(".search-query", "none");
fillIn("#search-min-post-count", "5"); await fillIn("#search-min-post-count", "5");
andThen(() => {
assert.equal( assert.equal(
find(".search-advanced-options #search-min-post-count").val(), find(".search-advanced-options #search-min-post-count").val(),
"5", "5",
@ -418,14 +391,12 @@ QUnit.test("update min post count through advanced search ui", assert => {
"none min_post_count:5", "none min_post_count:5",
'has updated search term to "none min_post_count:5"' 'has updated search term to "none min_post_count:5"'
); );
});
}); });
QUnit.test("validate advanced search when initially empty", assert => { QUnit.test("validate advanced search when initially empty", async assert => {
visit("/search?expanded=true"); await visit("/search?expanded=true");
click(".search-advanced-options .in-likes"); await click(".search-advanced-options .in-likes");
andThen(() => {
assert.ok( assert.ok(
exists(".search-advanced-options .in-likes:checked"), exists(".search-advanced-options .in-likes:checked"),
'has "I liked" populated' 'has "I liked" populated'
@ -435,5 +406,4 @@ QUnit.test("validate advanced search when initially empty", assert => {
"in:likes", "in:likes",
'has updated search term to "in:likes"' 'has updated search term to "in:likes"'
); );
});
}); });

View File

@ -3,34 +3,24 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Tag Hashtag", { acceptance("Tag Hashtag", {
loggedIn: true, loggedIn: true,
settings: { tagging_enabled: true }, settings: { tagging_enabled: true },
beforeEach() { pretend(server, helper) {
const response = object => { server.get("/tags/filter/search", () => {
return [200, { "Content-Type": "application/json" }, object]; return helper.response({ results: [{ text: "monkey", count: 1 }] });
};
// prettier-ignore
server.get("/tags/filter/search", () => { //eslint-disable-line
return response({ results: [{ text: "monkey", count: 1 }] });
}); });
// prettier-ignore server.get("/tags/check", () => {
server.get("/category_hashtags/check", () => { //eslint-disable-line return helper.response({
return response({ valid: [] }); valid: [{ value: "monkey", url: "/tags/monkey" }]
}); });
// prettier-ignore
server.get("/tags/check", () => { //eslint-disable-line
return response({ valid: [{ value: "monkey", url: "/tags/monkey" }] });
}); });
} }
}); });
QUnit.test("tag is cooked properly", assert => { QUnit.test("tag is cooked properly", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create"); await click("#topic-footer-buttons .btn.create");
fillIn(".d-editor-input", "this is a tag hashtag #monkey::tag"); await fillIn(".d-editor-input", "this is a tag hashtag #monkey::tag");
andThen(() => {
// TODO: Test that the autocomplete shows // TODO: Test that the autocomplete shows
assert.equal( assert.equal(
find(".d-editor-preview:visible") find(".d-editor-preview:visible")
@ -38,15 +28,12 @@ QUnit.test("tag is cooked properly", assert => {
.trim(), .trim(),
'<p>this is a tag hashtag <a href="/tags/monkey" class="hashtag">#<span>monkey</span></a></p>' '<p>this is a tag hashtag <a href="/tags/monkey" class="hashtag">#<span>monkey</span></a></p>'
); );
});
click("#reply-control .btn.create"); await click("#reply-control .btn.create");
andThen(() => {
assert.equal( assert.equal(
find(".topic-post:last .cooked") find(".topic-post:last .cooked")
.html() .html()
.trim(), .trim(),
'<p>this is a tag hashtag <a href="/tags/monkey" class="hashtag">#<span>monkey</span></a></p>' '<p>this is a tag hashtag <a href="/tags/monkey" class="hashtag">#<span>monkey</span></a></p>'
); );
});
}); });

View File

@ -1,13 +1,11 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "helpers/qunit-helpers";
acceptance("Tags", { loggedIn: true }); acceptance("Tags", { loggedIn: true });
QUnit.test("list the tags", assert => { QUnit.test("list the tags", async assert => {
visit("/tags"); await visit("/tags");
andThen(() => {
assert.ok($("body.tags-page").length, "has the body class"); assert.ok($("body.tags-page").length, "has the body class");
assert.ok(exists(".tag-eviltrout"), "shows the evil trout tag"); assert.ok(exists(".tag-eviltrout"), "shows the evil trout tag");
});
}); });
acceptance("Tags listed by group", { acceptance("Tags listed by group", {
@ -17,7 +15,7 @@ acceptance("Tags listed by group", {
} }
}); });
QUnit.test("list the tags in groups", assert => { QUnit.test("list the tags in groups", async assert => {
// prettier-ignore // prettier-ignore
server.get("/tags", () => { // eslint-disable-line no-undef server.get("/tags", () => { // eslint-disable-line no-undef
return [ return [
@ -57,8 +55,7 @@ QUnit.test("list the tags in groups", assert => {
]; ];
}); });
visit("/tags"); await visit("/tags");
andThen(() => {
assert.equal( assert.equal(
$(".tag-list").length, $(".tag-list").length,
4, 4,
@ -82,5 +79,4 @@ QUnit.test("list the tags in groups", assert => {
), ),
"shows the tags in default sort (by count)" "shows the tags in default sort (by count)"
); );
});
}); });

View File

@ -1,271 +1,9 @@
import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers"; import { acceptance, replaceCurrentUser } from "helpers/qunit-helpers";
acceptance("Topic - Edit timer", { loggedIn: true }); acceptance("Topic - Edit timer", {
loggedIn: true,
const response = object => [ pretend(server, helper) {
200, server.post("/t/280/timer", () =>
{ "Content-Type": "application/json" }, helper.response({
object
];
QUnit.test("default", assert => {
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
andThen(() => {
assert.equal(
futureDateInputSelector.header().title(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
});
click("#private-topic-timer");
andThen(() => {
assert.equal(timerType.header().title(), "Remind Me");
assert.equal(timerType.header().value(), "reminder");
assert.equal(
futureDateInputSelector.header().title(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
});
});
QUnit.test("autoclose - specific time", assert => {
const futureDateInputSelector = selectKit(".future-date-input-selector");
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
futureDateInputSelector.expand().selectRowByValue("next_week");
andThen(() => {
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex = /will automatically close in/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
});
QUnit.test("autoclose", assert => {
const futureDateInputSelector = selectKit(".future-date-input-selector");
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
futureDateInputSelector.expand().selectRowByValue("next_week");
andThen(() => {
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex = /will automatically close in/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
futureDateInputSelector.expand().selectRowByValue("pick_date_and_time");
fillIn(".future-date-input .date-picker", "2099-11-24");
andThen(() => {
assert.equal(
futureDateInputSelector.header().title(),
"Pick date and time"
);
assert.equal(
futureDateInputSelector.header().value(),
"pick_date_and_time"
);
const regex = /will automatically close in/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
futureDateInputSelector.expand().selectRowByValue("set_based_on_last_post");
fillIn(".future-date-input input[type=number]", "2");
andThen(() => {
assert.equal(
futureDateInputSelector.header().title(),
"Close based on last post"
);
assert.equal(
futureDateInputSelector.header().value(),
"set_based_on_last_post"
);
const regex = /This topic will close.*after the last reply/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
});
QUnit.test("close temporarily", assert => {
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
timerType.expand().selectRowByValue("open");
andThen(() => {
assert.equal(
futureDateInputSelector.header().title(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
});
futureDateInputSelector.expand().selectRowByValue("next_week");
andThen(() => {
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex = /will automatically open in/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
futureDateInputSelector.expand().selectRowByValue("pick_date_and_time");
fillIn(".future-date-input .date-picker", "2099-11-24");
andThen(() => {
assert.equal(
futureDateInputSelector.header().title(),
"Pick date and time"
);
assert.equal(
futureDateInputSelector.header().value(),
"pick_date_and_time"
);
const regex = /will automatically open in/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
});
QUnit.test("schedule", assert => {
const timerType = selectKit(".select-kit.timer-type");
const categoryChooser = selectKit(".modal-body .category-chooser");
const futureDateInputSelector = selectKit(".future-date-input-selector");
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
timerType.expand().selectRowByValue("publish_to_category");
andThen(() => {
assert.equal(categoryChooser.header().title(), "uncategorized");
assert.equal(categoryChooser.header().value(), null);
assert.equal(
futureDateInputSelector.header().title(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
});
categoryChooser.expand().selectRowByValue("7");
futureDateInputSelector.expand().selectRowByValue("next_week");
andThen(() => {
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex = /will be published to #dev/g;
const text = find(".future-date-input .topic-status-info")
.text()
.trim();
assert.ok(regex.test(text));
});
});
QUnit.test("TL4 can't auto-delete", assert => {
replaceCurrentUser({ staff: false, trust_level: 4 });
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
const timerType = selectKit(".select-kit.timer-type");
timerType.expand();
andThen(() => {
assert.ok(!timerType.rowByValue("delete").exists());
});
});
QUnit.test("auto delete", assert => {
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
visit("/t/internationalization-localization");
click(".toggle-admin-menu");
click(".topic-admin-status-update button");
timerType.expand().selectRowByValue("delete");
andThen(() => {
assert.equal(
futureDateInputSelector.header().title(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
});
futureDateInputSelector.expand().selectRowByValue("two_weeks");
andThen(() => {
assert.equal(futureDateInputSelector.header().title(), "Two Weeks");
assert.equal(futureDateInputSelector.header().value(), "two_weeks");
const regex = /will be automatically deleted/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
});
QUnit.test(
"Manually closing before the timer will clear the status text",
async assert => {
// prettier-ignore
server.post("/t/280/timer", () => // eslint-disable-line no-undef
response({
success: "OK", success: "OK",
execute_at: new Date( execute_at: new Date(
new Date().getTime() + 1 * 60 * 60 * 1000 new Date().getTime() + 1 * 60 * 60 * 1000
@ -277,14 +15,228 @@ QUnit.test(
}) })
); );
// prettier-ignore server.put("/t/internationalization-localization/280/status", () =>
server.put("/t/internationalization-localization/280/status", () => // eslint-disable-line no-undef helper.response({
response({
success: "OK", success: "OK",
topic_status_update: null topic_status_update: null
}) })
); );
}
});
QUnit.test("default", async assert => {
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await click("#private-topic-timer");
assert.equal(timerType.header().title(), "Remind Me");
assert.equal(timerType.header().value(), "reminder");
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
});
QUnit.test("autoclose - specific time", async assert => {
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex = /will automatically close in/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
QUnit.test("autoclose", async assert => {
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex1 = /will automatically close in/g;
const html1 = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex1.test(html1));
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("pick_date_and_time");
await fillIn(".future-date-input .date-picker", "2099-11-24");
assert.equal(futureDateInputSelector.header().title(), "Pick date and time");
assert.equal(futureDateInputSelector.header().value(), "pick_date_and_time");
const regex2 = /will automatically close in/g;
const html2 = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex2.test(html2));
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("set_based_on_last_post");
await fillIn(".future-date-input input[type=number]", "2");
assert.equal(
futureDateInputSelector.header().title(),
"Close based on last post"
);
assert.equal(
futureDateInputSelector.header().value(),
"set_based_on_last_post"
);
const regex3 = /This topic will close.*after the last reply/g;
const html3 = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex3.test(html3));
});
QUnit.test("close temporarily", async assert => {
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expandAwait();
await timerType.selectRowByValueAwait("open");
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex1 = /will automatically open in/g;
const html1 = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex1.test(html1));
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("pick_date_and_time");
await fillIn(".future-date-input .date-picker", "2099-11-24");
assert.equal(futureDateInputSelector.header().title(), "Pick date and time");
assert.equal(futureDateInputSelector.header().value(), "pick_date_and_time");
const regex2 = /will automatically open in/g;
const html2 = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex2.test(html2));
});
QUnit.test("schedule", async assert => {
const timerType = selectKit(".select-kit.timer-type");
const categoryChooser = selectKit(".modal-body .category-chooser");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expandAwait();
await timerType.selectRowByValueAwait("publish_to_category");
assert.equal(categoryChooser.header().title(), "uncategorized");
assert.equal(categoryChooser.header().value(), null);
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait("7");
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
const regex = /will be published to #dev/g;
const text = find(".future-date-input .topic-status-info")
.text()
.trim();
assert.ok(regex.test(text));
});
QUnit.test("TL4 can't auto-delete", async assert => {
replaceCurrentUser({ staff: false, trust_level: 4 });
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
const timerType = selectKit(".select-kit.timer-type");
await timerType.expandAwait();
assert.ok(!timerType.rowByValue("delete").exists());
});
QUnit.test("auto delete", async assert => {
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expandAwait();
await timerType.selectRowByValueAwait("delete");
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("two_weeks");
assert.equal(futureDateInputSelector.header().title(), "Two Weeks");
assert.equal(futureDateInputSelector.header().value(), "two_weeks");
const regex = /will be automatically deleted/g;
const html = find(".future-date-input .topic-status-info")
.html()
.trim();
assert.ok(regex.test(html));
});
QUnit.test(
"Manually closing before the timer will clear the status text",
async assert => {
const futureDateInputSelector = selectKit(".future-date-input-selector"); const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization"); await visit("/t/internationalization-localization");

View File

@ -1,39 +1,31 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "helpers/qunit-helpers";
acceptance("Topic Notifications button", { acceptance("Topic Notifications button", {
loggedIn: true, loggedIn: true,
beforeEach() { pretend(server, helper) {
const response = object => { server.post("/t/280/notifications", () => {
return [200, { "Content-Type": "application/json" }, object]; return helper.response({});
};
// prettier-ignore
server.post("/t/280/notifications", () => { // eslint-disable-line no-undef
return response({});
}); });
} }
}); });
QUnit.test("Updating topic notification level", assert => { QUnit.test("Updating topic notification level", async assert => {
const notificationOptions = selectKit( const notificationOptions = selectKit(
"#topic-footer-buttons .topic-notifications-options" "#topic-footer-buttons .topic-notifications-options"
); );
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
andThen(() => {
assert.ok( assert.ok(
notificationOptions.exists(), notificationOptions.exists(),
"it should display the notification options button in the topic's footer" "it should display the notification options button in the topic's footer"
); );
});
notificationOptions.expand().selectRowByValue("3"); await notificationOptions.expandAwait();
await notificationOptions.selectRowByValueAwait("3");
andThen(() => {
assert.equal( assert.equal(
notificationOptions.selectedRow().name(), notificationOptions.selectedRow().name(),
"Watching", "Watching",
"it should display the right notification level" "it should display the right notification level"
); );
});
}); });

View File

@ -1,21 +1,22 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "helpers/qunit-helpers";
acceptance("Topic", { loggedIn: true }); acceptance("Topic", {
loggedIn: true,
pretend(server, helper) {
server.put("/posts/398/wiki", () => {
return helper.response({});
});
}
});
QUnit.test("Share Popup", assert => { QUnit.test("Share Popup", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
andThen(() => {
assert.ok(!exists("#share-link.visible"), "it is not visible"); assert.ok(!exists("#share-link.visible"), "it is not visible");
});
click("button[data-share-url]"); await click("button[data-share-url]");
andThen(() => {
assert.ok(exists("#share-link.visible"), "it shows the popup"); assert.ok(exists("#share-link.visible"), "it shows the popup");
});
click("#share-link .close-share"); await click("#share-link .close-share");
andThen(() => {
assert.ok(!exists("#share-link.visible"), "it closes the popup"); assert.ok(!exists("#share-link.visible"), "it closes the popup");
});
// TODO tgxworld This fails on Travis but we need to push the security fix out // TODO tgxworld This fails on Travis but we need to push the security fix out
// first. // first.
@ -30,37 +31,33 @@ QUnit.test("Share Popup", assert => {
// }); // });
}); });
QUnit.test("Showing and hiding the edit controls", assert => { QUnit.test("Showing and hiding the edit controls", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
click("#topic-title .d-icon-pencil"); await click("#topic-title .d-icon-pencil");
andThen(() => {
assert.ok(exists("#edit-title"), "it shows the editing controls"); assert.ok(exists("#edit-title"), "it shows the editing controls");
assert.ok( assert.ok(
!exists(".title-wrapper .remove-featured-link"), !exists(".title-wrapper .remove-featured-link"),
"link to remove featured link is not shown" "link to remove featured link is not shown"
); );
});
fillIn("#edit-title", "this is the new title"); await fillIn("#edit-title", "this is the new title");
click("#topic-title .cancel-edit"); await click("#topic-title .cancel-edit");
andThen(() => {
assert.ok(!exists("#edit-title"), "it hides the editing controls"); assert.ok(!exists("#edit-title"), "it hides the editing controls");
});
}); });
QUnit.test("Updating the topic title and category", assert => { QUnit.test("Updating the topic title and category", async assert => {
const categoryChooser = selectKit(".title-wrapper .category-chooser"); const categoryChooser = selectKit(".title-wrapper .category-chooser");
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
click("#topic-title .d-icon-pencil"); await click("#topic-title .d-icon-pencil");
fillIn("#edit-title", "this is the new title"); await fillIn("#edit-title", "this is the new title");
categoryChooser.expand().selectRowByValue(4); await categoryChooser.expandAwait();
click("#topic-title .submit-edit"); await categoryChooser.selectRowByValueAwait(4);
await click("#topic-title .submit-edit");
andThen(() => {
assert.equal( assert.equal(
find("#topic-title .badge-category").text(), find("#topic-title .badge-category").text(),
"faq", "faq",
@ -73,36 +70,25 @@ QUnit.test("Updating the topic title and category", assert => {
"this is the new title", "this is the new title",
"it displays the new title" "it displays the new title"
); );
});
}); });
QUnit.test("Marking a topic as wiki", assert => { QUnit.test("Marking a topic as wiki", async assert => {
// prettier-ignore await visit("/t/internationalization-localization/280");
server.put("/posts/398/wiki", () => { // eslint-disable-line no-undef
return [200, { "Content-Type": "application/json" }, {}];
});
visit("/t/internationalization-localization/280");
andThen(() => {
assert.ok(find("a.wiki").length === 0, "it does not show the wiki icon"); assert.ok(find("a.wiki").length === 0, "it does not show the wiki icon");
});
click(".topic-post:eq(0) button.show-more-actions"); await click(".topic-post:eq(0) button.show-more-actions");
click(".topic-post:eq(0) button.show-post-admin-menu"); await click(".topic-post:eq(0) button.show-post-admin-menu");
click(".btn.wiki"); await click(".btn.wiki");
andThen(() => {
assert.ok(find("a.wiki").length === 1, "it shows the wiki icon"); assert.ok(find("a.wiki").length === 1, "it shows the wiki icon");
});
}); });
QUnit.test("Reply as new topic", assert => { QUnit.test("Reply as new topic", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
click("button.share:eq(0)"); await click("button.share:eq(0)");
click(".reply-as-new-topic a"); await click(".reply-as-new-topic a");
andThen(() => {
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.equal( assert.equal(
@ -121,15 +107,13 @@ QUnit.test("Reply as new topic", assert => {
"2", "2",
"it fills category selector with the right category" "it fills category selector with the right category"
); );
});
}); });
QUnit.test("Reply as new message", assert => { QUnit.test("Reply as new message", async assert => {
visit("/t/pm-for-testing/12"); await visit("/t/pm-for-testing/12");
click("button.share:eq(0)"); await click("button.share:eq(0)");
click(".reply-as-new-topic a"); await click(".reply-as-new-topic a");
andThen(() => {
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.equal( assert.equal(
@ -161,13 +145,11 @@ QUnit.test("Reply as new message", assert => {
"Group", "Group",
"it fills up the composer with the right group to start the PM to" "it fills up the composer with the right group to start the PM to"
); );
});
}); });
QUnit.test("Visit topic routes", assert => { QUnit.test("Visit topic routes", async assert => {
visit("/t/12"); await visit("/t/12");
andThen(() => {
assert.equal( assert.equal(
find(".fancy-title") find(".fancy-title")
.text() .text()
@ -175,11 +157,9 @@ QUnit.test("Visit topic routes", assert => {
"PM for testing", "PM for testing",
"it routes to the right topic" "it routes to the right topic"
); );
});
visit("/t/280/20"); await visit("/t/280/20");
andThen(() => {
assert.equal( assert.equal(
find(".fancy-title") find(".fancy-title")
.text() .text()
@ -187,18 +167,16 @@ QUnit.test("Visit topic routes", assert => {
"Internationalization / localization", "Internationalization / localization",
"it routes to the right topic" "it routes to the right topic"
); );
});
}); });
QUnit.test("Updating the topic title with emojis", assert => { QUnit.test("Updating the topic title with emojis", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
click("#topic-title .d-icon-pencil"); await click("#topic-title .d-icon-pencil");
fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:"); await fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:");
click("#topic-title .submit-edit"); await click("#topic-title .submit-edit");
andThen(() => {
assert.equal( assert.equal(
find(".fancy-title") find(".fancy-title")
.html() .html()
@ -206,7 +184,6 @@ QUnit.test("Updating the topic title with emojis", assert => {
'emojis title <img src="/images/emoji/emoji_one/bike.png?v=5" title="bike" alt="bike" class="emoji"> <img src="/images/emoji/emoji_one/blonde_woman/6.png?v=5" title="blonde_woman:t6" alt="blonde_woman:t6" class="emoji">', 'emojis title <img src="/images/emoji/emoji_one/bike.png?v=5" title="bike" alt="bike" class="emoji"> <img src="/images/emoji/emoji_one/blonde_woman/6.png?v=5" title="blonde_woman:t6" alt="blonde_woman:t6" class="emoji">',
"it displays the new title with emojis" "it displays the new title with emojis"
); );
});
}); });
acceptance("Topic featured links", { acceptance("Topic featured links", {
@ -217,29 +194,23 @@ acceptance("Topic featured links", {
} }
}); });
QUnit.test("remove featured link", assert => { QUnit.test("remove featured link", async assert => {
visit("/t/299/1"); await visit("/t/299/1");
andThen(() => {
assert.ok( assert.ok(
exists(".title-wrapper .topic-featured-link"), exists(".title-wrapper .topic-featured-link"),
"link is shown with topic title" "link is shown with topic title"
); );
});
click(".title-wrapper .edit-topic"); await click(".title-wrapper .edit-topic");
andThen(() => {
assert.ok( assert.ok(
exists(".title-wrapper .remove-featured-link"), exists(".title-wrapper .remove-featured-link"),
"link to remove featured link" "link to remove featured link"
); );
});
// this test only works in a browser: // this test only works in a browser:
// click('.title-wrapper .remove-featured-link'); // await click('.title-wrapper .remove-featured-link');
// click('.title-wrapper .submit-edit'); // await click('.title-wrapper .submit-edit');
// andThen(() => {
// assert.ok(!exists('.title-wrapper .topic-featured-link'), 'link is gone'); // assert.ok(!exists('.title-wrapper .topic-featured-link'), 'link is gone');
// });
}); });
QUnit.test("selecting posts", async assert => { QUnit.test("selecting posts", async assert => {