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(exists(".badge-groups .badge-card"), "has a list of badges");
});
visit("/badges/9/autobiographer"); assert.ok($("body.badges-page").length, "has body class");
andThen(() => { assert.ok(exists(".badge-groups .badge-card"), "has a list of badges");
assert.ok(exists(".badge-card"), "has the badge in the listing");
assert.ok(exists(".user-info"), "has the list of users with that badge"); await visit("/badges/9/autobiographer");
assert.ok(!exists(".badge-card:eq(0) script"));
}); 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(".badge-card:eq(0) script"));
}); });

View File

@@ -7,28 +7,24 @@ 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() .value(),
.value(), 1
1 );
);
});
}); });

View File

@@ -4,127 +4,115 @@ 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
.eq(0) .eq(0)
.find(".badge-group") .find(".badge-group")
.text(); .text();
assert.equal(badgeName, "everyone"); assert.equal(badgeName, "everyone");
const permission = $permissionListItems const permission = $permissionListItems
.eq(0) .eq(0)
.find(".permission") .find(".permission")
.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)" );
);
const badgeName = $addedPermissionItem.find(".badge-group").text(); const badgeName = $addedPermissionItem.find(".badge-group").text();
assert.equal(badgeName, "staff"); assert.equal(badgeName, "staff");
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, "it adds the permission to the list"
"it adds the permission to the list" );
);
const $permissionListItems = find(".permission-list li"); const $permissionListItems = find(".permission-list li");
const badgeName = $permissionListItems const badgeName = $permissionListItems
.eq(0) .eq(0)
.find(".badge-group") .find(".badge-group")
.text(); .text();
assert.equal(badgeName, "everyone"); assert.equal(badgeName, "everyone");
const permission = $permissionListItems const permission = $permissionListItems
.eq(0) .eq(0)
.find(".permission") .find(".permission")
.text(); .text();
assert.equal(permission, "Create / Reply / See"); assert.equal(permission, "Create / Reply / See");
});
}); });

View File

@@ -6,64 +6,54 @@ 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, "/c/bug",
"/c/bug", "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, "/c/bug",
"/c/bug", "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 => {

View File

@@ -2,28 +2,24 @@ 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") .html()
.html() .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() .trim(),
.trim(), '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,321 +7,255 @@ 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"), "title errors are hidden by default"
"title errors are hidden by default" );
); assert.ok(
assert.ok( 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" );
); assert.ok(
assert.ok( !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() .trim(),
.trim(), "<p>this is the <em>content</em> of a post</p>",
"<p>this is the <em>content</em> of a post</p>", "it previews content"
"it previews content" );
); assert.ok(
assert.ok( 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;
// Testing keyboard events is tough! // Testing keyboard events is tough!
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
const event = document.createEvent("Event"); const event = document.createEvent("Event");
event.initEvent("keydown", true, true); event.initEvent("keydown", true, true);
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") .val()
.val() .trim(),
.trim(), `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");
}); assert.ok(!exists(".bootbox.modal"), "it dismisses the error");
click(".bootbox.modal a.btn-primary"); assert.ok(exists(".d-editor-input"), "the composer input is visible");
andThen(() => {
assert.ok(!exists(".bootbox.modal"), "it dismisses the error");
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(!exists("#reply-title"), "there is no title since this is a reply");
assert.ok(
!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");
}); assert.ok(visible(".reply-where-modal"), "it pops up a modal");
click("#reply-control button.create");
andThen(function() {
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(!exists("#reply-title"), "there is no title since this is a reply");
assert.ok(
!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() .indexOf("Any plans to support"),
.indexOf("Any plans to support"), 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"), "it has the edits icon"
"it has the edits icon" );
); assert.ok(
assert.ok( find("#topic-title h1")
find("#topic-title h1") .text()
.text() .indexOf("This is the new text for the title") !== -1,
.indexOf("This is the new text for the title") !== -1, "it shows the new title"
"it shows the new title" );
); assert.ok(
assert.ok( find(".topic-post:eq(0) .cooked")
find(".topic-post:eq(0) .cooked") .text()
.text() .indexOf("This is the new text for the post") !== -1,
.indexOf("This is the new text for the post") !== -1, "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() .indexOf("This is the first post."),
.indexOf("This is the first post."), 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");
}); assert.equal(
click(".topic-post:eq(1) button.edit"); find(".d-editor-input")
andThen(() => { .val()
assert.equal( .indexOf("This is the second post."),
find(".d-editor-input") 0,
.val() "it populates the input with the post text"
.indexOf("This is the second post."), );
0,
"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,107 +263,113 @@ 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", async assert => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.edit");
assert.equal(
find(".d-editor-input")
.val()
.indexOf("This is the first post."),
0,
"it populates the input with the post text"
);
await click(".topic-post:eq(0) button.reply");
assert.equal(find(".d-editor-input").val(), "", "it clears the input");
await click(".topic-post:eq(0) button.edit");
assert.equal(
find(".d-editor-input")
.val()
.indexOf("This is the first post."),
0,
"it populates the input with the post text"
);
}); });
QUnit.test("Composer can toggle between edit and reply", assert => { QUnit.test(
visit("/t/this-is-a-test-topic/9"); "Composer can toggle between reply and createTopic",
async assert => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
click(".topic-post:eq(0) button.edit"); await selectKit(".toolbar-popup-menu-options").expandAwait();
andThen(() => { await selectKit(".toolbar-popup-menu-options").selectRowByValueAwait(
assert.equal( "toggleWhisper"
find(".d-editor-input")
.val()
.indexOf("This is the first post."),
0,
"it populates the input with the post text"
); );
});
click(".topic-post:eq(0) button.reply");
andThen(() => {
assert.equal(find(".d-editor-input").val(), "", "it clears the input");
});
click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.equal(
find(".d-editor-input")
.val()
.indexOf("This is the first post."),
0,
"it populates the input with the post text"
);
});
});
QUnit.test("Composer can toggle between reply and createTopic", assert => {
visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.reply");
selectKit(".toolbar-popup-menu-options")
.expand()
.selectRowByValue("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", async assert => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
await fillIn(".d-editor-input", "This is a dirty reply");
await click(".topic-post:eq(0) button.edit");
assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog");
await click(".modal-footer a:eq(0)");
assert.equal(
find(".d-editor-input")
.val()
.indexOf("This is the first post."),
0,
"it populates the input with the post text"
);
}); });
QUnit.test("Composer 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(".topic-post:eq(0) button.edit"); await click(".toggler");
andThen(() => { await click(".topic-post:eq(0) button.edit");
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()
@@ -437,30 +377,8 @@ QUnit.test("Composer 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"
); );
}); }
}); );
QUnit.test("Composer draft with dirty reply can toggle to edit", assert => {
visit("/t/this-is-a-test-topic/9");
click(".topic-post:eq(0) button.reply");
fillIn(".d-editor-input", "This is a dirty reply");
click(".toggler");
click(".topic-post:eq(0) button.edit");
andThen(() => {
assert.ok(exists(".bootbox.modal"), "it pops up a confirmation dialog");
});
click(".modal-footer a:eq(0)");
andThen(() => {
assert.equal(
find(".d-editor-input")
.val()
.indexOf("This is the first post."),
0,
"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,45 +388,41 @@ 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"), "title errors are hidden by default"
"title errors are hidden by default" );
); assert.ok(
assert.ok( 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" );
); assert.ok(
assert.ok( 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,152 +9,140 @@ 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() .trim()
.trim() .indexOf("onebox") > 0,
.indexOf("onebox") > 0, "it pastes the link into the body and previews it"
"it pastes the link into the body and previews it" );
); assert.ok(
assert.ok( 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" );
); assert.equal(
assert.equal( find(".title-input input").val(),
find(".title-input input").val(), "An interesting article",
"An interesting article", "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() .trim()
.trim() .indexOf("onebox") > 0,
.indexOf("onebox") > 0, "it pastes the link into the body and previews it"
"it pastes the link into the body and previews it" );
); assert.ok(
assert.ok( 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" );
); assert.equal(
assert.equal( find(".title-input input").val(),
find(".title-input input").val(), "http://www.example.com/no-title.html",
"http://www.example.com/no-title.html", "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() .trim()
.trim() .indexOf("onebox") > 0,
.indexOf("onebox") > 0, "it pastes the link into the body and previews it"
"it pastes the link into the body and previews it" );
); assert.ok(
assert.ok( exists(".d-editor-textarea-wrapper .popup-tip.good"),
exists(".d-editor-textarea-wrapper .popup-tip.good"), "link is pasted into body"
"link is pasted into body" );
); assert.equal(
assert.equal( find(".title-input input").val(),
find(".title-input input").val(), "http://www.example.com/nope-onebox.html",
"http://www.example.com/nope-onebox.html", "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() .trim()
.trim() .indexOf("onebox"),
.indexOf("onebox"), -1,
-1, "onebox preview doesn't show"
"onebox preview doesn't show" );
); assert.equal(
assert.equal( find(".d-editor-input").val().length,
find(".d-editor-input").val().length, 0,
0, "link isn't put into the post"
"link isn't put into the post" );
); 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() .trim()
.trim() .indexOf("onebox") > 0,
.indexOf("onebox") > 0, "it pastes the link into the body and previews it"
"it pastes the link into the body and previews it" );
); assert.ok(
assert.ok( 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" );
); assert.equal(
assert.equal( find(".title-input input").val(),
find(".title-input input").val(), "An interesting article",
"An interesting article", "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() .trim()
.trim() .indexOf("onebox"),
.indexOf("onebox"), -1,
-1, "onebox preview doesn't show"
"onebox preview doesn't show" );
); assert.equal(
assert.equal( find(".d-editor-input").val().length,
find(".d-editor-input").val().length, 0,
0, "link isn't put into the post"
"link isn't put into the post" );
); assert.equal(
assert.equal( find(".title-input input").val(),
find(".title-input input").val(), "http://www.example.com/has-title.html test",
"http://www.example.com/has-title.html test", "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", {
@@ -167,38 +155,34 @@ 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");
}); assert.ok(
fillIn("#reply-title", "http://www.example.com/has-title.html"); find(".d-editor-preview")
andThen(() => { .html()
assert.ok( .trim()
find(".d-editor-preview") .indexOf("onebox") > 0,
.html() "it pastes the link into the body and previews it"
.trim() );
.indexOf("onebox") > 0, assert.ok(
"it pastes the link into the body and previews it" exists(".d-editor-textarea-wrapper .popup-tip.good"),
); "the body is now good"
assert.ok( );
exists(".d-editor-textarea-wrapper .popup-tip.good"), assert.equal(
"the body is now good" find(".title-input input").val(),
); "An interesting article",
assert.equal( "title is from the oneboxed article"
find(".title-input input").val(), );
"An interesting article", assert.ok(
"title is from the oneboxed article" find(".d-editor-textarea-wrapper.disabled").length === 0,
); "textarea is enabled"
assert.ok( );
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
});
}); });

View File

@@ -25,57 +25,47 @@ 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" );
); assert.ok(
assert.ok( 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"
);
});
}); });