DEV: migrate acceptance tests to async await - badges, category, composer, customHTML

This commit is contained in:
Maja Komel
2018-07-19 11:40:42 +02:00
parent e8e9b5cea4
commit e36d1c72f1
10 changed files with 645 additions and 805 deletions

View File

@@ -2,17 +2,15 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Badges"); acceptance("Badges");
QUnit.test("Visit Badge Pages", assert => { QUnit.test("Visit Badge Pages", async assert => {
visit("/badges"); await visit("/badges");
andThen(() => {
assert.ok($("body.badges-page").length, "has body class"); assert.ok($("body.badges-page").length, "has body class");
assert.ok(exists(".badge-groups .badge-card"), "has a list of badges"); assert.ok(exists(".badge-groups .badge-card"), "has a list of badges");
});
visit("/badges/9/autobiographer"); await visit("/badges/9/autobiographer");
andThen(() => {
assert.ok(exists(".badge-card"), "has the badge in the listing"); assert.ok(exists(".badge-card"), "has the badge in the listing");
assert.ok(exists(".user-info"), "has the list of users with that badge"); assert.ok(exists(".user-info"), "has the list of users with that badge");
assert.ok(!exists(".badge-card:eq(0) script")); assert.ok(!exists(".badge-card:eq(0) script"));
}); });
});

View File

@@ -7,23 +7,20 @@ acceptance("CategoryChooser", {
} }
}); });
QUnit.test("does not display uncategorized if not allowed", assert => { QUnit.test("does not display uncategorized if not allowed", async assert => {
const categoryChooser = selectKit(".category-chooser"); const categoryChooser = selectKit(".category-chooser");
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
categoryChooser.expand(); categoryChooser.expandAwait();
andThen(() => {
assert.ok(categoryChooser.rowByIndex(0).name() !== "uncategorized"); assert.ok(categoryChooser.rowByIndex(0).name() !== "uncategorized");
}); });
});
QUnit.test("prefill category when category_id is set", assert => { QUnit.test("prefill category when category_id is set", async assert => {
visit("/new-topic?category_id=1"); await visit("/new-topic?category_id=1");
andThen(() => {
assert.equal( assert.equal(
selectKit(".category-chooser") selectKit(".category-chooser")
.header() .header()
@@ -31,4 +28,3 @@ QUnit.test("prefill category when category_id is set", assert => {
1 1
); );
}); });
});

View File

@@ -4,13 +4,12 @@ acceptance("Category Edit - security", {
loggedIn: true loggedIn: true
}); });
QUnit.test("default", assert => { QUnit.test("default", async assert => {
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
click("li.edit-category-security a"); await click("li.edit-category-security a");
andThen(() => {
const $permissionListItems = find(".permission-list li"); const $permissionListItems = find(".permission-list li");
const badgeName = $permissionListItems const badgeName = $permissionListItems
@@ -25,52 +24,46 @@ QUnit.test("default", assert => {
.text(); .text();
assert.equal(permission, "Create / Reply / See"); assert.equal(permission, "Create / Reply / See");
}); });
});
QUnit.test("removing a permission", assert => { QUnit.test("removing a permission", async assert => {
const availableGroups = selectKit(".available-groups"); const availableGroups = selectKit(".available-groups");
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
click("li.edit-category-security a"); await click("li.edit-category-security a");
click(".edit-category-tab-security .edit-permission"); await click(".edit-category-tab-security .edit-permission");
availableGroups.expand(); availableGroups.expand();
andThen(() => {
assert.notOk( assert.notOk(
availableGroups.rowByValue("everyone").exists(), availableGroups.rowByValue("everyone").exists(),
"everyone is already used and is not in the available groups" "everyone is already used and is not in the available groups"
); );
});
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(); availableGroups.expand();
andThen(() => {
assert.ok( assert.ok(
availableGroups.rowByValue("everyone").exists(), availableGroups.rowByValue("everyone").exists(),
"everyone has been removed and appears in the available groups" "everyone has been removed and appears in the available groups"
); );
}); });
});
QUnit.test("adding a permission", assert => { QUnit.test("adding a permission", async assert => {
const availableGroups = selectKit(".available-groups"); const availableGroups = selectKit(".available-groups");
const permissionSelector = selectKit(".permission-selector"); const permissionSelector = selectKit(".permission-selector");
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
click("li.edit-category-security a"); await click("li.edit-category-security a");
click(".edit-category-tab-security .edit-permission"); await click(".edit-category-tab-security .edit-permission");
availableGroups.expand().selectRowByValue("staff"); availableGroups.expand().selectRowByValue("staff");
permissionSelector.expand().selectRowByValue("2"); permissionSelector.expand().selectRowByValue("2");
click(".edit-category-tab-security .add-permission"); await click(".edit-category-tab-security .add-permission");
andThen(() => {
const $addedPermissionItem = find( const $addedPermissionItem = find(
".edit-category-tab-security .permission-list li:nth-child(2)" ".edit-category-tab-security .permission-list li:nth-child(2)"
); );
@@ -81,32 +74,28 @@ QUnit.test("adding a permission", assert => {
const permission = $addedPermissionItem.find(".permission").text(); const permission = $addedPermissionItem.find(".permission").text();
assert.equal(permission, "Reply / See"); assert.equal(permission, "Reply / See");
}); });
});
QUnit.test("adding a previously removed permission", assert => { QUnit.test("adding a previously removed permission", async assert => {
const availableGroups = selectKit(".available-groups"); const availableGroups = selectKit(".available-groups");
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
click("li.edit-category-security a"); await await click("li.edit-category-security a");
click(".edit-category-tab-security .edit-permission"); await click(".edit-category-tab-security .edit-permission");
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"
); );
andThen(() => {
assert.equal( assert.equal(
find(".edit-category-tab-security .permission-list li").length, find(".edit-category-tab-security .permission-list li").length,
0, 0,
"it removes the permission from the list" "it removes the permission from the list"
); );
});
availableGroups.expand().selectRowByValue("everyone"); availableGroups.expand().selectRowByValue("everyone");
click(".edit-category-tab-security .add-permission"); await click(".edit-category-tab-security .add-permission");
andThen(() => {
assert.equal( assert.equal(
find(".edit-category-tab-security .permission-list li").length, find(".edit-category-tab-security .permission-list li").length,
1, 1,
@@ -127,4 +116,3 @@ QUnit.test("adding a previously removed permission", assert => {
.text(); .text();
assert.equal(permission, "Create / Reply / See"); assert.equal(permission, "Create / Reply / See");
}); });
});

View File

@@ -6,27 +6,22 @@ acceptance("Category Edit", {
settings: { email_in: true } settings: { email_in: true }
}); });
QUnit.test("Can open the category modal", assert => { QUnit.test("Can open the category modal", async assert => {
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
andThen(() => {
assert.ok(visible(".d-modal"), "it pops up a modal"); assert.ok(visible(".d-modal"), "it pops up a modal");
});
click("a.close"); await click("a.close");
andThen(() => {
assert.ok(!visible(".d-modal"), "it closes the modal"); assert.ok(!visible(".d-modal"), "it closes the modal");
}); });
});
QUnit.test("Change the category color", assert => { QUnit.test("Change the category color", async assert => {
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
fillIn("#edit-text-color", "#ff0000"); await fillIn("#edit-text-color", "#ff0000");
click("#save-category"); await click("#save-category");
andThen(() => {
assert.ok(!visible(".d-modal"), "it closes the modal"); assert.ok(!visible(".d-modal"), "it closes the modal");
assert.equal( assert.equal(
DiscourseURL.redirectedTo, DiscourseURL.redirectedTo,
@@ -34,16 +29,14 @@ QUnit.test("Change the category color", assert => {
"it does one of the rare full page redirects" "it does one of the rare full page redirects"
); );
}); });
});
QUnit.test("Change the topic template", assert => { QUnit.test("Change the topic template", async assert => {
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
click(".edit-category-topic-template"); await click(".edit-category-topic-template");
fillIn(".d-editor-input", "this is the new topic template"); await fillIn(".d-editor-input", "this is the new topic template");
click("#save-category"); await click("#save-category");
andThen(() => {
assert.ok(!visible(".d-modal"), "it closes the modal"); assert.ok(!visible(".d-modal"), "it closes the modal");
assert.equal( assert.equal(
DiscourseURL.redirectedTo, DiscourseURL.redirectedTo,
@@ -51,20 +44,17 @@ QUnit.test("Change the topic template", assert => {
"it does one of the rare full page redirects" "it does one of the rare full page redirects"
); );
}); });
});
QUnit.test("Error Saving", assert => { QUnit.test("Error Saving", async assert => {
visit("/c/bug"); await visit("/c/bug");
click(".edit-category"); await click(".edit-category");
click(".edit-category-settings"); await click(".edit-category-settings");
fillIn(".email-in", "duplicate@example.com"); await fillIn(".email-in", "duplicate@example.com");
click("#save-category"); await click("#save-category");
andThen(() => {
assert.ok(visible("#modal-alert")); assert.ok(visible("#modal-alert"));
assert.equal(find("#modal-alert").html(), "duplicate email"); assert.equal(find("#modal-alert").html(), "duplicate email");
}); });
});
QUnit.test("Subcategory list settings", async assert => { QUnit.test("Subcategory list settings", async assert => {
const categoryChooser = selectKit( const categoryChooser = selectKit(

View File

@@ -2,12 +2,11 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Category hashtag", { loggedIn: true }); acceptance("Category hashtag", { loggedIn: true });
QUnit.test("category hashtag is cooked properly", assert => { QUnit.test("category hashtag 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 category hashtag #bug"); await fillIn(".d-editor-input", "this is a category hashtag #bug");
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")
@@ -15,10 +14,8 @@ QUnit.test("category hashtag is cooked properly", assert => {
.trim(), .trim(),
'<p>this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a></p>' '<p>this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a></p>'
); );
});
click("#reply-control .btn.create"); await click("#reply-control .btn.create");
andThen(() => {
assert.equal( assert.equal(
find(".topic-post:last .cooked p") find(".topic-post:last .cooked p")
.html() .html()
@@ -26,4 +23,3 @@ QUnit.test("category hashtag is cooked properly", assert => {
'this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a>' 'this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a>'
); );
}); });
});

View File

@@ -7,14 +7,11 @@ acceptance("Composer", {
} }
}); });
QUnit.test("Tests the Composer controls", assert => { QUnit.test("Tests the Composer controls", async assert => {
visit("/"); await visit("/");
andThen(() => {
assert.ok(exists("#create-topic"), "the create button is visible"); assert.ok(exists("#create-topic"), "the create button is visible");
});
click("#create-topic"); await click("#create-topic");
andThen(() => {
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok( assert.ok(
exists(".title-input .popup-tip.bad.hide"), exists(".title-input .popup-tip.bad.hide"),
@@ -24,26 +21,20 @@ QUnit.test("Tests the Composer controls", assert => {
exists(".d-editor-textarea-wrapper .popup-tip.bad.hide"), exists(".d-editor-textarea-wrapper .popup-tip.bad.hide"),
"body errors are hidden by default" "body errors are hidden by default"
); );
});
click("a.toggle-preview"); await click("a.toggle-preview");
andThen(() => {
assert.ok( assert.ok(
!exists(".d-editor-preview:visible"), !exists(".d-editor-preview:visible"),
"clicking the toggle hides the preview" "clicking the toggle hides the preview"
); );
});
click("a.toggle-preview"); await click("a.toggle-preview");
andThen(() => {
assert.ok( assert.ok(
exists(".d-editor-preview:visible"), exists(".d-editor-preview:visible"),
"clicking the toggle shows the preview again" "clicking the toggle shows the preview again"
); );
});
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.ok( assert.ok(
!exists(".title-input .popup-tip.bad.hide"), !exists(".title-input .popup-tip.bad.hide"),
"it shows the empty title error" "it shows the empty title error"
@@ -52,15 +43,11 @@ QUnit.test("Tests the Composer controls", assert => {
!exists(".d-editor-wrapper .popup-tip.bad.hide"), !exists(".d-editor-wrapper .popup-tip.bad.hide"),
"it shows the empty body error" "it shows the empty body error"
); );
});
fillIn("#reply-title", "this is my new topic title"); await fillIn("#reply-title", "this is my new topic title");
andThen(() => {
assert.ok(exists(".title-input .popup-tip.good"), "the title is now good"); assert.ok(exists(".title-input .popup-tip.good"), "the title is now good");
});
fillIn(".d-editor-input", "this is the *content* of a post"); await fillIn(".d-editor-input", "this is the *content* of a post");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -72,9 +59,7 @@ QUnit.test("Tests the Composer controls", assert => {
exists(".d-editor-textarea-wrapper .popup-tip.good"), exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good" "the body is now good"
); );
});
andThen(() => {
const textarea = find("#reply-control .d-editor-input")[0]; const textarea = find("#reply-control .d-editor-input")[0];
textarea.selectionStart = textarea.value.length; textarea.selectionStart = textarea.value.length;
textarea.selectionEnd = textarea.value.length; textarea.selectionEnd = textarea.value.length;
@@ -86,10 +71,8 @@ QUnit.test("Tests the Composer controls", assert => {
event[mac ? "metaKey" : "ctrlKey"] = true; event[mac ? "metaKey" : "ctrlKey"] = true;
event.keyCode = 66; event.keyCode = 66;
textarea.dispatchEvent(event); Ember.run(() => textarea.dispatchEvent(event));
});
andThen(() => {
const example = I18n.t(`composer.bold_text`); const example = I18n.t(`composer.bold_text`);
assert.equal( assert.equal(
find("#reply-control .d-editor-input") find("#reply-control .d-editor-input")
@@ -98,161 +81,119 @@ QUnit.test("Tests the Composer controls", assert => {
`this is the *content* of a post**${example}**`, `this is the *content* of a post**${example}**`,
"it supports keyboard shortcuts" "it supports keyboard shortcuts"
); );
});
click("#reply-control a.cancel"); await click("#reply-control a.cancel");
andThen(() => {
assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog"); assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog");
});
click(".modal-footer a:eq(1)"); await click(".modal-footer a:eq(1)");
andThen(() => {
assert.ok(!exists(".bootbox.modal"), "the confirmation can be cancelled"); assert.ok(!exists(".bootbox.modal"), "the confirmation can be cancelled");
}); });
});
QUnit.test("Create a topic with server side errors", assert => { QUnit.test("Create a topic with server side errors", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "this title triggers an error"); await fillIn("#reply-title", "this title triggers an error");
fillIn(".d-editor-input", "this is the *content* of a post"); await fillIn(".d-editor-input", "this is the *content* of a post");
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.ok(exists(".bootbox.modal"), "it pops up an error message"); assert.ok(exists(".bootbox.modal"), "it pops up an error message");
}); await click(".bootbox.modal a.btn-primary");
click(".bootbox.modal a.btn-primary");
andThen(() => {
assert.ok(!exists(".bootbox.modal"), "it dismisses the error"); assert.ok(!exists(".bootbox.modal"), "it dismisses the error");
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
}); });
});
QUnit.test("Create a Topic", assert => { QUnit.test("Create a Topic", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "Internationalization Localization"); await fillIn("#reply-title", "Internationalization Localization");
fillIn(".d-editor-input", "this is the *content* of a new topic post"); await fillIn(".d-editor-input", "this is the *content* of a new topic post");
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.equal( assert.equal(
currentURL(), currentURL(),
"/t/internationalization-localization/280", "/t/internationalization-localization/280",
"it transitions to the newly created topic URL" "it transitions to the newly created topic URL"
); );
}); });
});
QUnit.test("Create an enqueued Topic", assert => { QUnit.test("Create an enqueued Topic", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "Internationalization Localization"); await fillIn("#reply-title", "Internationalization Localization");
fillIn(".d-editor-input", "enqueue this content please"); await fillIn(".d-editor-input", "enqueue this content please");
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.ok(visible(".d-modal"), "it pops up a modal"); assert.ok(visible(".d-modal"), "it pops up a modal");
assert.equal(currentURL(), "/", "it doesn't change routes"); assert.equal(currentURL(), "/", "it doesn't change routes");
});
click(".modal-footer button"); await click(".modal-footer button");
andThen(() => {
assert.ok(invisible(".d-modal"), "the modal can be dismissed"); assert.ok(invisible(".d-modal"), "the modal can be dismissed");
}); });
});
QUnit.test("Create a Reply", assert => { QUnit.test("Create a Reply", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
andThen(() => {
assert.ok( assert.ok(
!exists("article[data-post-id=12345]"), !exists("article[data-post-id=12345]"),
"the post is not in the DOM" "the post is not in the DOM"
); );
});
click("#topic-footer-buttons .btn.create"); await click("#topic-footer-buttons .btn.create");
andThen(() => {
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok( assert.ok(!exists("#reply-title"), "there is no title since this is a reply");
!exists("#reply-title"),
"there is no title since this is a reply"
);
});
fillIn(".d-editor-input", "this is the content of my reply"); await fillIn(".d-editor-input", "this is the content of my reply");
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.equal( assert.equal(
find(".cooked:last p").text(), find(".cooked:last p").text(),
"this is the content of my reply" "this is the content of my reply"
); );
}); });
});
QUnit.test("Posting on a different topic", assert => { QUnit.test("Posting on a different topic", 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 the content for a different topic"); await fillIn(".d-editor-input", "this is the content for a different topic");
visit("/t/1-3-0beta9-no-rate-limit-popups/28830"); await visit("/t/1-3-0beta9-no-rate-limit-popups/28830");
andThen(function() {
assert.equal(currentURL(), "/t/1-3-0beta9-no-rate-limit-popups/28830"); assert.equal(currentURL(), "/t/1-3-0beta9-no-rate-limit-popups/28830");
}); await click("#reply-control button.create");
click("#reply-control button.create");
andThen(function() {
assert.ok(visible(".reply-where-modal"), "it pops up a modal"); assert.ok(visible(".reply-where-modal"), "it pops up a modal");
});
click(".btn-reply-here"); await click(".btn-reply-here");
andThen(() => {
assert.equal( assert.equal(
find(".cooked:last p").text(), find(".cooked:last p").text(),
"this is the content for a different topic" "this is the content for a different topic"
); );
}); });
});
QUnit.test("Create an enqueued Reply", assert => { QUnit.test("Create an enqueued Reply", 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");
andThen(() => {
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok( assert.ok(!exists("#reply-title"), "there is no title since this is a reply");
!exists("#reply-title"),
"there is no title since this is a reply"
);
});
fillIn(".d-editor-input", "enqueue this content please"); await fillIn(".d-editor-input", "enqueue this content please");
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.ok( assert.ok(
find(".cooked:last p").text() !== "enqueue this content please", find(".cooked:last p").text() !== "enqueue this content please",
"it doesn't insert the post" "it doesn't insert the post"
); );
});
andThen(() => {
assert.ok(visible(".d-modal"), "it pops up a modal"); assert.ok(visible(".d-modal"), "it pops up a modal");
});
click(".modal-footer button"); await click(".modal-footer button");
andThen(() => {
assert.ok(invisible(".d-modal"), "the modal can be dismissed"); assert.ok(invisible(".d-modal"), "the modal can be dismissed");
}); });
});
QUnit.test("Edit the first post", assert => { QUnit.test("Edit the first post", async assert => {
visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
assert.ok( assert.ok(
!exists(".topic-post:eq(0) .post-info.edits"), !exists(".topic-post:eq(0) .post-info.edits"),
"it has no edits icon at first" "it has no edits icon at first"
); );
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.edit"); await click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -260,12 +201,10 @@ QUnit.test("Edit the first post", assert => {
0, 0,
"it populates the input with the post text" "it populates the input with the post text"
); );
});
fillIn(".d-editor-input", "This is the new text for the post"); await fillIn(".d-editor-input", "This is the new text for the post");
fillIn("#reply-title", "This is the new text for the title"); await fillIn("#reply-title", "This is the new text for the title");
click("#reply-control button.create"); await click("#reply-control button.create");
andThen(() => {
assert.ok(!exists(".d-editor-input"), "it closes the composer"); assert.ok(!exists(".d-editor-input"), "it closes the composer");
assert.ok( assert.ok(
exists(".topic-post:eq(0) .post-info.edits"), exists(".topic-post:eq(0) .post-info.edits"),
@@ -284,13 +223,11 @@ QUnit.test("Edit the first post", assert => {
"it updates the post" "it updates the post"
); );
}); });
});
QUnit.test("Composer can switch between edits", assert => { QUnit.test("Composer can switch between edits", async assert => {
visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.edit"); await click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -298,9 +235,7 @@ QUnit.test("Composer can switch between edits", assert => {
0, 0,
"it populates the input with the post text" "it populates the input with the post text"
); );
}); await click(".topic-post:eq(1) button.edit");
click(".topic-post:eq(1) button.edit");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -309,19 +244,18 @@ QUnit.test("Composer can switch between edits", assert => {
"it populates the input with the post text" "it populates the input with the post text"
); );
}); });
});
QUnit.test("Composer with dirty edit can toggle to another edit", assert => { QUnit.test(
visit("/t/this-is-a-test-topic/9"); "Composer with dirty edit can toggle to another edit",
async assert => {
await visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.edit"); await click(".topic-post:eq(0) button.edit");
fillIn(".d-editor-input", "This is a dirty reply"); await fillIn(".d-editor-input", "This is a dirty reply");
click(".topic-post:eq(1) button.edit"); await click(".topic-post:eq(1) button.edit");
andThen(() => {
assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog"); assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog");
});
click(".modal-footer a:eq(0)"); await click(".modal-footer a:eq(0)");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -329,14 +263,13 @@ QUnit.test("Composer with dirty edit can toggle to another edit", assert => {
0, 0,
"it populates the input with the post text" "it populates the input with the post text"
); );
}); }
}); );
QUnit.test("Composer can toggle between edit and reply", assert => { QUnit.test("Composer can toggle between edit and reply", async assert => {
visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.edit"); await click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -344,13 +277,9 @@ QUnit.test("Composer can toggle between edit and reply", assert => {
0, 0,
"it populates the input with the post text" "it populates the input with the post text"
); );
}); await click(".topic-post:eq(0) button.reply");
click(".topic-post:eq(0) button.reply");
andThen(() => {
assert.equal(find(".d-editor-input").val(), "", "it clears the input"); assert.equal(find(".d-editor-input").val(), "", "it clears the input");
}); await click(".topic-post:eq(0) button.edit");
click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -359,77 +288,68 @@ QUnit.test("Composer can toggle between edit and reply", assert => {
"it populates the input with the post text" "it populates the input with the post text"
); );
}); });
});
QUnit.test("Composer can toggle between reply and createTopic", assert => { QUnit.test(
visit("/t/this-is-a-test-topic/9"); "Composer can toggle between reply and createTopic",
click(".topic-post:eq(0) button.reply"); async assert => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
selectKit(".toolbar-popup-menu-options") await selectKit(".toolbar-popup-menu-options").expandAwait();
.expand() await selectKit(".toolbar-popup-menu-options").selectRowByValueAwait(
.selectRowByValue("toggleWhisper"); "toggleWhisper"
);
andThen(() => {
assert.ok( assert.ok(
find(".composer-fields .whisper") find(".composer-fields .whisper")
.text() .text()
.indexOf(I18n.t("composer.whisper")) > 0, .indexOf(I18n.t("composer.whisper")) > 0,
"it sets the post type to whisper" "it sets the post type to whisper"
); );
});
visit("/"); await visit("/");
andThen(() => {
assert.ok(exists("#create-topic"), "the create topic button is visible"); assert.ok(exists("#create-topic"), "the create topic button is visible");
});
click("#create-topic"); await click("#create-topic");
andThen(() => {
assert.ok( assert.ok(
find(".composer-fields .whisper") find(".composer-fields .whisper")
.text() .text()
.indexOf(I18n.t("composer.whisper")) === -1, .indexOf(I18n.t("composer.whisper")) === -1,
"it should reset the state of the composer's model" "it should reset the state of the composer's model"
); );
});
selectKit(".toolbar-popup-menu-options") await selectKit(".toolbar-popup-menu-options").expandAwait();
.expand() await selectKit(".toolbar-popup-menu-options").selectRowByValueAwait(
.selectRowByValue("toggleInvisible"); "toggleInvisible"
);
andThen(() => {
assert.ok( assert.ok(
find(".composer-fields .whisper") find(".composer-fields .whisper")
.text() .text()
.indexOf(I18n.t("composer.unlist")) > 0, .indexOf(I18n.t("composer.unlist")) > 0,
"it sets the topic to unlisted" "it sets the topic to unlisted"
); );
});
visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.reply"); await click(".topic-post:eq(0) button.reply");
andThen(() => {
assert.ok( assert.ok(
find(".composer-fields .whisper") find(".composer-fields .whisper")
.text() .text()
.indexOf(I18n.t("composer.unlist")) === -1, .indexOf(I18n.t("composer.unlist")) === -1,
"it should reset the state of the composer's model" "it should reset the state of the composer's model"
); );
}); }
}); );
QUnit.test("Composer with dirty reply can toggle to edit", assert => { QUnit.test("Composer with dirty reply can toggle to edit", async assert => {
visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.reply"); await click(".topic-post:eq(0) button.reply");
fillIn(".d-editor-input", "This is a dirty reply"); await fillIn(".d-editor-input", "This is a dirty reply");
click(".topic-post:eq(0) button.edit"); await click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog"); assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog");
}); await click(".modal-footer a:eq(0)");
click(".modal-footer a:eq(0)");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -438,20 +358,18 @@ QUnit.test("Composer with dirty reply can toggle to edit", assert => {
"it populates the input with the post text" "it populates the input with the post text"
); );
}); });
});
QUnit.test("Composer draft with dirty reply can toggle to edit", assert => { QUnit.test(
visit("/t/this-is-a-test-topic/9"); "Composer draft with dirty reply can toggle to edit",
async assert => {
await visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.reply"); await click(".topic-post:eq(0) button.reply");
fillIn(".d-editor-input", "This is a dirty reply"); await fillIn(".d-editor-input", "This is a dirty reply");
click(".toggler"); await click(".toggler");
click(".topic-post:eq(0) button.edit"); await click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog"); assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog");
}); await click(".modal-footer a:eq(0)");
click(".modal-footer a:eq(0)");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-input") find(".d-editor-input")
.val() .val()
@@ -459,8 +377,8 @@ QUnit.test("Composer draft with dirty reply can toggle to edit", assert => {
0, 0,
"it populates the input with the post text" "it populates the input with the post text"
); );
}); }
}); );
acceptance("Composer and uncategorized is not allowed", { acceptance("Composer and uncategorized is not allowed", {
loggedIn: true, loggedIn: true,
@@ -470,12 +388,11 @@ acceptance("Composer and uncategorized is not allowed", {
} }
}); });
QUnit.test("Disable body until category is selected", assert => { QUnit.test("Disable body until category is selected", async assert => {
replaceCurrentUser({ admin: false, staff: false, trust_level: 1 }); replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
andThen(() => {
assert.ok(exists(".d-editor-input"), "the composer input is visible"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok( assert.ok(
exists(".title-input .popup-tip.bad.hide"), exists(".title-input .popup-tip.bad.hide"),
@@ -489,26 +406,23 @@ QUnit.test("Disable body until category is selected", assert => {
exists(".d-editor-textarea-wrapper.disabled"), exists(".d-editor-textarea-wrapper.disabled"),
"textarea is disabled" "textarea is disabled"
); );
});
const categoryChooser = selectKit(".category-chooser"); const categoryChooser = selectKit(".category-chooser");
categoryChooser.expand().selectRowByValue(2); await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait(2);
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0, find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled" "textarea is enabled"
); );
});
fillIn(".d-editor-input", "Now I can type stuff"); await fillIn(".d-editor-input", "Now I can type stuff");
categoryChooser.expand().selectRowByValue("__none__"); await categoryChooser.expandAwait();
await categoryChooser.selectRowByValue("__none__");
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0, find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is still enabled" "textarea is still enabled"
); );
}); });
});

View File

@@ -9,11 +9,10 @@ acceptance("Composer topic featured links", {
} }
}); });
QUnit.test("onebox with title", assert => { QUnit.test("onebox with title", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "http://www.example.com/has-title.html"); await fillIn("#reply-title", "http://www.example.com/has-title.html");
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -31,13 +30,11 @@ QUnit.test("onebox with title", assert => {
"title is from the oneboxed article" "title is from the oneboxed article"
); );
}); });
});
QUnit.test("onebox result doesn't include a title", assert => { QUnit.test("onebox result doesn't include a title", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "http://www.example.com/no-title.html"); await fillIn("#reply-title", "http://www.example.com/no-title.html");
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -55,13 +52,11 @@ QUnit.test("onebox result doesn't include a title", assert => {
"title is unchanged" "title is unchanged"
); );
}); });
});
QUnit.test("no onebox result", assert => { QUnit.test("no onebox result", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "http://www.example.com/nope-onebox.html"); await fillIn("#reply-title", "http://www.example.com/nope-onebox.html");
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -79,14 +74,12 @@ QUnit.test("no onebox result", assert => {
"title is unchanged" "title is unchanged"
); );
}); });
});
QUnit.test("ignore internal links", assert => { QUnit.test("ignore internal links", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
const title = "http://" + window.location.hostname + "/internal-page.html"; const title = "http://" + window.location.hostname + "/internal-page.html";
fillIn("#reply-title", title); await fillIn("#reply-title", title);
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -102,16 +95,14 @@ QUnit.test("ignore internal links", assert => {
); );
assert.equal(find(".title-input input").val(), title, "title is unchanged"); assert.equal(find(".title-input input").val(), title, "title is unchanged");
}); });
});
QUnit.test("link is longer than max title length", assert => { QUnit.test("link is longer than max title length", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn( await fillIn(
"#reply-title", "#reply-title",
"http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html" "http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"
); );
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -129,13 +120,11 @@ QUnit.test("link is longer than max title length", assert => {
"title is from the oneboxed article" "title is from the oneboxed article"
); );
}); });
});
QUnit.test("onebox with title but extra words in title field", assert => { QUnit.test("onebox with title but extra words in title field", async assert => {
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
fillIn("#reply-title", "http://www.example.com/has-title.html test"); await fillIn("#reply-title", "http://www.example.com/has-title.html test");
andThen(() => {
assert.equal( assert.equal(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -155,7 +144,6 @@ QUnit.test("onebox with title but extra words in title field", assert => {
"title is unchanged" "title is unchanged"
); );
}); });
});
acceptance("Composer topic featured links when uncategorized is not allowed", { acceptance("Composer topic featured links when uncategorized is not allowed", {
loggedIn: true, loggedIn: true,
@@ -167,19 +155,16 @@ acceptance("Composer topic featured links when uncategorized is not allowed", {
} }
}); });
QUnit.test("Pasting a link enables the text input area", assert => { QUnit.test("Pasting a link enables the text input area", async assert => {
replaceCurrentUser({ admin: false, staff: false, trust_level: 1 }); replaceCurrentUser({ admin: false, staff: false, trust_level: 1 });
visit("/"); await visit("/");
click("#create-topic"); await click("#create-topic");
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-textarea-wrapper.disabled").length, find(".d-editor-textarea-wrapper.disabled").length,
"textarea is disabled" "textarea is disabled"
); );
}); await fillIn("#reply-title", "http://www.example.com/has-title.html");
fillIn("#reply-title", "http://www.example.com/has-title.html");
andThen(() => {
assert.ok( assert.ok(
find(".d-editor-preview") find(".d-editor-preview")
.html() .html()
@@ -201,4 +186,3 @@ QUnit.test("Pasting a link enables the text input area", assert => {
"textarea is enabled" "textarea is enabled"
); );
}); });
});

View File

@@ -25,25 +25,22 @@ acceptance("Create Account - User Fields", {
} }
}); });
QUnit.test("create account with user fields", assert => { QUnit.test("create account with user fields", async assert => {
visit("/"); await visit("/");
click("header .sign-up-button"); await click("header .sign-up-button");
andThen(() => {
assert.ok(exists(".create-account"), "it shows the create account modal"); assert.ok(exists(".create-account"), "it shows the create account modal");
assert.ok(exists(".user-field"), "it has at least one user field"); assert.ok(exists(".user-field"), "it has at least one user field");
assert.ok( assert.ok(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"create account is disabled at first" "create account is disabled at first"
); );
});
fillIn("#new-account-name", "Dr. Good Tuna"); await fillIn("#new-account-name", "Dr. Good Tuna");
fillIn("#new-account-password", "cool password bro"); await fillIn("#new-account-password", "cool password bro");
fillIn("#new-account-email", "good.tuna@test.com"); await fillIn("#new-account-email", "good.tuna@test.com");
fillIn("#new-account-username", "goodtuna"); await fillIn("#new-account-username", "goodtuna");
andThen(() => {
assert.ok( assert.ok(
exists("#username-validation.good"), exists("#username-validation.good"),
"the username validation is good" "the username validation is good"
@@ -52,30 +49,23 @@ QUnit.test("create account with user fields", assert => {
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"create account is still disabled due to lack of user fields" "create account is still disabled due to lack of user fields"
); );
});
fillIn(".user-field input[type=text]:first", "Barky"); await fillIn(".user-field input[type=text]:first", "Barky");
andThen(() => {
assert.ok( assert.ok(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"create account is disabled because field is not checked" "create account is disabled because field is not checked"
); );
});
click(".user-field input[type=checkbox]"); await click(".user-field input[type=checkbox]");
andThen(() => {
assert.not( assert.not(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"create account is enabled because field is not checked" "create account is enabled because field is not checked"
); );
});
click(".user-field input[type=checkbox]"); await click(".user-field input[type=checkbox]");
andThen(() => {
assert.ok( assert.ok(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"unclicking the checkbox disables the submit" "unclicking the checkbox disables the submit"
); );
}); });
});

View File

@@ -4,37 +4,27 @@ import PreloadStore from "preload-store";
acceptance("CustomHTML set"); acceptance("CustomHTML set");
QUnit.test("has no custom HTML in the top", assert => { QUnit.test("has no custom HTML in the top", async assert => {
visit("/static/faq"); await visit("/static/faq");
andThen(() => {
assert.ok(!exists("span.custom-html-test"), "it has no markup"); assert.ok(!exists("span.custom-html-test"), "it has no markup");
}); });
});
QUnit.test("renders set HTML", assert => { QUnit.test("renders set HTML", async assert => {
setCustomHTML("top", '<span class="custom-html-test">HTML</span>'); setCustomHTML("top", '<span class="custom-html-test">HTML</span>');
visit("/static/faq"); await visit("/static/faq");
andThen(() => {
assert.equal( assert.equal(
find("span.custom-html-test").text(), find("span.custom-html-test").text(),
"HTML", "HTML",
"it inserted the markup" "it inserted the markup"
); );
}); });
});
QUnit.test("renders preloaded HTML", assert => { QUnit.test("renders preloaded HTML", async assert => {
PreloadStore.store("customHTML", { PreloadStore.store("customHTML", {
top: "<span class='cookie'>monster</span>" top: "<span class='cookie'>monster</span>"
}); });
visit("/static/faq"); await visit("/static/faq");
andThen(() => { assert.equal(find("span.cookie").text(), "monster", "it inserted the markup");
assert.equal(
find("span.cookie").text(),
"monster",
"it inserted the markup"
);
});
}); });

View File

@@ -12,13 +12,7 @@ acceptance("CustomHTML template", {
} }
}); });
QUnit.test("renders custom template", assert => { QUnit.test("renders custom template", async assert => {
visit("/static/faq"); await visit("/static/faq");
andThen(() => { assert.equal(find("span.top-span").text(), "TOP", "it inserted the template");
assert.equal(
find("span.top-span").text(),
"TOP",
"it inserted the template"
);
});
}); });