DEV: migrate acceptance tests to async await - admin, about, account created (#6111)

This commit is contained in:
Maja Komel 2018-07-19 11:35:10 +02:00 committed by Guo Xiang Tan
parent 4bee7fb458
commit 6aa2eb19d4
9 changed files with 285 additions and 329 deletions

View File

@ -1,12 +1,11 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("About");
QUnit.test("viewing", assert => {
visit("/about");
andThen(() => {
QUnit.test("viewing", async assert => {
await visit("/about");
assert.ok($("body.about-page").length, "has body class");
assert.ok(exists(".about.admins .user-info"), "has admins");
assert.ok(exists(".about.moderators .user-info"), "has moderators");
assert.ok(exists(".about.stats tr td"), "has stats");
});
});

View File

@ -3,13 +3,12 @@ import PreloadStore from "preload-store";
acceptance("Account Created");
QUnit.test("account created - message", assert => {
QUnit.test("account created - message", async assert => {
PreloadStore.store("accountCreated", {
message: "Hello World"
});
visit("/u/account-created");
await visit("/u/account-created");
andThen(() => {
assert.ok(exists(".account-created"));
assert.equal(
find(".account-created .ac-message")
@ -20,18 +19,17 @@ QUnit.test("account created - message", assert => {
);
assert.notOk(exists(".activation-controls"));
});
});
QUnit.test("account created - resend email", assert => {
QUnit.test("account created - resend email", async assert => {
PreloadStore.store("accountCreated", {
message: "Hello World",
username: "eviltrout",
email: "eviltrout@example.com",
show_controls: true
});
visit("/u/account-created");
andThen(() => {
await visit("/u/account-created");
assert.ok(exists(".account-created"));
assert.equal(
find(".account-created .ac-message")
@ -40,60 +38,55 @@ QUnit.test("account created - resend email", assert => {
"Hello World",
"it displays the message"
);
});
click(".activation-controls .resend");
andThen(() => {
await click(".activation-controls .resend");
assert.equal(currentPath(), "account-created.resent");
const email = find(".account-created .ac-message b").text();
assert.equal(email, "eviltrout@example.com");
});
});
QUnit.test("account created - update email - cancel", assert => {
QUnit.test("account created - update email - cancel", async assert => {
PreloadStore.store("accountCreated", {
message: "Hello World",
username: "eviltrout",
email: "eviltrout@example.com",
show_controls: true
});
visit("/u/account-created");
click(".activation-controls .edit-email");
andThen(() => {
await visit("/u/account-created");
await click(".activation-controls .edit-email");
assert.equal(currentPath(), "account-created.edit-email");
assert.ok(find(".activation-controls .btn-primary:disabled").length);
});
click(".activation-controls .edit-cancel");
andThen(() => {
await click(".activation-controls .edit-cancel");
assert.equal(currentPath(), "account-created.index");
});
});
QUnit.test("account created - update email - submit", assert => {
QUnit.test("account created - update email - submit", async assert => {
PreloadStore.store("accountCreated", {
message: "Hello World",
username: "eviltrout",
email: "eviltrout@example.com",
show_controls: true
});
visit("/u/account-created");
click(".activation-controls .edit-email");
andThen(() => {
await visit("/u/account-created");
await click(".activation-controls .edit-email");
assert.ok(find(".activation-controls .btn-primary:disabled").length);
});
fillIn(".activate-new-email", "newemail@example.com");
andThen(() => {
await fillIn(".activate-new-email", "newemail@example.com");
assert.notOk(find(".activation-controls .btn-primary:disabled").length);
});
click(".activation-controls .btn-primary");
andThen(() => {
await click(".activation-controls .btn-primary");
assert.equal(currentPath(), "account-created.resent");
const email = find(".account-created .ac-message b").text();
assert.equal(email, "newemail@example.com");
});
});

View File

@ -1,9 +1,9 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Flagging", { loggedIn: true });
QUnit.test("flagged posts", assert => {
visit("/admin/flags/active");
andThen(() => {
QUnit.test("flagged posts", async assert => {
await visit("/admin/flags/active");
assert.equal(find(".flagged-posts .flagged-post").length, 1);
assert.equal(
find(".flagged-post .flag-user").length,
@ -18,122 +18,111 @@ QUnit.test("flagged posts", assert => {
"shows the flagged username"
);
});
});
QUnit.test("flagged posts - agree", assert => {
QUnit.test("flagged posts - agree", async assert => {
const agreeFlag = selectKit(".agree-flag");
visit("/admin/flags/active");
await visit("/admin/flags/active");
agreeFlag.expand().selectRowByValue("confirm-agree-keep");
await agreeFlag.expandAwait();
await agreeFlag.selectRowByValueAwait("confirm-agree-keep");
andThen(() => {
assert.equal(
find(".admin-flags .flagged-post").length,
0,
"post was removed"
);
});
});
QUnit.test("flagged posts - agree + hide", assert => {
QUnit.test("flagged posts - agree + hide", async assert => {
const agreeFlag = selectKit(".agree-flag");
visit("/admin/flags/active");
await visit("/admin/flags/active");
agreeFlag.expand().selectRowByValue("confirm-agree-hide");
await agreeFlag.expandAwait();
await agreeFlag.selectRowByValueAwait("confirm-agree-hide");
andThen(() => {
assert.equal(
find(".admin-flags .flagged-post").length,
0,
"post was removed"
);
});
});
QUnit.test("flagged posts - agree + deleteSpammer", assert => {
QUnit.test("flagged posts - agree + deleteSpammer", async assert => {
const agreeFlag = selectKit(".agree-flag");
visit("/admin/flags/active");
await visit("/admin/flags/active");
agreeFlag.expand().selectRowByValue("delete-spammer");
await agreeFlag.expandAwait();
await agreeFlag.selectRowByValueAwait("delete-spammer");
click(".confirm-delete");
await click(".confirm-delete");
andThen(() => {
assert.equal(
find(".admin-flags .flagged-post").length,
0,
"post was removed"
);
});
});
QUnit.test("flagged posts - disagree", assert => {
visit("/admin/flags/active");
click(".disagree-flag");
andThen(() => {
QUnit.test("flagged posts - disagree", async assert => {
await visit("/admin/flags/active");
await click(".disagree-flag");
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
});
QUnit.test("flagged posts - defer", assert => {
visit("/admin/flags/active");
click(".defer-flag");
andThen(() => {
QUnit.test("flagged posts - defer", async assert => {
await visit("/admin/flags/active");
await click(".defer-flag");
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
});
QUnit.test("flagged posts - delete + defer", assert => {
QUnit.test("flagged posts - delete + defer", async assert => {
const deleteFlag = selectKit(".delete-flag");
visit("/admin/flags/active");
await visit("/admin/flags/active");
deleteFlag.expand().selectRowByValue("delete-defer");
await deleteFlag.expandAwait();
await deleteFlag.selectRowByValueAwait("delete-defer");
andThen(() => {
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
});
QUnit.test("flagged posts - delete + agree", assert => {
QUnit.test("flagged posts - delete + agree", async assert => {
const deleteFlag = selectKit(".delete-flag");
visit("/admin/flags/active");
await visit("/admin/flags/active");
deleteFlag.expand().selectRowByValue("delete-agree");
await deleteFlag.expandAwait();
await deleteFlag.selectRowByValueAwait("delete-agree");
andThen(() => {
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
});
QUnit.test("flagged posts - delete + deleteSpammer", assert => {
QUnit.test("flagged posts - delete + deleteSpammer", async assert => {
const deleteFlag = selectKit(".delete-flag");
visit("/admin/flags/active");
await visit("/admin/flags/active");
deleteFlag.expand().selectRowByValue("delete-spammer");
await deleteFlag.expandAwait();
await deleteFlag.selectRowByValueAwait("delete-spammer");
click(".confirm-delete");
await click(".confirm-delete");
andThen(() => {
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
});
QUnit.test("topics with flags", assert => {
visit("/admin/flags/topics");
andThen(() => {
QUnit.test("topics with flags", async assert => {
await visit("/admin/flags/topics");
assert.equal(find(".flagged-topics .flagged-topic").length, 1);
assert.equal(find(".flagged-topic .flagged-topic-user").length, 2);
assert.equal(find(".flagged-topic div.flag-counts").length, 3);
});
click(".flagged-topic .show-details");
andThen(() => {
await click(".flagged-topic .show-details");
assert.equal(currentURL(), "/admin/flags/topics/280");
});
});

View File

@ -1,11 +1,10 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Search Log Term", { loggedIn: true });
QUnit.test("show search log term details", assert => {
visit("/admin/logs/search_logs/term/ruby");
andThen(() => {
QUnit.test("show search log term details", async assert => {
await visit("/admin/logs/search_logs/term/ruby");
assert.ok($("div.search-logs-filter").length, "has the search type filter");
assert.ok(exists("canvas.chartjs-render-monitor"), "has graph canvas");
assert.ok(exists("div.header-search-results"), "has header search results");
});
});

View File

@ -1,13 +1,12 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Search Logs", { loggedIn: true });
QUnit.test("show search logs", assert => {
visit("/admin/logs/search_logs");
andThen(() => {
QUnit.test("show search logs", async assert => {
await visit("/admin/logs/search_logs");
assert.ok($("table.search-logs-list.grid").length, "has the div class");
assert.ok(
exists(".search-logs-list .admin-list-item .col"),
"has a list of search logs"
);
});
});

View File

@ -2,51 +2,44 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Site Texts", { loggedIn: true });
QUnit.test("search for a key", assert => {
visit("/admin/customize/site_texts");
QUnit.test("search for a key", async assert => {
await visit("/admin/customize/site_texts");
await fillIn(".site-text-search", "Test");
fillIn(".site-text-search", "Test");
andThen(() => {
assert.ok(exists(".site-text"));
assert.ok(exists(".site-text:not(.overridden)"));
assert.ok(exists(".site-text.overridden"));
});
// Only show overridden
click(".extra-options input");
andThen(() => {
await click(".extra-options input");
assert.ok(!exists(".site-text:not(.overridden)"));
assert.ok(exists(".site-text.overridden"));
});
});
QUnit.test("edit and revert a site text by key", assert => {
visit("/admin/customize/site_texts/site.test");
andThen(() => {
QUnit.test("edit and revert a site text by key", async assert => {
await visit("/admin/customize/site_texts/site.test");
assert.equal(find(".title h3").text(), "site.test");
assert.ok(!exists(".save-messages .saved"));
assert.ok(!exists(".save-messages .saved"));
assert.ok(!exists(".revert-site-text"));
});
// Change the value
fillIn(".site-text-value", "New Test Value");
click(".save-changes");
await fillIn(".site-text-value", "New Test Value");
await click(".save-changes");
andThen(() => {
assert.ok(exists(".save-messages .saved"));
assert.ok(exists(".revert-site-text"));
});
// Revert the changes
click(".revert-site-text");
andThen(() => {
assert.ok(exists(".bootbox.modal"));
});
click(".bootbox.modal .btn-primary");
await click(".revert-site-text");
assert.ok(exists(".bootbox.modal"));
await click(".bootbox.modal .btn-primary");
andThen(() => {
assert.ok(!exists(".save-messages .saved"));
assert.ok(!exists(".revert-site-text"));
});
});

View File

@ -22,60 +22,52 @@ acceptance("Admin - Suspend User", {
}
});
QUnit.test("suspend a user - cancel", assert => {
visit("/admin/users/1234/regular");
click(".suspend-user");
QUnit.test("suspend a user - cancel", async assert => {
await visit("/admin/users/1234/regular");
await click(".suspend-user");
andThen(() => {
assert.equal(find(".suspend-user-modal:visible").length, 1);
});
click(".d-modal-cancel");
andThen(() => {
await click(".d-modal-cancel");
assert.equal(find(".suspend-user-modal:visible").length, 0);
});
});
QUnit.test("suspend, then unsuspend a user", assert => {
QUnit.test("suspend, then unsuspend a user", async assert => {
const suspendUntilCombobox = selectKit(".suspend-until .combobox");
visit("/admin/flags/active");
await visit("/admin/flags/active");
visit("/admin/users/1234/regular");
await visit("/admin/users/1234/regular");
andThen(() => {
assert.ok(!exists(".suspension-info"));
});
click(".suspend-user");
await click(".suspend-user");
andThen(() => {
assert.equal(
find(".perform-suspend[disabled]").length,
1,
"disabled by default"
);
});
suspendUntilCombobox.expand().selectRowByValue("tomorrow");
suspendUntilCombobox.expandAwait();
suspendUntilCombobox.selectRowByValueAwait("tomorrow");
await fillIn(".suspend-reason", "for breaking the rules");
await fillIn(".suspend-message", "this is an email reason why");
fillIn(".suspend-reason", "for breaking the rules");
fillIn(".suspend-message", "this is an email reason why");
andThen(() => {
assert.equal(
find(".perform-suspend[disabled]").length,
0,
"no longer disabled"
);
});
click(".perform-suspend");
andThen(() => {
await click(".perform-suspend");
assert.equal(find(".suspend-user-modal:visible").length, 0);
assert.ok(exists(".suspension-info"));
});
click(".unsuspend-user");
andThen(() => {
await click(".unsuspend-user");
assert.ok(!exists(".suspension-info"));
});
});

View File

@ -2,10 +2,9 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Users List", { loggedIn: true });
QUnit.test("lists users", assert => {
visit("/admin/users/list/active");
andThen(() => {
QUnit.test("lists users", async assert => {
await visit("/admin/users/list/active");
assert.ok(exists(".users-list .user"));
assert.ok(!exists(".user:eq(0) .email small"), "escapes email");
});
});

View File

@ -1,56 +1,51 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Admin - Watched Words", { loggedIn: true });
QUnit.test("list words in groups", assert => {
visit("/admin/logs/watched_words/action/block");
andThen(() => {
QUnit.test("list words in groups", async assert => {
await visit("/admin/logs/watched_words/action/block");
assert.ok(exists(".watched-words-list"));
assert.ok(
!exists(".watched-words-list .watched-word"),
"Don't show bad words by default."
);
});
fillIn(".admin-controls .controls input[type=text]", "li");
andThen(() => {
await fillIn(".admin-controls .controls input[type=text]", "li");
assert.equal(
find(".watched-words-list .watched-word").length,
1,
"When filtering, show words even if checkbox is unchecked."
);
});
fillIn(".admin-controls .controls input[type=text]", "");
andThen(() => {
await fillIn(".admin-controls .controls input[type=text]", "");
assert.ok(
!exists(".watched-words-list .watched-word"),
"Clearing the filter hides words again."
);
});
click(".show-words-checkbox");
andThen(() => {
await click(".show-words-checkbox");
assert.ok(
exists(".watched-words-list .watched-word"),
"Always show the words when checkbox is checked."
);
});
click(".nav-stacked .censor a");
andThen(() => {
await click(".nav-stacked .censor a");
assert.ok(exists(".watched-words-list"));
assert.ok(!exists(".watched-words-list .watched-word"), "Empty word list.");
});
});
QUnit.test("add words", assert => {
visit("/admin/logs/watched_words/action/block");
andThen(() => {
QUnit.test("add words", async assert => {
await visit("/admin/logs/watched_words/action/block");
click(".show-words-checkbox");
fillIn(".watched-word-form input", "poutine");
});
click(".watched-word-form button");
andThen(() => {
await click(".watched-word-form button");
let found = [];
_.each(find(".watched-words-list .watched-word"), i => {
if (
@ -63,14 +58,13 @@ QUnit.test("add words", assert => {
});
assert.equal(found.length, 1);
});
});
QUnit.test("remove words", assert => {
visit("/admin/logs/watched_words/action/block");
click(".show-words-checkbox");
QUnit.test("remove words", async assert => {
await visit("/admin/logs/watched_words/action/block");
await click(".show-words-checkbox");
let word = null;
andThen(() => {
_.each(find(".watched-words-list .watched-word"), i => {
if (
$(i)
@ -80,9 +74,8 @@ QUnit.test("remove words", assert => {
word = i;
}
});
click("#" + $(word).attr("id"));
});
andThen(() => {
await click("#" + $(word).attr("id"));
assert.equal(find(".watched-words-list .watched-word").length, 1);
});
});