DEV: migrate acceptance tests to async await - plugin, reports, user, topic

This commit is contained in:
Maja Komel 2018-07-19 16:40:12 +02:00 committed by GitHub
parent 2e96646659
commit 73739060f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 476 additions and 626 deletions

View File

@ -4,15 +4,13 @@ acceptance("Personal Message", {
loggedIn: true
});
QUnit.test("footer edit button", assert => {
visit("/t/pm-for-testing/12");
QUnit.test("footer edit button", async assert => {
await visit("/t/pm-for-testing/12");
andThen(() => {
assert.ok(
!exists(".edit-message"),
"does not show edit first post button on footer by default"
);
});
assert.ok(
!exists(".edit-message"),
"does not show edit first post button on footer by default"
);
});
acceptance("Personal Message Tagging", {
@ -20,13 +18,11 @@ acceptance("Personal Message Tagging", {
site: { can_tag_pms: true }
});
QUnit.test("show footer edit button", assert => {
visit("/t/pm-for-testing/12");
QUnit.test("show footer edit button", async assert => {
await visit("/t/pm-for-testing/12");
andThen(() => {
assert.ok(
exists(".edit-message"),
"shows edit first post button on footer when PM tagging is enabled"
);
});
assert.ok(
exists(".edit-message"),
"shows edit first post button on footer when PM tagging is enabled"
);
});

View File

@ -36,24 +36,21 @@ acceptance("Plugin Outlet - Connector Class", {
}
});
QUnit.test("Renders a template into the outlet", assert => {
visit("/u/eviltrout");
andThen(() => {
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.ok(
!find(".user-profile-primary-outlet.dont-render").length,
"doesn't render"
);
});
click(".say-hello");
andThen(() => {
assert.equal(
find(".hello-result").text(),
"hello!",
"actions delegate properly"
);
});
QUnit.test("Renders a template into the outlet", async assert => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.ok(
!find(".user-profile-primary-outlet.dont-render").length,
"doesn't render"
);
await click(".say-hello");
assert.equal(
find(".hello-result").text(),
"hello!",
"actions delegate properly"
);
});

View File

@ -23,26 +23,24 @@ acceptance("Plugin Outlet - Multi Template", {
}
});
QUnit.test("Renders a template into the outlet", assert => {
visit("/u/eviltrout");
andThen(() => {
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.ok(
find(".user-profile-primary-outlet.goodbye").length === 1,
"it has class names"
);
assert.equal(
find(".hello-span").text(),
"Hello",
"it renders into the outlet"
);
assert.equal(
find(".bye-span").text(),
"Goodbye",
"it renders into the outlet"
);
});
QUnit.test("Renders a template into the outlet", async assert => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.ok(
find(".user-profile-primary-outlet.goodbye").length === 1,
"it has class names"
);
assert.equal(
find(".hello-span").text(),
"Hello",
"it renders into the outlet"
);
assert.equal(
find(".bye-span").text(),
"Goodbye",
"it renders into the outlet"
);
});

View File

@ -14,17 +14,15 @@ acceptance("Plugin Outlet - Single Template", {
}
});
QUnit.test("Renders a template into the outlet", assert => {
visit("/u/eviltrout");
andThen(() => {
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.equal(
find(".hello-username").text(),
"eviltrout",
"it renders into the outlet"
);
});
QUnit.test("Renders a template into the outlet", async assert => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
"it has class names"
);
assert.equal(
find(".hello-username").text(),
"eviltrout",
"it renders into the outlet"
);
});

View File

@ -14,14 +14,12 @@ acceptance("Raw Plugin Outlet", {
}
});
QUnit.test("Renders the raw plugin outlet", assert => {
visit("/");
andThen(() => {
assert.ok(find(".topic-lala").length > 0, "it renders the outlet");
assert.equal(
find(".topic-lala:eq(0)").text(),
"11557",
"it has the topic id"
);
});
QUnit.test("Renders the raw plugin outlet", async assert => {
await visit("/");
assert.ok(find(".topic-lala").length > 0, "it renders the outlet");
assert.equal(
find(".topic-lala:eq(0)").text(),
"11557",
"it has the topic id"
);
});

View File

@ -4,28 +4,26 @@ acceptance("Reports", {
loggedIn: true
});
QUnit.test("Visit reports page", assert => {
visit("/admin/reports");
QUnit.test("Visit reports page", async assert => {
await visit("/admin/reports");
andThen(() => {
assert.equal($(".reports-list .report").length, 1);
assert.equal($(".reports-list .report").length, 1);
const $report = $(".reports-list .report:first-child");
const $report = $(".reports-list .report:first-child");
assert.equal(
$report
.find(".report-title")
.html()
.trim(),
"My report"
);
assert.equal(
$report
.find(".report-title")
.html()
.trim(),
"My report"
);
assert.equal(
$report
.find(".report-description")
.html()
.trim(),
"List of my activities"
);
});
assert.equal(
$report
.find(".report-description")
.html()
.trim(),
"List of my activities"
);
});

View File

@ -1,162 +1,135 @@
import { acceptance, logIn } from "helpers/qunit-helpers";
acceptance("Search");
QUnit.test("search", assert => {
visit("/");
QUnit.test("search", async assert => {
await visit("/");
click("#search-button");
await click("#search-button");
andThen(() => {
assert.ok(exists("#search-term"), "it shows the search bar");
assert.ok(!exists(".search-menu .results ul li"), "no results by default");
});
assert.ok(exists("#search-term"), "it shows the search bar");
assert.ok(!exists(".search-menu .results ul li"), "no results by default");
fillIn("#search-term", "dev");
keyEvent("#search-term", "keyup", 16);
andThen(() => {
assert.ok(exists(".search-menu .results ul li"), "it shows results");
});
await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
click(".show-help");
await click(".show-help");
andThen(() => {
assert.equal(
find(".full-page-search").val(),
"dev",
"it shows the search term"
);
assert.ok(
exists(".search-advanced-options"),
"advanced search is expanded"
);
});
assert.equal(
find(".full-page-search").val(),
"dev",
"it shows the search term"
);
assert.ok(exists(".search-advanced-options"), "advanced search is expanded");
});
QUnit.test("search for a tag", assert => {
visit("/");
QUnit.test("search for a tag", async assert => {
await visit("/");
click("#search-button");
await click("#search-button");
fillIn("#search-term", "evil");
keyEvent("#search-term", "keyup", 16);
andThen(() => {
assert.ok(exists(".search-menu .results ul li"), "it shows results");
});
await fillIn("#search-term", "evil");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
});
QUnit.test("search scope checkbox", assert => {
visit("/c/bug");
click("#search-button");
andThen(() => {
assert.ok(
exists(".search-context input:checked"),
"scope to category checkbox is checked"
);
});
click("#search-button");
QUnit.test("search scope checkbox", async assert => {
await visit("/c/bug");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to category checkbox is checked"
);
await click("#search-button");
visit("/t/internationalization-localization/280");
click("#search-button");
andThen(() => {
assert.not(
exists(".search-context input:checked"),
"scope to topic checkbox is not checked"
);
});
click("#search-button");
await visit("/t/internationalization-localization/280");
await click("#search-button");
assert.not(
exists(".search-context input:checked"),
"scope to topic checkbox is not checked"
);
await click("#search-button");
visit("/u/eviltrout");
click("#search-button");
andThen(() => {
assert.ok(
exists(".search-context input:checked"),
"scope to user checkbox is checked"
);
});
await visit("/u/eviltrout");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to user checkbox is checked"
);
});
QUnit.test("Search with context", assert => {
visit("/t/internationalization-localization/280/1");
QUnit.test("Search with context", async assert => {
await visit("/t/internationalization-localization/280/1");
click("#search-button");
fillIn("#search-term", "dev");
click(".search-context input[type='checkbox']");
keyEvent("#search-term", "keyup", 16);
await click("#search-button");
await fillIn("#search-term", "dev");
await click(".search-context input[type='checkbox']");
await keyEvent("#search-term", "keyup", 16);
andThen(() => {
assert.ok(exists(".search-menu .results ul li"), "it shows results");
assert.ok(exists(".search-menu .results ul li"), "it shows results");
assert.ok(
exists(".cooked span.highlight-strong"),
"it should highlight the search term"
);
});
assert.ok(
exists(".cooked span.highlight-strong"),
"it should highlight the search term"
);
visit("/");
click("#search-button");
await visit("/");
await click("#search-button");
andThen(() => {
assert.ok(!exists(".search-context input[type='checkbox']"));
});
assert.ok(!exists(".search-context input[type='checkbox']"));
visit("/t/internationalization-localization/280/1");
click("#search-button");
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
andThen(() => {
assert.ok(!$(".search-context input[type=checkbox]").is(":checked"));
});
assert.ok(!$(".search-context input[type=checkbox]").is(":checked"));
});
QUnit.test("Right filters are shown to anonymous users", assert => {
QUnit.test("Right filters are shown to anonymous users", async assert => {
const inSelector = selectKit(".select-kit#in");
visit("/search?expanded=true");
await visit("/search?expanded=true");
inSelector.expand();
await inSelector.expandAwait();
andThen(() => {
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());
assert.ok(inSelector.rowByValue("unpinned").exists());
assert.ok(inSelector.rowByValue("wiki").exists());
assert.ok(inSelector.rowByValue("images").exists());
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());
assert.ok(inSelector.rowByValue("unpinned").exists());
assert.ok(inSelector.rowByValue("wiki").exists());
assert.ok(inSelector.rowByValue("images").exists());
assert.notOk(inSelector.rowByValue("unseen").exists());
assert.notOk(inSelector.rowByValue("posted").exists());
assert.notOk(inSelector.rowByValue("watching").exists());
assert.notOk(inSelector.rowByValue("tracking").exists());
assert.notOk(inSelector.rowByValue("bookmarks").exists());
assert.notOk(inSelector.rowByValue("unseen").exists());
assert.notOk(inSelector.rowByValue("posted").exists());
assert.notOk(inSelector.rowByValue("watching").exists());
assert.notOk(inSelector.rowByValue("tracking").exists());
assert.notOk(inSelector.rowByValue("bookmarks").exists());
assert.notOk(exists(".search-advanced-options .in-likes"));
assert.notOk(exists(".search-advanced-options .in-private"));
assert.notOk(exists(".search-advanced-options .in-seen"));
});
assert.notOk(exists(".search-advanced-options .in-likes"));
assert.notOk(exists(".search-advanced-options .in-private"));
assert.notOk(exists(".search-advanced-options .in-seen"));
});
QUnit.test("Right filters are shown to logged-in users", assert => {
QUnit.test("Right filters are shown to logged-in users", async assert => {
const inSelector = selectKit(".select-kit#in");
logIn();
Discourse.reset();
visit("/search?expanded=true");
await visit("/search?expanded=true");
inSelector.expand();
await inSelector.expandAwait();
andThen(() => {
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());
assert.ok(inSelector.rowByValue("unpinned").exists());
assert.ok(inSelector.rowByValue("wiki").exists());
assert.ok(inSelector.rowByValue("images").exists());
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());
assert.ok(inSelector.rowByValue("unpinned").exists());
assert.ok(inSelector.rowByValue("wiki").exists());
assert.ok(inSelector.rowByValue("images").exists());
assert.ok(inSelector.rowByValue("unseen").exists());
assert.ok(inSelector.rowByValue("posted").exists());
assert.ok(inSelector.rowByValue("watching").exists());
assert.ok(inSelector.rowByValue("tracking").exists());
assert.ok(inSelector.rowByValue("bookmarks").exists());
assert.ok(inSelector.rowByValue("unseen").exists());
assert.ok(inSelector.rowByValue("posted").exists());
assert.ok(inSelector.rowByValue("watching").exists());
assert.ok(inSelector.rowByValue("tracking").exists());
assert.ok(inSelector.rowByValue("bookmarks").exists());
assert.ok(exists(".search-advanced-options .in-likes"));
assert.ok(exists(".search-advanced-options .in-private"));
assert.ok(exists(".search-advanced-options .in-seen"));
});
assert.ok(exists(".search-advanced-options .in-likes"));
assert.ok(exists(".search-advanced-options .in-private"));
assert.ok(exists(".search-advanced-options .in-seen"));
});

View File

@ -2,18 +2,14 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Shared Drafts", { loggedIn: true });
QUnit.test("Viewing", assert => {
visit("/t/some-topic/9");
andThen(() => {
assert.ok(find(".shared-draft-controls").length === 1);
let categoryChooser = selectKit(".shared-draft-controls .category-chooser");
assert.equal(categoryChooser.header().value(), "3");
});
QUnit.test("Viewing", async assert => {
await visit("/t/some-topic/9");
assert.ok(find(".shared-draft-controls").length === 1);
let categoryChooser = selectKit(".shared-draft-controls .category-chooser");
assert.equal(categoryChooser.header().value(), "3");
click(".publish-shared-draft");
click(".bootbox .btn-primary");
await click(".publish-shared-draft");
await click(".bootbox .btn-primary");
andThen(() => {
assert.ok(find(".shared-draft-controls").length === 0);
});
assert.ok(find(".shared-draft-controls").length === 0);
});

View File

@ -1,218 +1,176 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Signing In");
QUnit.test("sign in", assert => {
visit("/");
click("header .login-button");
andThen(() => {
assert.ok(exists(".login-modal"), "it shows the login modal");
});
QUnit.test("sign in", async assert => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
// Test invalid password first
fillIn("#login-account-name", "eviltrout");
fillIn("#login-account-password", "incorrect");
click(".modal-footer .btn-primary");
andThen(() => {
assert.ok(exists("#modal-alert:visible"), "it displays the login error");
assert.not(
exists(".modal-footer .btn-primary:disabled"),
"enables the login button"
);
});
await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "incorrect");
await click(".modal-footer .btn-primary");
assert.ok(exists("#modal-alert:visible"), "it displays the login error");
assert.not(
exists(".modal-footer .btn-primary:disabled"),
"enables the login button"
);
// Use the correct password
fillIn("#login-account-password", "correct");
click(".modal-footer .btn-primary");
andThen(() => {
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"disables the login button"
);
});
await fillIn("#login-account-password", "correct");
await click(".modal-footer .btn-primary");
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"disables the login button"
);
});
QUnit.test("sign in - not activated", assert => {
visit("/");
andThen(() => {
click("header .login-button");
andThen(() => {
assert.ok(exists(".login-modal"), "it shows the login modal");
});
QUnit.test("sign in - not activated", async assert => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
fillIn("#login-account-name", "eviltrout");
fillIn("#login-account-password", "not-activated");
click(".modal-footer .btn-primary");
andThen(() => {
assert.equal(
find(".modal-body b").text(),
"<small>eviltrout@example.com</small>"
);
assert.ok(!exists(".modal-body small"), "it escapes the email address");
});
await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "not-activated");
await click(".modal-footer .btn-primary");
assert.equal(
find(".modal-body b").text(),
"<small>eviltrout@example.com</small>"
);
assert.ok(!exists(".modal-body small"), "it escapes the email address");
click(".modal-footer button.resend");
andThen(() => {
assert.equal(
find(".modal-body b").text(),
"<small>current@example.com</small>"
);
assert.ok(!exists(".modal-body small"), "it escapes the email address");
});
});
await click(".modal-footer button.resend");
assert.equal(
find(".modal-body b").text(),
"<small>current@example.com</small>"
);
assert.ok(!exists(".modal-body small"), "it escapes the email address");
});
QUnit.test("sign in - not activated - edit email", assert => {
visit("/");
andThen(() => {
click("header .login-button");
andThen(() => {
assert.ok(exists(".login-modal"), "it shows the login modal");
});
QUnit.test("sign in - not activated - edit email", async assert => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
fillIn("#login-account-name", "eviltrout");
fillIn("#login-account-password", "not-activated-edit");
click(".modal-footer .btn-primary");
click(".modal-footer button.edit-email");
andThen(() => {
assert.equal(find(".activate-new-email").val(), "current@example.com");
assert.equal(
find(".modal-footer .btn-primary:disabled").length,
1,
"must change email"
);
});
fillIn(".activate-new-email", "different@example.com");
andThen(() => {
assert.equal(find(".modal-footer .btn-primary:disabled").length, 0);
});
click(".modal-footer .btn-primary");
andThen(() => {
assert.equal(find(".modal-body b").text(), "different@example.com");
});
});
await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "not-activated-edit");
await click(".modal-footer .btn-primary");
await click(".modal-footer button.edit-email");
assert.equal(find(".activate-new-email").val(), "current@example.com");
assert.equal(
find(".modal-footer .btn-primary:disabled").length,
1,
"must change email"
);
await fillIn(".activate-new-email", "different@example.com");
assert.equal(find(".modal-footer .btn-primary:disabled").length, 0);
await click(".modal-footer .btn-primary");
assert.equal(find(".modal-body b").text(), "different@example.com");
});
QUnit.test("second factor", assert => {
visit("/");
click("header .login-button");
QUnit.test("second factor", async assert => {
await visit("/");
await click("header .login-button");
andThen(() => {
assert.ok(exists(".login-modal"), "it shows the login modal");
});
assert.ok(exists(".login-modal"), "it shows the login modal");
fillIn("#login-account-name", "eviltrout");
fillIn("#login-account-password", "need-second-factor");
click(".modal-footer .btn-primary");
await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "need-second-factor");
await click(".modal-footer .btn-primary");
andThen(() => {
assert.not(exists("#modal-alert:visible"), "it hides the login error");
assert.not(
exists("#credentials:visible"),
"it hides the username and password prompt"
);
assert.ok(
exists("#second-factor:visible"),
"it displays the second factor prompt"
);
assert.not(
exists(".modal-footer .btn-primary:disabled"),
"enables the login button"
);
});
assert.not(exists("#modal-alert:visible"), "it hides the login error");
assert.not(
exists("#credentials:visible"),
"it hides the username and password prompt"
);
assert.ok(
exists("#second-factor:visible"),
"it displays the second factor prompt"
);
assert.not(
exists(".modal-footer .btn-primary:disabled"),
"enables the login button"
);
fillIn("#login-second-factor", "123456");
click(".modal-footer .btn-primary");
await fillIn("#login-second-factor", "123456");
await click(".modal-footer .btn-primary");
andThen(() => {
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"disables the login button"
);
});
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"disables the login button"
);
});
QUnit.test("create account", assert => {
visit("/");
click("header .sign-up-button");
QUnit.test("create account", async assert => {
await visit("/");
await click("header .sign-up-button");
andThen(() => {
assert.ok(exists(".create-account"), "it shows the create account modal");
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"create account is disabled at first"
);
});
assert.ok(exists(".create-account"), "it shows the create account modal");
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"create account is disabled at first"
);
fillIn("#new-account-name", "Dr. Good Tuna");
fillIn("#new-account-password", "cool password bro");
await fillIn("#new-account-name", "Dr. Good Tuna");
await fillIn("#new-account-password", "cool password bro");
// Check username
fillIn("#new-account-email", "good.tuna@test.com");
fillIn("#new-account-username", "taken");
andThen(() => {
assert.ok(
exists("#username-validation.bad"),
"the username validation is bad"
);
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"create account is still disabled"
);
});
await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-username", "taken");
assert.ok(
exists("#username-validation.bad"),
"the username validation is bad"
);
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"create account is still disabled"
);
fillIn("#new-account-username", "goodtuna");
andThen(() => {
assert.ok(
exists("#username-validation.good"),
"the username validation is good"
);
assert.not(
exists(".modal-footer .btn-primary:disabled"),
"create account is enabled"
);
});
await fillIn("#new-account-username", "goodtuna");
assert.ok(
exists("#username-validation.good"),
"the username validation is good"
);
assert.not(
exists(".modal-footer .btn-primary:disabled"),
"create account is enabled"
);
click(".modal-footer .btn-primary");
andThen(() => {
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"create account is disabled"
);
});
await click(".modal-footer .btn-primary");
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"create account is disabled"
);
});
QUnit.test("second factor backup - valid token", assert => {
visit("/");
click("header .login-button");
fillIn("#login-account-name", "eviltrout");
fillIn("#login-account-password", "need-second-factor");
click(".modal-footer .btn-primary");
click(".login-modal .toggle-second-factor-method");
fillIn("#login-second-factor", "123456");
click(".modal-footer .btn-primary");
QUnit.test("second factor backup - valid token", async assert => {
await visit("/");
await click("header .login-button");
await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "need-second-factor");
await click(".modal-footer .btn-primary");
await click(".login-modal .toggle-second-factor-method");
await fillIn("#login-second-factor", "123456");
await click(".modal-footer .btn-primary");
andThen(() => {
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"it closes the modal when the code is valid"
);
});
assert.ok(
exists(".modal-footer .btn-primary:disabled"),
"it closes the modal when the code is valid"
);
});
QUnit.test("second factor backup - invalid token", assert => {
visit("/");
click("header .login-button");
fillIn("#login-account-name", "eviltrout");
fillIn("#login-account-password", "need-second-factor");
click(".modal-footer .btn-primary");
click(".login-modal .toggle-second-factor-method");
fillIn("#login-second-factor", "something");
click(".modal-footer .btn-primary");
QUnit.test("second factor backup - invalid token", async assert => {
await visit("/");
await click("header .login-button");
await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "need-second-factor");
await click(".modal-footer .btn-primary");
await click(".login-modal .toggle-second-factor-method");
await fillIn("#login-second-factor", "something");
await click(".modal-footer .btn-primary");
andThen(() => {
assert.ok(
exists("#modal-alert:visible"),
"it shows an error when the code is invalid"
);
});
assert.ok(
exists("#modal-alert:visible"),
"it shows an error when the code is invalid"
);
});

View File

@ -1,37 +1,27 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Static");
QUnit.test("Static Pages", assert => {
visit("/faq");
andThen(() => {
assert.ok($("body.static-faq").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
});
QUnit.test("Static Pages", async assert => {
await visit("/faq");
assert.ok($("body.static-faq").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
visit("/guidelines");
andThen(() => {
assert.ok($("body.static-guidelines").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
});
await visit("/guidelines");
assert.ok($("body.static-guidelines").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
visit("/tos");
andThen(() => {
assert.ok($("body.static-tos").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
});
await visit("/tos");
assert.ok($("body.static-tos").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
visit("/privacy");
andThen(() => {
assert.ok($("body.static-privacy").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
});
await visit("/privacy");
assert.ok($("body.static-privacy").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
visit("/login");
andThen(() => {
assert.equal(
currentPath(),
"discovery.latest",
"it redirects them to latest unless `login_required`"
);
});
await visit("/login");
assert.equal(
currentPath(),
"discovery.latest",
"it redirects them to latest unless `login_required`"
);
});

View File

@ -1,48 +1,38 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Topic - Anonymous");
QUnit.test("Enter a Topic", assert => {
visit("/t/internationalization-localization/280/1");
andThen(() => {
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(exists("#topic .cooked"), "The topic has cooked posts");
assert.ok(
find(".shared-draft-notice").length === 0,
"no shared draft unless there's a dest category id"
);
});
QUnit.test("Enter a Topic", async assert => {
await visit("/t/internationalization-localization/280/1");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(exists("#topic .cooked"), "The topic has cooked posts");
assert.ok(
find(".shared-draft-notice").length === 0,
"no shared draft unless there's a dest category id"
);
});
QUnit.test("Enter without an id", assert => {
visit("/t/internationalization-localization");
andThen(() => {
assert.ok(exists("#topic"), "The topic was rendered");
});
QUnit.test("Enter without an id", async assert => {
await visit("/t/internationalization-localization");
assert.ok(exists("#topic"), "The topic was rendered");
});
QUnit.test("Enter a 404 topic", assert => {
visit("/t/not-found/404");
andThen(() => {
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(
find(".not-found").text() === "not found",
"it renders the error message"
);
});
QUnit.test("Enter a 404 topic", async assert => {
await visit("/t/not-found/404");
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(
find(".not-found").text() === "not found",
"it renders the error message"
);
});
QUnit.test("Enter without access", assert => {
visit("/t/i-dont-have-access/403");
andThen(() => {
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
QUnit.test("Enter without access", async assert => {
await visit("/t/i-dont-have-access/403");
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
QUnit.test("Enter with 500 errors", assert => {
visit("/t/throws-error/500");
andThen(() => {
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
QUnit.test("Enter with 500 errors", async assert => {
await visit("/t/throws-error/500");
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});

View File

@ -1,67 +1,55 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Topic Discovery");
QUnit.test("Visit Discovery Pages", assert => {
visit("/");
andThen(() => {
assert.ok($("body.navigation-topics").length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
});
QUnit.test("Visit Discovery Pages", async assert => {
await visit("/");
assert.ok($("body.navigation-topics").length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
visit("/c/bug");
andThen(() => {
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.ok(!exists(".category-list"), "doesn't render subcategories");
assert.ok(
$("body.category-bug").length,
"has a custom css class for the category id on the body"
);
});
await visit("/c/bug");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.ok(!exists(".category-list"), "doesn't render subcategories");
assert.ok(
$("body.category-bug").length,
"has a custom css class for the category id on the body"
);
visit("/categories");
andThen(() => {
assert.ok($("body.navigation-categories").length, "has the body class");
assert.ok(
$("body.category-bug").length === 0,
"removes the custom category class"
);
assert.ok(exists(".category"), "has a list of categories");
assert.ok(
$("body.categories-list").length,
"has a custom class to indicate categories"
);
});
await visit("/categories");
assert.ok($("body.navigation-categories").length, "has the body class");
assert.ok(
$("body.category-bug").length === 0,
"removes the custom category class"
);
assert.ok(exists(".category"), "has a list of categories");
assert.ok(
$("body.categories-list").length,
"has a custom class to indicate categories"
);
visit("/top");
andThen(() => {
assert.ok(
$("body.categories-list").length === 0,
"removes the `categories-list` class"
);
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
});
await visit("/top");
assert.ok(
$("body.categories-list").length === 0,
"removes the `categories-list` class"
);
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
visit("/c/feature");
andThen(() => {
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(
exists(".category-boxes"),
"The list of subcategories were rendered with box style"
);
});
await visit("/c/feature");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(
exists(".category-boxes"),
"The list of subcategories were rendered with box style"
);
visit("/c/dev");
andThen(() => {
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(
exists(".category-boxes-with-topics"),
"The list of subcategories were rendered with box-with-featured-topics style"
);
assert.ok(
exists(".category-boxes-with-topics .featured-topics"),
"The featured topics are there too"
);
});
await visit("/c/dev");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(
exists(".category-boxes-with-topics"),
"The list of subcategories were rendered with box-with-featured-topics style"
);
assert.ok(
exists(".category-boxes-with-topics .featured-topics"),
"The featured topics are there too"
);
});

View File

@ -1,10 +1,8 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Unknown");
QUnit.test("Unknown URL", assert => {
QUnit.test("Unknown URL", async assert => {
assert.expect(1);
visit("/url-that-doesn't-exist");
andThen(() => {
assert.ok(exists(".page-not-found"), "The not found content is present");
});
await visit("/url-that-doesn't-exist");
assert.ok(exists(".page-not-found"), "The not found content is present");
});

View File

@ -2,57 +2,45 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("User Anonymous");
function hasStream(assert) {
andThen(() => {
assert.ok(exists(".user-main .about"), "it has the about section");
assert.ok(count(".user-stream .item") > 0, "it has stream items");
});
assert.ok(exists(".user-main .about"), "it has the about section");
assert.ok(count(".user-stream .item") > 0, "it has stream items");
}
function hasTopicList(assert) {
andThen(() => {
assert.equal(count(".user-stream .item"), 0, "has no stream displayed");
assert.ok(count(".topic-list tr") > 0, "it has a topic list");
});
assert.equal(count(".user-stream .item"), 0, "has no stream displayed");
assert.ok(count(".topic-list tr") > 0, "it has a topic list");
}
QUnit.test("Root URL", assert => {
visit("/u/eviltrout");
andThen(() => {
assert.ok($("body.user-summary-page").length, "has the body class");
assert.equal(currentPath(), "user.summary", "it defaults to summary");
});
QUnit.test("Root URL", async assert => {
await visit("/u/eviltrout");
assert.ok($("body.user-summary-page").length, "has the body class");
assert.equal(currentPath(), "user.summary", "it defaults to summary");
});
QUnit.test("Filters", assert => {
visit("/u/eviltrout/activity");
andThen(() => {
assert.ok($("body.user-activity-page").length, "has the body class");
});
QUnit.test("Filters", async assert => {
await visit("/u/eviltrout/activity");
assert.ok($("body.user-activity-page").length, "has the body class");
hasStream(assert);
visit("/u/eviltrout/activity/topics");
hasTopicList(assert);
await visit("/u/eviltrout/activity/topics");
await hasTopicList(assert);
visit("/u/eviltrout/activity/replies");
await visit("/u/eviltrout/activity/replies");
hasStream(assert);
});
QUnit.test("Badges", assert => {
visit("/u/eviltrout/badges");
andThen(() => {
assert.ok($("body.user-badges-page").length, "has the body class");
assert.ok(exists(".user-badges-list .badge-card"), "shows a badge");
});
QUnit.test("Badges", async assert => {
await visit("/u/eviltrout/badges");
assert.ok($("body.user-badges-page").length, "has the body class");
assert.ok(exists(".user-badges-list .badge-card"), "shows a badge");
});
QUnit.test("Restricted Routes", assert => {
visit("/u/eviltrout/preferences");
QUnit.test("Restricted Routes", async assert => {
await visit("/u/eviltrout/preferences");
andThen(() => {
assert.equal(
currentURL(),
"/u/eviltrout/activity",
"it redirects from preferences"
);
});
assert.equal(
currentURL(),
"/u/eviltrout/activity",
"it redirects from preferences"
);
});

View File

@ -2,13 +2,10 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("User Card");
QUnit.test("user card", assert => {
visit("/");
QUnit.test("user card", async assert => {
await visit("/");
assert.ok(invisible("#user-card"), "user card is invisible by default");
click("a[data-user-card=eviltrout]:first");
andThen(() => {
assert.ok(visible("#user-card"), "card should appear");
});
await click("a[data-user-card=eviltrout]:first");
assert.ok(visible("#user-card"), "card should appear");
});

View File

@ -2,53 +2,40 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("User", { loggedIn: true });
QUnit.test("Invites", assert => {
visit("/u/eviltrout/invited/pending");
andThen(() => {
assert.ok($("body.user-invites-page").length, "has the body class");
});
QUnit.test("Invites", async assert => {
await visit("/u/eviltrout/invited/pending");
assert.ok($("body.user-invites-page").length, "has the body class");
});
QUnit.test("Messages", assert => {
visit("/u/eviltrout/messages");
andThen(() => {
assert.ok($("body.user-messages-page").length, "has the body class");
});
QUnit.test("Messages", async assert => {
await visit("/u/eviltrout/messages");
assert.ok($("body.user-messages-page").length, "has the body class");
});
QUnit.test("Notifications", assert => {
visit("/u/eviltrout/notifications");
andThen(() => {
assert.ok($("body.user-notifications-page").length, "has the body class");
});
QUnit.test("Notifications", async assert => {
await visit("/u/eviltrout/notifications");
assert.ok($("body.user-notifications-page").length, "has the body class");
});
QUnit.test("Root URL - Viewing Self", assert => {
visit("/u/eviltrout");
andThen(() => {
assert.ok($("body.user-activity-page").length, "has the body class");
assert.equal(
currentPath(),
"user.userActivity.index",
"it defaults to activity"
);
assert.ok(exists(".container.viewing-self"), "has the viewing-self class");
});
QUnit.test("Root URL - Viewing Self", async assert => {
await visit("/u/eviltrout");
assert.ok($("body.user-activity-page").length, "has the body class");
assert.equal(
currentPath(),
"user.userActivity.index",
"it defaults to activity"
);
assert.ok(exists(".container.viewing-self"), "has the viewing-self class");
});
QUnit.test("Viewing Summary", assert => {
visit("/u/eviltrout/summary");
andThen(() => {
assert.ok(exists(".replies-section li a"), "replies");
assert.ok(exists(".topics-section li a"), "topics");
assert.ok(exists(".links-section li a"), "links");
assert.ok(exists(".replied-section .user-info"), "liked by");
assert.ok(exists(".liked-by-section .user-info"), "liked by");
assert.ok(exists(".liked-section .user-info"), "liked");
assert.ok(exists(".badges-section .badge-card"), "badges");
assert.ok(
exists(".top-categories-section .category-link"),
"top categories"
);
});
QUnit.test("Viewing Summary", async assert => {
await visit("/u/eviltrout/summary");
assert.ok(exists(".replies-section li a"), "replies");
assert.ok(exists(".topics-section li a"), "topics");
assert.ok(exists(".links-section li a"), "links");
assert.ok(exists(".replied-section .user-info"), "liked by");
assert.ok(exists(".liked-by-section .user-info"), "liked by");
assert.ok(exists(".liked-section .user-info"), "liked");
assert.ok(exists(".badges-section .badge-card"), "badges");
assert.ok(exists(".top-categories-section .category-link"), "top categories");
});