2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-11 21:04:42 +08:00

DEV: migrate tests to async/await

This commit is contained in:
Maja Komel 2018-07-29 22:51:32 +02:00
parent 176d8ca78d
commit 04baddf731
31 changed files with 1320 additions and 1729 deletions

View file

@ -48,6 +48,7 @@
"selectKitSelectRowByValue":true,
"selectKitSelectRowByName":true,
"selectKitSelectRowByIndex":true,
"keyboardHelper":true,
"selectKitSelectNoneRow":true,
"selectKitFillInFilter":true,
"asyncTestDiscourse":true,

View file

@ -11,17 +11,14 @@ QUnit.module("Acceptance: wizard", {
}
});
test("Wizard starts", assert => {
visit("/");
andThen(() => {
test("Wizard starts", async assert => {
await visit("/");
assert.ok(exists(".wizard-column-contents"));
assert.equal(currentPath(), "step");
});
});
test("Going back and forth in steps", assert => {
visit("/steps/hello-world");
andThen(() => {
test("Going back and forth in steps", async assert => {
await visit("/steps/hello-world");
assert.ok(exists(".wizard-step"));
assert.ok(
exists(".wizard-step-hello-world"),
@ -38,26 +35,20 @@ test("Going back and forth in steps", assert => {
assert.ok(exists(".wizard-field .field-description"));
assert.ok(!exists(".wizard-btn.back"));
assert.ok(!exists(".wizard-field .field-error-description"));
});
// invalid data
click(".wizard-btn.next");
andThen(() => {
await click(".wizard-btn.next");
assert.ok(exists(".invalid .field-full-name"));
});
// server validation fail
fillIn("input.field-full-name", "Server Fail");
click(".wizard-btn.next");
andThen(() => {
await fillIn("input.field-full-name", "Server Fail");
await click(".wizard-btn.next");
assert.ok(exists(".invalid .field-full-name"));
assert.ok(exists(".wizard-field .field-error-description"));
});
// server validation ok
fillIn("input.field-full-name", "Evil Trout");
click(".wizard-btn.next");
andThen(() => {
await fillIn("input.field-full-name", "Evil Trout");
await click(".wizard-btn.next");
assert.ok(!exists(".wizard-field .field-error-description"));
assert.ok(!exists(".wizard-step-title"));
assert.ok(!exists(".wizard-step-description"));
@ -68,12 +59,9 @@ test("Going back and forth in steps", assert => {
assert.ok(!exists(".wizard-btn.next"));
assert.ok(exists(".wizard-btn.done"), "last step shows a done button");
assert.ok(exists(".action-link.back"), "shows the back button");
});
click(".action-link.back");
andThen(() => {
await click(".action-link.back");
assert.ok(exists(".wizard-step-title"));
assert.ok(exists(".wizard-btn.next"));
assert.ok(!exists(".wizard-prev"));
});
});

View file

@ -8,7 +8,7 @@ componentTest("can add users", {
this.set("field", {});
},
test(assert) {
async test(assert) {
assert.ok(
this.$(".users-list .invite-list-user").length === 0,
"no users at first"
@ -26,19 +26,16 @@ componentTest("can add users", {
"it has a warning since no users were added"
);
click(".add-user");
andThen(() => {
await click(".add-user");
assert.ok(
this.$(".users-list .invite-list-user").length === 0,
"doesn't add a blank user"
);
assert.ok(this.$(".new-user .invalid").length === 1);
});
fillIn(".invite-email", "eviltrout@example.com");
click(".add-user");
await fillIn(".invite-email", "eviltrout@example.com");
await click(".add-user");
andThen(() => {
assert.ok(
this.$(".users-list .invite-list-user").length === 1,
"adds the user"
@ -53,40 +50,30 @@ componentTest("can add users", {
"adds the email to the JSON"
);
assert.ok(val[0].role.length, "adds the role to the JSON");
assert.ok(
!this.get("field.warning"),
"no warning once the user is added"
);
});
assert.ok(!this.get("field.warning"), "no warning once the user is added");
fillIn(".invite-email", "eviltrout@example.com");
click(".add-user");
await fillIn(".invite-email", "eviltrout@example.com");
await click(".add-user");
andThen(() => {
assert.ok(
this.$(".users-list .invite-list-user").length === 1,
"can't add the same user twice"
);
assert.ok(this.$(".new-user .invalid").length === 1);
});
fillIn(".invite-email", "not-an-email");
click(".add-user");
await fillIn(".invite-email", "not-an-email");
await click(".add-user");
andThen(() => {
assert.ok(
this.$(".users-list .invite-list-user").length === 1,
"won't add an invalid email"
);
assert.ok(this.$(".new-user .invalid").length === 1);
});
click(".invite-list .invite-list-user:eq(0) .remove-user");
andThen(() => {
await click(".invite-list .invite-list-user:eq(0) .remove-user");
assert.ok(
this.$(".users-list .invite-list-user").length === 0,
"removed the user"
);
});
}
});

View file

@ -8,19 +8,15 @@ acceptance("Details Button", {
}
});
function findTextarea() {
return find(".d-editor-input")[0];
}
test("details button", assert => {
test("details button", async assert => {
const popupMenu = selectKit(".toolbar-popup-menu-options");
visit("/");
click("#create-topic");
await visit("/");
await click("#create-topic");
popupMenu.expand().selectRowByValue("insertDetails");
await popupMenu.expand();
await popupMenu.selectRowByValue("insertDetails");
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`\n[details="${I18n.t("composer.details_title")}"]\n${I18n.t(
@ -28,19 +24,16 @@ test("details button", assert => {
)}\n[/details]\n`,
"it should contain the right output"
);
});
fillIn(".d-editor-input", "This is my title");
await fillIn(".d-editor-input", "This is my title");
andThen(() => {
const textarea = findTextarea();
const textarea = find(".d-editor-input")[0];
textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
});
popupMenu.expand().selectRowByValue("insertDetails");
await popupMenu.expand();
await popupMenu.selectRowByValue("insertDetails");
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`\n[details="${I18n.t(
@ -49,7 +42,6 @@ test("details button", assert => {
"it should contain the right selected output"
);
const textarea = findTextarea();
assert.equal(
textarea.selectionStart,
21,
@ -60,19 +52,15 @@ test("details button", assert => {
37,
"it should end highlighting at the right position"
);
});
fillIn(".d-editor-input", "Before some text in between After");
await fillIn(".d-editor-input", "Before some text in between After");
andThen(() => {
const textarea = findTextarea();
textarea.selectionStart = 7;
textarea.selectionEnd = 28;
});
popupMenu.expand().selectRowByValue("insertDetails");
await popupMenu.expand();
await popupMenu.selectRowByValue("insertDetails");
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`Before \n[details="${I18n.t(
@ -81,7 +69,6 @@ test("details button", assert => {
"it should contain the right output"
);
const textarea = findTextarea();
assert.equal(
textarea.selectionStart,
28,
@ -92,19 +79,15 @@ test("details button", assert => {
48,
"it should end highlighting at the right position"
);
});
fillIn(".d-editor-input", "Before \nsome text in between\n After");
await fillIn(".d-editor-input", "Before \nsome text in between\n After");
andThen(() => {
const textarea = findTextarea();
textarea.selectionStart = 8;
textarea.selectionEnd = 29;
});
popupMenu.expand().selectRowByValue("insertDetails");
await popupMenu.expand();
await popupMenu.selectRowByValue("insertDetails");
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`Before \n\n[details="${I18n.t(
@ -113,7 +96,6 @@ test("details button", assert => {
"it should contain the right output"
);
const textarea = findTextarea();
assert.equal(
textarea.selectionStart,
29,
@ -124,26 +106,23 @@ test("details button", assert => {
49,
"it should end highlighting at the right position"
);
});
});
test("details button surrounds all selected text in a single details block", assert => {
test("details button surrounds all selected text in a single details block", async assert => {
const multilineInput = "first line\n\nsecond line\n\nthird line";
const popupMenu = selectKit(".toolbar-popup-menu-options");
visit("/");
click("#create-topic");
fillIn(".d-editor-input", multilineInput);
await visit("/");
await click("#create-topic");
await fillIn(".d-editor-input", multilineInput);
andThen(() => {
const textarea = findTextarea();
const textarea = find(".d-editor-input")[0];
textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
});
popupMenu.expand().selectRowByValue("insertDetails");
await popupMenu.expand();
await popupMenu.selectRowByValue("insertDetails");
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`\n[details="${I18n.t(
@ -151,5 +130,4 @@ test("details button surrounds all selected text in a single details block", ass
)}"]\n${multilineInput}\n[/details]\n`,
"it should contain the right output"
);
});
});

View file

@ -9,7 +9,7 @@ acceptance("Rendering polls", {
}
});
test("Single Poll", assert => {
test("Single Poll", async assert => {
// prettier-ignore
server.get("/t/13.json", () => { // eslint-disable-line no-undef
return [
@ -313,9 +313,8 @@ test("Single Poll", assert => {
];
});
visit("/t/this-is-a-test-topic-for-polls/13");
await visit("/t/this-is-a-test-topic-for-polls/13");
andThen(() => {
const polls = find(".poll");
assert.equal(polls.length, 2, "it should render the polls correctly");
@ -329,10 +328,9 @@ test("Single Poll", assert => {
"3",
"it should display the right number of votes"
);
});
});
test("Public poll", assert => {
test("Public poll", async assert => {
// prettier-ignore
server.get("/t/12.json", () => { // eslint-disable-line no-undef
return [
@ -1328,35 +1326,29 @@ test("Public poll", assert => {
return [200, { "Content-Type": "application/json" }, body];
});
visit("/t/this-is-a-topic-created-for-testing/12");
await visit("/t/this-is-a-topic-created-for-testing/12");
andThen(() => {
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
});
click("button.toggle-results");
await click("button.toggle-results");
andThen(() => {
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
});
click(".poll-voters-toggle-expand:first a");
await click(".poll-voters-toggle-expand:first a");
andThen(() => {
assert.equal(
find(".poll-voters:first li").length,
50,
"it should display the right number of voters"
);
});
});
test("Public number poll", assert => {
test("Public number poll", async assert => {
// prettier-ignore
server.get("/t/13.json", () => { // eslint-disable-line no-undef
return [
@ -2016,30 +2008,24 @@ test("Public number poll", assert => {
return [200, { "Content-Type": "application/json" }, body];
});
visit("/t/this-is-a-topic-for-testing-number-poll/13");
await visit("/t/this-is-a-topic-for-testing-number-poll/13");
andThen(() => {
const polls = find(".poll");
assert.equal(polls.length, 1, "it should render the poll correctly");
});
click("button.toggle-results");
await click("button.toggle-results");
andThen(() => {
assert.equal(
find(".poll-voters:first li").length,
25,
"it should display the right number of voters"
);
});
click(".poll-voters-toggle-expand:first a");
await click(".poll-voters-toggle-expand:first a");
andThen(() => {
assert.equal(
find(".poll-voters:first li").length,
35,
"it should display the right number of voters"
);
});
});

View file

@ -24,8 +24,8 @@ QUnit.test("flagged posts - agree", async assert => {
await visit("/admin/flags/active");
await agreeFlag.expandAwait();
await agreeFlag.selectRowByValueAwait("confirm-agree-keep");
await agreeFlag.expand();
await agreeFlag.selectRowByValue("confirm-agree-keep");
assert.equal(
find(".admin-flags .flagged-post").length,
@ -39,8 +39,8 @@ QUnit.test("flagged posts - agree + hide", async assert => {
await visit("/admin/flags/active");
await agreeFlag.expandAwait();
await agreeFlag.selectRowByValueAwait("confirm-agree-hide");
await agreeFlag.expand();
await agreeFlag.selectRowByValue("confirm-agree-hide");
assert.equal(
find(".admin-flags .flagged-post").length,
@ -54,8 +54,8 @@ QUnit.test("flagged posts - agree + deleteSpammer", async assert => {
await visit("/admin/flags/active");
await agreeFlag.expandAwait();
await agreeFlag.selectRowByValueAwait("delete-spammer");
await agreeFlag.expand();
await agreeFlag.selectRowByValue("delete-spammer");
await click(".confirm-delete");
@ -85,8 +85,8 @@ QUnit.test("flagged posts - delete + defer", async assert => {
await visit("/admin/flags/active");
await deleteFlag.expandAwait();
await deleteFlag.selectRowByValueAwait("delete-defer");
await deleteFlag.expand();
await deleteFlag.selectRowByValue("delete-defer");
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
@ -96,8 +96,8 @@ QUnit.test("flagged posts - delete + agree", async assert => {
await visit("/admin/flags/active");
await deleteFlag.expandAwait();
await deleteFlag.selectRowByValueAwait("delete-agree");
await deleteFlag.expand();
await deleteFlag.selectRowByValue("delete-agree");
assert.equal(find(".admin-flags .flagged-post").length, 0);
});
@ -107,8 +107,8 @@ QUnit.test("flagged posts - delete + deleteSpammer", async assert => {
await visit("/admin/flags/active");
await deleteFlag.expandAwait();
await deleteFlag.selectRowByValueAwait("delete-spammer");
await deleteFlag.expand();
await deleteFlag.selectRowByValue("delete-spammer");
await click(".confirm-delete");

View file

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

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@ QUnit.test("replying to post", async assert => {
await visit("/t/internationalization-localization/280");
await click("article#post_3 button.reply");
await composerActions.expandAwait();
await composerActions.expand();
assert.equal(composerActions.rowByIndex(0).value(), "reply_as_new_topic");
assert.equal(
@ -34,8 +34,8 @@ QUnit.test("replying to post - reply_as_private_message", async assert => {
await visit("/t/internationalization-localization/280");
await click("article#post_3 button.reply");
await composerActions.expandAwait();
await composerActions.selectRowByValueAwait("reply_as_private_message");
await composerActions.expand();
await composerActions.selectRowByValue("reply_as_private_message");
assert.equal(find(".users-input .item:eq(0)").text(), "codinghorror");
assert.ok(
@ -55,8 +55,8 @@ QUnit.test("replying to post - reply_to_topic", async assert => {
"test replying to topic when initially replied to post"
);
await composerActions.expandAwait();
await composerActions.selectRowByValueAwait("reply_to_topic");
await composerActions.expand();
await composerActions.selectRowByValue("reply_to_topic");
assert.equal(
find(".action-title .topic-link")
@ -84,8 +84,8 @@ QUnit.test("replying to post - toggle_whisper", async assert => {
"test replying as whisper to topic when initially not a whisper"
);
await composerActions.expandAwait();
await composerActions.selectRowByValueAwait("toggle_whisper");
await composerActions.expand();
await composerActions.selectRowByValue("toggle_whisper");
assert.ok(
find(".composer-fields .whisper")
@ -103,15 +103,15 @@ QUnit.test("replying to post - reply_as_new_topic", async assert => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil");
await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait(4);
await categoryChooser.expand();
await categoryChooser.selectRowByValue(4);
await click("#topic-title .submit-edit");
await click("article#post_3 button.reply");
await fillIn(".d-editor-input", quote);
await composerActions.expandAwait();
await composerActions.selectRowByValueAwait("reply_as_new_topic");
await composerActions.expand();
await composerActions.selectRowByValue("reply_as_new_topic");
assert.equal(categoryChooserReplyArea.header().name(), "faq");
assert.equal(
@ -133,8 +133,8 @@ QUnit.test("shared draft", async assert => {
await visit("/");
await click("#create-topic");
await composerActions.expandAwait();
await composerActions.selectRowByValueAwait("shared_draft");
await composerActions.expand();
await composerActions.selectRowByValue("shared_draft");
assert.equal(
find("#reply-control .btn-primary.create .d-button-label").text(),
@ -159,8 +159,8 @@ QUnit.test("interactions", async assert => {
await visit("/t/internationalization-localization/280");
await click("article#post_3 button.reply");
await fillIn(".d-editor-input", quote);
await composerActions.expandAwait();
await composerActions.selectRowByValueAwait("reply_to_topic");
await composerActions.expand();
await composerActions.selectRowByValue("reply_to_topic");
assert.equal(
find(".action-title")
@ -170,7 +170,7 @@ QUnit.test("interactions", async assert => {
);
assert.equal(find(".d-editor-input").val(), quote);
await composerActions.expandAwait();
await composerActions.expand();
assert.equal(composerActions.rowByIndex(0).value(), "reply_as_new_topic");
assert.equal(composerActions.rowByIndex(1).value(), "reply_to_post");
@ -181,8 +181,8 @@ QUnit.test("interactions", async assert => {
assert.equal(composerActions.rowByIndex(3).value(), "toggle_whisper");
assert.equal(composerActions.rows().length, 4);
await composerActions.selectRowByValueAwait("reply_to_post");
await composerActions.expandAwait();
await composerActions.selectRowByValue("reply_to_post");
await composerActions.expand();
assert.ok(exists(find(".action-title img.avatar")));
assert.equal(
@ -201,8 +201,8 @@ QUnit.test("interactions", async assert => {
assert.equal(composerActions.rowByIndex(3).value(), "toggle_whisper");
assert.equal(composerActions.rows().length, 4);
await composerActions.selectRowByValueAwait("reply_as_new_topic");
await composerActions.expandAwait();
await composerActions.selectRowByValue("reply_as_new_topic");
await composerActions.expand();
assert.equal(
find(".action-title")
@ -224,8 +224,8 @@ QUnit.test("interactions", async assert => {
assert.equal(composerActions.rowByIndex(3).value(), "shared_draft");
assert.equal(composerActions.rows().length, 4);
await composerActions.selectRowByValueAwait("reply_as_private_message");
await composerActions.expandAwait();
await composerActions.selectRowByValue("reply_as_private_message");
await composerActions.expand();
assert.equal(
find(".action-title")

View file

@ -295,8 +295,8 @@ QUnit.test(
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
await selectKit(".toolbar-popup-menu-options").expandAwait();
await selectKit(".toolbar-popup-menu-options").selectRowByValueAwait(
await selectKit(".toolbar-popup-menu-options").expand();
await selectKit(".toolbar-popup-menu-options").selectRowByValue(
"toggleWhisper"
);
@ -318,8 +318,8 @@ QUnit.test(
"it should reset the state of the composer's model"
);
await selectKit(".toolbar-popup-menu-options").expandAwait();
await selectKit(".toolbar-popup-menu-options").selectRowByValueAwait(
await selectKit(".toolbar-popup-menu-options").expand();
await selectKit(".toolbar-popup-menu-options").selectRowByValue(
"toggleInvisible"
);
@ -409,8 +409,8 @@ QUnit.test("Disable body until category is selected", async assert => {
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait(2);
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0,
@ -418,8 +418,8 @@ QUnit.test("Disable body until category is selected", async assert => {
);
await fillIn(".d-editor-input", "Now I can type stuff");
await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait("__none__");
await categoryChooser.expand();
await categoryChooser.selectRowByValue("__none__");
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0,

View file

@ -58,9 +58,12 @@ QUnit.test("update some fields", async assert => {
await savePreferences();
click(".preferences-nav .nav-notifications a");
selectKit(".control-group.notifications .combo-box.duration")
.expand()
.selectRowByValue(1440);
await selectKit(
".control-group.notifications .combo-box.duration"
).expand();
await selectKit(
".control-group.notifications .combo-box.duration"
).selectRowByValue(1440);
await savePreferences();
click(".preferences-nav .nav-categories a");

View file

@ -156,9 +156,9 @@ QUnit.test("update category through advanced search ui", async assert => {
await fillIn(".search-query", "none");
await categoryChooser.expandAwait();
await categoryChooser.expand();
await categoryChooser.fillInFilter("faq");
await categoryChooser.selectRowByValueAwait(4);
await categoryChooser.selectRowByValue(4);
assert.ok(
exists('.search-advanced-options .badge-category:contains("faq")'),
@ -317,8 +317,8 @@ QUnit.test("update in filter through advanced search ui", async assert => {
await visit("/search");
await fillIn(".search-query", "none");
await inSelector.expandAwait();
await inSelector.selectRowByValueAwait("bookmarks");
await inSelector.expand();
await inSelector.selectRowByValue("bookmarks");
assert.ok(
inSelector.rowByName("I bookmarked").exists(),
@ -339,8 +339,8 @@ QUnit.test("update status through advanced search ui", async assert => {
await visit("/search");
await fillIn(".search-query", "none");
await statusSelector.expandAwait();
await statusSelector.selectRowByValueAwait("closed");
await statusSelector.expand();
await statusSelector.selectRowByValue("closed");
assert.ok(
statusSelector.rowByName("are closed").exists(),
@ -362,8 +362,8 @@ QUnit.test("update post time through advanced search ui", async assert => {
await fillIn(".search-query", "none");
await fillIn("#search-post-date .date-picker", "2016-10-05");
await postTimeSelector.expandAwait();
await postTimeSelector.selectRowByValueAwait("after");
await postTimeSelector.expand();
await postTimeSelector.selectRowByValue("after");
assert.ok(
postTimeSelector.rowByName("after").exists(),

View file

@ -89,7 +89,7 @@ QUnit.test("Right filters are shown to anonymous users", async assert => {
await visit("/search?expanded=true");
await inSelector.expandAwait();
await inSelector.expand();
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());
@ -115,7 +115,7 @@ QUnit.test("Right filters are shown to logged-in users", async assert => {
Discourse.reset();
await visit("/search?expanded=true");
await inSelector.expandAwait();
await inSelector.expand();
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());

View file

@ -51,8 +51,8 @@ QUnit.test("autoclose - specific time", async assert => {
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
@ -71,8 +71,8 @@ QUnit.test("autoclose", async assert => {
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
@ -83,8 +83,8 @@ QUnit.test("autoclose", async assert => {
.trim();
assert.ok(regex1.test(html1));
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("pick_date_and_time");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("pick_date_and_time");
await fillIn(".future-date-input .date-picker", "2099-11-24");
@ -97,8 +97,8 @@ QUnit.test("autoclose", async assert => {
.trim();
assert.ok(regex2.test(html2));
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("set_based_on_last_post");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("set_based_on_last_post");
await fillIn(".future-date-input input[type=number]", "2");
@ -126,14 +126,14 @@ QUnit.test("close temporarily", async assert => {
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expandAwait();
await timerType.selectRowByValueAwait("open");
await timerType.expand();
await timerType.selectRowByValue("open");
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
@ -144,8 +144,8 @@ QUnit.test("close temporarily", async assert => {
.trim();
assert.ok(regex1.test(html1));
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("pick_date_and_time");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("pick_date_and_time");
await fillIn(".future-date-input .date-picker", "2099-11-24");
@ -168,8 +168,8 @@ QUnit.test("schedule", async assert => {
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expandAwait();
await timerType.selectRowByValueAwait("publish_to_category");
await timerType.expand();
await timerType.selectRowByValue("publish_to_category");
assert.equal(categoryChooser.header().title(), "uncategorized");
assert.equal(categoryChooser.header().value(), null);
@ -177,11 +177,11 @@ QUnit.test("schedule", async assert => {
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait("7");
await categoryChooser.expand();
await categoryChooser.selectRowByValue("7");
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("next_week");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(futureDateInputSelector.header().title(), "Next week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
@ -202,7 +202,7 @@ QUnit.test("TL4 can't auto-delete", async assert => {
const timerType = selectKit(".select-kit.timer-type");
await timerType.expandAwait();
await timerType.expand();
assert.ok(!timerType.rowByValue("delete").exists());
});
@ -215,14 +215,14 @@ QUnit.test("auto delete", async assert => {
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expandAwait();
await timerType.selectRowByValueAwait("delete");
await timerType.expand();
await timerType.selectRowByValue("delete");
assert.equal(futureDateInputSelector.header().title(), "Select a timeframe");
assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.expandAwait();
await futureDateInputSelector.selectRowByValueAwait("two_weeks");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("two_weeks");
assert.equal(futureDateInputSelector.header().title(), "Two Weeks");
assert.equal(futureDateInputSelector.header().value(), "two_weeks");
@ -242,7 +242,8 @@ QUnit.test(
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expand().selectRowByValue("next_week");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
await click(".modal-footer button.btn-primary");
const regex = /will automatically close in/g;

View file

@ -20,8 +20,8 @@ QUnit.test("Updating topic notification level", async assert => {
"it should display the notification options button in the topic's footer"
);
await notificationOptions.expandAwait();
await notificationOptions.selectRowByValueAwait("3");
await notificationOptions.expand();
await notificationOptions.selectRowByValue("3");
assert.equal(
notificationOptions.selectedRow().name(),

View file

@ -54,8 +54,8 @@ QUnit.test("Updating the topic title and category", async assert => {
await click("#topic-title .d-icon-pencil");
await fillIn("#edit-title", "this is the new title");
await categoryChooser.expandAwait();
await categoryChooser.selectRowByValueAwait(4);
await categoryChooser.expand();
await categoryChooser.selectRowByValue(4);
await click("#topic-title .submit-edit");
assert.equal(

View file

@ -10,7 +10,7 @@ componentTest("default", {
assert.equal(subject.el().find(".d-icon-bars").length, 1);
assert.equal(subject.el().find(".d-icon-caret-down").length, 1);
await subject.expandAwait();
await subject.expand();
assert.equal(subject.rowByValue("create").name(), "New Category");
}

View file

@ -30,7 +30,7 @@ componentTest("with excludeCategoryId", {
template: "{{category-chooser excludeCategoryId=2}}",
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.notOk(
this.get("subject")
@ -44,7 +44,7 @@ componentTest("with scopedCategoryId", {
template: "{{category-chooser scopedCategoryId=2}}",
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")

View file

@ -16,7 +16,6 @@ componentTest("default", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
@ -29,7 +28,6 @@ componentTest("default", {
.exists(),
"selected categories are not in the list"
);
});
}
});
@ -41,10 +39,9 @@ componentTest("with blacklist", {
this.set("blacklist", [Category.findById(8)]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.ok(
this.get("subject")
.rowByValue(6)
@ -57,7 +54,6 @@ componentTest("with blacklist", {
.exists(),
"blacklisted categories are not in the list"
);
});
}
});
@ -68,12 +64,10 @@ componentTest("interactions", {
this.set("categories", [Category.findById(2), Category.findById(6)]);
},
test(assert) {
this.get("subject")
.expand()
.selectRowByValue(8);
async test(assert) {
await this.get("subject").expand();
await this.get("subject").selectRowByValue(8);
andThen(() => {
assert.equal(
this.get("subject")
.header()
@ -82,17 +76,12 @@ componentTest("interactions", {
"it adds the selected category"
);
assert.equal(this.get("categories").length, 3);
});
this.get("subject").expand();
this.get("subject")
.keyboard()
.backspace();
this.get("subject")
.keyboard()
.backspace();
await this.get("subject").expand();
await this.get("subject").keyboard("backspace");
await this.get("subject").keyboard("backspace");
andThen(() => {
assert.equal(
this.get("subject")
.header()
@ -101,6 +90,5 @@ componentTest("interactions", {
"it removes the last selected category"
);
assert.equal(this.get("categories").length, 2);
});
}
});

View file

@ -13,7 +13,7 @@ componentTest("default", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -46,7 +46,7 @@ componentTest("with valueAttribute", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -70,7 +70,7 @@ componentTest("with nameProperty", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -94,7 +94,7 @@ componentTest("with an array as content", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -120,7 +120,7 @@ componentTest("with value and none as a string", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -148,7 +148,7 @@ componentTest("with value and none as a string", {
);
assert.equal(this.get("value"), "trout");
await this.get("subject").selectNoneRowAwait();
await this.get("subject").selectNoneRow();
assert.equal(this.get("value"), null);
}
@ -191,7 +191,7 @@ componentTest("with value and none as an object", {
);
assert.equal(this.get("value"), "evil");
await this.get("subject").selectNoneRowAwait();
await this.get("subject").selectNoneRow();
assert.equal(this.get("value"), null);
}
@ -207,7 +207,7 @@ componentTest("with no value and none as an object", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -228,7 +228,7 @@ componentTest("with no value and none string", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -247,7 +247,7 @@ componentTest("with no value and no none", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -289,7 +289,7 @@ componentTest("with noneLabel", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")

View file

@ -6,11 +6,10 @@ moduleForComponent("d-editor", { integration: true });
componentTest("preview updates with markdown", {
template: "{{d-editor value=value}}",
test(assert) {
async test(assert) {
assert.ok(this.$(".d-editor-button-bar").length);
fillIn(".d-editor-input", "hello **world**");
await fillIn(".d-editor-input", "hello **world**");
andThen(() => {
assert.equal(this.get("value"), "hello **world**");
assert.equal(
this.$(".d-editor-preview")
@ -18,23 +17,20 @@ componentTest("preview updates with markdown", {
.trim(),
"<p>hello <strong>world</strong></p>"
);
});
}
});
componentTest("preview sanitizes HTML", {
template: "{{d-editor value=value}}",
test(assert) {
fillIn(".d-editor-input", `"><svg onload="prompt(/xss/)"></svg>`);
andThen(() => {
async test(assert) {
await fillIn(".d-editor-input", `"><svg onload="prompt(/xss/)"></svg>`);
assert.equal(
this.$(".d-editor-preview")
.html()
.trim(),
'<p>"&gt;</p>'
);
});
}
});
@ -45,7 +41,7 @@ componentTest("updating the value refreshes the preview", {
this.set("value", "evil trout");
},
test(assert) {
async test(assert) {
assert.equal(
this.$(".d-editor-preview")
.html()
@ -53,14 +49,12 @@ componentTest("updating the value refreshes the preview", {
"<p>evil trout</p>"
);
andThen(() => this.set("value", "zogstrip"));
andThen(() =>
await this.set("value", "zogstrip");
assert.equal(
this.$(".d-editor-preview")
.html()
.trim(),
"<p>zogstrip</p>"
)
);
}
});
@ -97,216 +91,167 @@ function composerTestCase(title, testFunc) {
});
}
testCase(`selecting the space before a word`, function(assert, textarea) {
testCase(`selecting the space before a word`, async function(assert, textarea) {
textarea.selectionStart = 5;
textarea.selectionEnd = 7;
click(`button.bold`);
andThen(() => {
await click(`button.bold`);
assert.equal(this.get("value"), `hello **w**orld.`);
assert.equal(textarea.selectionStart, 8);
assert.equal(textarea.selectionEnd, 9);
});
});
testCase(`selecting the space after a word`, function(assert, textarea) {
testCase(`selecting the space after a word`, async function(assert, textarea) {
textarea.selectionStart = 0;
textarea.selectionEnd = 6;
click(`button.bold`);
andThen(() => {
await click(`button.bold`);
assert.equal(this.get("value"), `**hello** world.`);
assert.equal(textarea.selectionStart, 2);
assert.equal(textarea.selectionEnd, 7);
});
});
testCase(`bold button with no selection`, function(assert, textarea) {
click(`button.bold`);
andThen(() => {
testCase(`bold button with no selection`, async function(assert, textarea) {
await click(`button.bold`);
const example = I18n.t(`composer.bold_text`);
assert.equal(this.get("value"), `hello world.**${example}**`);
assert.equal(textarea.selectionStart, 14);
assert.equal(textarea.selectionEnd, 14 + example.length);
});
});
testCase(`bold button with a selection`, function(assert, textarea) {
testCase(`bold button with a selection`, async function(assert, textarea) {
textarea.selectionStart = 6;
textarea.selectionEnd = 11;
click(`button.bold`);
andThen(() => {
await click(`button.bold`);
assert.equal(this.get("value"), `hello **world**.`);
assert.equal(textarea.selectionStart, 8);
assert.equal(textarea.selectionEnd, 13);
});
click(`button.bold`);
andThen(() => {
await click(`button.bold`);
assert.equal(this.get("value"), "hello world.");
assert.equal(textarea.selectionStart, 6);
assert.equal(textarea.selectionEnd, 11);
});
});
testCase(`bold with a multiline selection`, function(assert, textarea) {
testCase(`bold with a multiline selection`, async function(assert, textarea) {
this.set("value", "hello\n\nworld\n\ntest.");
andThen(() => {
textarea.selectionStart = 0;
textarea.selectionEnd = 12;
});
click(`button.bold`);
andThen(() => {
await click(`button.bold`);
assert.equal(this.get("value"), `**hello**\n\n**world**\n\ntest.`);
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 20);
});
click(`button.bold`);
andThen(() => {
await click(`button.bold`);
assert.equal(this.get("value"), `hello\n\nworld\n\ntest.`);
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 12);
});
});
testCase(`italic button with no selection`, function(assert, textarea) {
click(`button.italic`);
andThen(() => {
testCase(`italic button with no selection`, async function(assert, textarea) {
await click(`button.italic`);
const example = I18n.t(`composer.italic_text`);
assert.equal(this.get("value"), `hello world._${example}_`);
assert.equal(textarea.selectionStart, 13);
assert.equal(textarea.selectionEnd, 13 + example.length);
});
});
testCase(`italic button with a selection`, function(assert, textarea) {
testCase(`italic button with a selection`, async function(assert, textarea) {
textarea.selectionStart = 6;
textarea.selectionEnd = 11;
click(`button.italic`);
andThen(() => {
await click(`button.italic`);
assert.equal(this.get("value"), `hello _world_.`);
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 12);
});
click(`button.italic`);
andThen(() => {
await click(`button.italic`);
assert.equal(this.get("value"), "hello world.");
assert.equal(textarea.selectionStart, 6);
assert.equal(textarea.selectionEnd, 11);
});
});
testCase(`italic with a multiline selection`, function(assert, textarea) {
testCase(`italic with a multiline selection`, async function(assert, textarea) {
this.set("value", "hello\n\nworld\n\ntest.");
andThen(() => {
textarea.selectionStart = 0;
textarea.selectionEnd = 12;
});
click(`button.italic`);
andThen(() => {
await click(`button.italic`);
assert.equal(this.get("value"), `_hello_\n\n_world_\n\ntest.`);
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 16);
});
click(`button.italic`);
andThen(() => {
await click(`button.italic`);
assert.equal(this.get("value"), `hello\n\nworld\n\ntest.`);
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 12);
});
});
testCase("link modal (cancel)", function(assert) {
testCase("link modal (cancel)", async function(assert) {
assert.equal(this.$(".insert-link.hidden").length, 1);
click("button.link");
andThen(() => {
await click("button.link");
assert.equal(this.$(".insert-link.hidden").length, 0);
});
click(".insert-link button.btn-danger");
andThen(() => {
await click(".insert-link button.btn-danger");
assert.equal(this.$(".insert-link.hidden").length, 1);
assert.equal(this.get("value"), "hello world.");
});
});
testCase("link modal (cancel clears inputs)", async function(assert) {
testCase("link modal (simple link)", async function(assert, textarea) {
await click("button.link");
await fillIn(".insert-link input.link-url", "https://meta.discourse.org/");
await fillIn(".insert-link input.link-text", "Discourse Meta");
await click(".insert-link button.btn-danger");
await click("button.link");
assert.equal(this.$(".insert-link input.link-url")[0].value, "");
assert.equal(this.$(".insert-link input.link-text")[0].value, "");
});
testCase("link modal (simple link)", function(assert, textarea) {
click("button.link");
const url = "http://eviltrout.com";
fillIn(".insert-link input.link-url", url);
click(".insert-link button.btn-primary");
andThen(() => {
await fillIn(".insert-link input.link-url", url);
await click(".insert-link button.btn-primary");
assert.equal(this.$(".insert-link.hidden").length, 1);
assert.equal(this.get("value"), `hello world.[${url}](${url})`);
assert.equal(textarea.selectionStart, 13);
assert.equal(textarea.selectionEnd, 13 + url.length);
});
});
testCase("link modal auto http addition", function(assert) {
click("button.link");
fillIn(".insert-link input.link-url", "sam.com");
click(".insert-link button.btn-primary");
andThen(() => {
testCase("link modal auto http addition", async function(assert) {
await click("button.link");
await fillIn(".insert-link input.link-url", "sam.com");
await click(".insert-link button.btn-primary");
assert.equal(this.get("value"), `hello world.[sam.com](http://sam.com)`);
});
});
testCase("link modal (simple link) with selected text", function(
testCase("link modal (simple link) with selected text", async function(
assert,
textarea
) {
textarea.selectionStart = 0;
textarea.selectionEnd = 12;
click("button.link");
andThen(() => {
await click("button.link");
assert.equal(this.$("input.link-text")[0].value, "hello world.");
});
fillIn(".insert-link input.link-url", "http://eviltrout.com");
click(".insert-link button.btn-primary");
andThen(() => {
await fillIn(".insert-link input.link-url", "http://eviltrout.com");
await click(".insert-link button.btn-primary");
assert.equal(this.$(".insert-link.hidden").length, 1);
assert.equal(this.get("value"), "[hello world.](http://eviltrout.com)");
});
});
testCase("link modal (link with description)", function(assert) {
click("button.link");
fillIn(".insert-link input.link-url", "http://eviltrout.com");
fillIn(".insert-link input.link-text", "evil trout");
click(".insert-link button.btn-primary");
andThen(() => {
testCase("link modal (link with description)", async function(assert) {
await click("button.link");
await fillIn(".insert-link input.link-url", "http://eviltrout.com");
await fillIn(".insert-link input.link-text", "evil trout");
await click(".insert-link button.btn-primary");
assert.equal(this.$(".insert-link.hidden").length, 1);
assert.equal(
this.get("value"),
"hello world.[evil trout](http://eviltrout.com)"
);
});
});
componentTest("advanced code", {
@ -325,13 +270,12 @@ function xyz(x, y, z) {
);
},
test(assert) {
async test(assert) {
const textarea = this.$("textarea.d-editor-input")[0];
textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`
@ -342,7 +286,6 @@ function xyz(x, y, z) {
}
`
);
});
}
});
@ -352,21 +295,18 @@ componentTest("code button", {
this.siteSettings.code_formatting_style = "4-spaces-indent";
},
test(assert) {
async test(assert) {
const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]);
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(this.get("value"), ` ${I18n.t("composer.code_text")}`);
this.set("value", "first line\n\nsecond line\n\nthird line");
textarea.selectionStart = 11;
textarea.selectionEnd = 11;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`first line
@ -377,10 +317,8 @@ third line`
);
this.set("value", "first line\n\nsecond line\n\nthird line");
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`first line
@ -390,15 +328,11 @@ second line
third line\`${I18n.t("composer.code_title")}\``
);
this.set("value", "first line\n\nsecond line\n\nthird line");
});
andThen(() => {
textarea.selectionStart = 5;
textarea.selectionEnd = 5;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`first\`${I18n.t("composer.code_title")}\` line
@ -408,55 +342,38 @@ second line
third line`
);
this.set("value", "first line\n\nsecond line\n\nthird line");
});
andThen(() => {
textarea.selectionStart = 6;
textarea.selectionEnd = 10;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
"first `line`\n\nsecond line\n\nthird line"
);
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 11);
});
click("button.code");
andThen(() => {
assert.equal(
this.get("value"),
"first line\n\nsecond line\n\nthird line"
);
await click("button.code");
assert.equal(this.get("value"), "first line\n\nsecond line\n\nthird line");
assert.equal(textarea.selectionStart, 6);
assert.equal(textarea.selectionEnd, 10);
textarea.selectionStart = 0;
textarea.selectionEnd = 23;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
" first line\n\n second line\n\nthird line"
);
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 31);
});
click("button.code");
andThen(() => {
assert.equal(
this.get("value"),
"first line\n\nsecond line\n\nthird line"
);
await click("button.code");
assert.equal(this.get("value"), "first line\n\nsecond line\n\nthird line");
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 23);
});
}
});
@ -466,11 +383,10 @@ componentTest("code fences", {
this.set("value", "");
},
test(assert) {
async test(assert) {
const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]);
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`\`\`\`
@ -485,10 +401,9 @@ ${I18n.t("composer.paste_code_text")}
textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`\`\`\`
@ -506,10 +421,9 @@ third line
textarea.selectionStart = 0;
textarea.selectionEnd = 0;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`\`${I18n.t("composer.code_title")}\`first line
@ -527,10 +441,9 @@ third line`
textarea.selectionStart = 0;
textarea.selectionEnd = 10;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`\`first line\`
@ -545,10 +458,9 @@ third line`
textarea.selectionStart = 0;
textarea.selectionEnd = 23;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`\`\`\`
@ -565,10 +477,9 @@ third line`
textarea.selectionStart = 6;
textarea.selectionEnd = 17;
});
click("button.code");
andThen(() => {
await click("button.code");
assert.equal(
this.get("value"),
`first \n\`\`\`\nline\nsecond\n\`\`\`\n line\nthird line`
@ -576,7 +487,6 @@ third line`
assert.equal(textarea.selectionStart, 27);
assert.equal(textarea.selectionEnd, 27);
});
}
});
@ -585,24 +495,19 @@ componentTest("quote button - empty lines", {
beforeEach() {
this.set("value", "one\n\ntwo\n\nthree");
},
test(assert) {
async test(assert) {
const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]);
andThen(() => {
textarea.selectionStart = 0;
});
click("button.quote");
andThen(() => {
await click("button.quote");
assert.equal(this.get("value"), "> one\n> \n> two\n> \n> three");
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 25);
});
click("button.quote");
andThen(() => {
await click("button.quote");
assert.equal(this.get("value"), "one\n\ntwo\n\nthree");
});
}
});
@ -611,172 +516,130 @@ componentTest("quote button - selecting empty lines", {
beforeEach() {
this.set("value", "one\n\n\n\ntwo");
},
test(assert) {
async test(assert) {
const textarea = jumpEnd(this.$("textarea.d-editor-input")[0]);
andThen(() => {
textarea.selectionStart = 6;
textarea.selectionEnd = 10;
});
click("button.quote");
andThen(() => {
await click("button.quote");
assert.equal(this.get("value"), "one\n\n\n> \n> two");
});
}
});
testCase("quote button", function(assert, textarea) {
andThen(() => {
testCase("quote button", async function(assert, textarea) {
textarea.selectionStart = 6;
textarea.selectionEnd = 9;
});
click("button.quote");
andThen(() => {
await click("button.quote");
assert.equal(this.get("value"), "hello\n\n> wor\n\nld.");
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 12);
});
click("button.quote");
await click("button.quote");
andThen(() => {
assert.equal(this.get("value"), "hello\n\nwor\n\nld.");
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 10);
});
andThen(() => {
textarea.selectionStart = 15;
textarea.selectionEnd = 15;
});
click("button.quote");
andThen(() => {
await click("button.quote");
assert.equal(this.get("value"), "hello\n\nwor\n\nld.\n\n> Blockquote");
});
});
testCase(`bullet button with no selection`, function(assert, textarea) {
testCase(`bullet button with no selection`, async function(assert, textarea) {
const example = I18n.t("composer.list_item");
click(`button.bullet`);
andThen(() => {
await click(`button.bullet`);
assert.equal(this.get("value"), `hello world.\n\n* ${example}`);
assert.equal(textarea.selectionStart, 14);
assert.equal(textarea.selectionEnd, 16 + example.length);
});
click(`button.bullet`);
andThen(() => {
await click(`button.bullet`);
assert.equal(this.get("value"), `hello world.\n\n${example}`);
});
});
testCase(`bullet button with a selection`, function(assert, textarea) {
testCase(`bullet button with a selection`, async function(assert, textarea) {
textarea.selectionStart = 6;
textarea.selectionEnd = 11;
click(`button.bullet`);
andThen(() => {
await click(`button.bullet`);
assert.equal(this.get("value"), `hello\n\n* world\n\n.`);
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 14);
});
click(`button.bullet`);
andThen(() => {
await click(`button.bullet`);
assert.equal(this.get("value"), `hello\n\nworld\n\n.`);
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 12);
});
});
testCase(`bullet button with a multiple line selection`, function(
testCase(`bullet button with a multiple line selection`, async function(
assert,
textarea
) {
this.set("value", "* Hello\n\nWorld\n\nEvil");
andThen(() => {
textarea.selectionStart = 0;
textarea.selectionEnd = 20;
});
click(`button.bullet`);
andThen(() => {
await click(`button.bullet`);
assert.equal(this.get("value"), "Hello\n\nWorld\n\nEvil");
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 18);
});
click(`button.bullet`);
andThen(() => {
await click(`button.bullet`);
assert.equal(this.get("value"), "* Hello\n\n* World\n\n* Evil");
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 24);
});
});
testCase(`list button with no selection`, function(assert, textarea) {
testCase(`list button with no selection`, async function(assert, textarea) {
const example = I18n.t("composer.list_item");
click(`button.list`);
andThen(() => {
await click(`button.list`);
assert.equal(this.get("value"), `hello world.\n\n1. ${example}`);
assert.equal(textarea.selectionStart, 14);
assert.equal(textarea.selectionEnd, 17 + example.length);
});
click(`button.list`);
andThen(() => {
await click(`button.list`);
assert.equal(this.get("value"), `hello world.\n\n${example}`);
assert.equal(textarea.selectionStart, 14);
assert.equal(textarea.selectionEnd, 14 + example.length);
});
});
testCase(`list button with a selection`, function(assert, textarea) {
testCase(`list button with a selection`, async function(assert, textarea) {
textarea.selectionStart = 6;
textarea.selectionEnd = 11;
click(`button.list`);
andThen(() => {
await click(`button.list`);
assert.equal(this.get("value"), `hello\n\n1. world\n\n.`);
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 15);
});
click(`button.list`);
andThen(() => {
await click(`button.list`);
assert.equal(this.get("value"), `hello\n\nworld\n\n.`);
assert.equal(textarea.selectionStart, 7);
assert.equal(textarea.selectionEnd, 12);
});
});
testCase(`list button with line sequence`, function(assert, textarea) {
testCase(`list button with line sequence`, async function(assert, textarea) {
this.set("value", "Hello\n\nWorld\n\nEvil");
andThen(() => {
textarea.selectionStart = 0;
textarea.selectionEnd = 18;
});
click(`button.list`);
andThen(() => {
await click(`button.list`);
assert.equal(this.get("value"), "1. Hello\n\n2. World\n\n3. Evil");
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 27);
});
click(`button.list`);
andThen(() => {
await click(`button.list`);
assert.equal(this.get("value"), "Hello\n\nWorld\n\nEvil");
assert.equal(textarea.selectionStart, 0);
assert.equal(textarea.selectionEnd, 18);
});
});
componentTest("clicking the toggle-direction button toggles the direction", {
@ -786,36 +649,31 @@ componentTest("clicking the toggle-direction button toggles the direction", {
this.siteSettings.default_locale = "en";
},
test(assert) {
async test(assert) {
const textarea = this.$("textarea.d-editor-input");
click("button.toggle-direction");
andThen(() => {
await click("button.toggle-direction");
assert.equal(textarea.attr("dir"), "rtl");
});
click("button.toggle-direction");
andThen(() => {
await click("button.toggle-direction");
assert.equal(textarea.attr("dir"), "ltr");
});
}
});
testCase(`doesn't jump to bottom with long text`, function(assert, textarea) {
testCase(`doesn't jump to bottom with long text`, async function(
assert,
textarea
) {
let longText = "hello world.";
for (let i = 0; i < 8; i++) {
longText = longText + longText;
}
this.set("value", longText);
andThen(() => {
$(textarea).scrollTop(0);
textarea.selectionStart = 3;
textarea.selectionEnd = 3;
});
click("button.bold");
andThen(() => {
await click("button.bold");
assert.equal($(textarea).scrollTop(), 0, "it stays scrolled up");
});
});
componentTest("emoji", {
@ -834,45 +692,35 @@ componentTest("emoji", {
});
this.set("value", "hello world.");
},
test(assert) {
async test(assert) {
jumpEnd(this.$("textarea.d-editor-input")[0]);
click("button.emoji");
await click("button.emoji");
click(
await click(
'.emoji-picker .section[data-section="people"] button.emoji[title="grinning"]'
);
andThen(() => {
assert.equal(this.get("value"), "hello world.:grinning:");
});
}
});
testCase("replace-text event by default", function(assert) {
testCase("replace-text event by default", async function(assert) {
this.set("value", "red green blue");
andThen(() => {
this.container
await this.container
.lookup("app-events:main")
.trigger("composer:replace-text", "green", "yellow");
});
andThen(() => {
assert.equal(this.get("value"), "red green blue");
});
});
composerTestCase("replace-text event for composer", function(assert) {
composerTestCase("replace-text event for composer", async function(assert) {
this.set("value", "red green blue");
andThen(() => {
this.container
await this.container
.lookup("app-events:main")
.trigger("composer:replace-text", "green", "yellow");
});
andThen(() => {
assert.equal(this.get("value"), "red yellow blue");
});
});
(() => {
@ -949,39 +797,26 @@ composerTestCase("replace-text event for composer", function(assert) {
return [start, end - start];
}
function formatTextWithSelection(text, [start, len]) {
return [
'"',
text.substr(0, start),
"<",
text.substr(start, len),
">",
text.substr(start + len),
'"'
].join("");
}
for (let i = 0; i < CASES.length; i++) {
const CASE = CASES[i];
composerTestCase(`replace-text event: ${CASE.description}`, function(
// prettier-ignore
composerTestCase(`replace-text event: ${CASE.description}`, async function( // eslint-disable-line no-loop-func
assert,
textarea
) {
this.set("value", BEFORE);
setSelection(textarea, CASE.before);
andThen(() => {
await setSelection(textarea, CASE.before);
this.container
.lookup("app-events:main")
.trigger("composer:replace-text", "green", "yellow");
});
andThen(() => {
let expect = formatTextWithSelection(AFTER, CASE.after);
let actual = formatTextWithSelection(
let expect = await formatTextWithSelection(AFTER, CASE.after); // eslint-disable-line no-undef
let actual = await formatTextWithSelection( // eslint-disable-line no-undef
this.get("value"),
getSelection(textarea)
);
assert.equal(actual, expect);
});
});
}
})();

View file

@ -11,7 +11,6 @@ componentTest("default", {
},
test(assert) {
andThen(() => {
assert.equal(
selectKit()
.header()
@ -24,7 +23,6 @@ componentTest("default", {
.value(),
"bold,italic"
);
});
}
});
@ -36,14 +34,12 @@ componentTest("with empty string as value", {
},
test(assert) {
andThen(() => {
assert.equal(
selectKit()
.header()
.value(),
""
);
});
}
});
@ -55,14 +51,12 @@ componentTest("with only setting value", {
},
test(assert) {
andThen(() => {
assert.equal(
selectKit()
.header()
.value(),
"bold,italic"
);
});
}
});
@ -74,35 +68,26 @@ componentTest("interactions", {
this.set("choices", ["bold", "italic", "underline"]);
},
test(assert) {
async test(assert) {
const listSetting = selectKit();
listSetting.expand().selectRowByValue("underline");
await listSetting.expand();
await listSetting.selectRowByValue("underline");
andThen(() => {
assert.equal(listSetting.header().value(), "bold,italic,underline");
});
listSetting.expand().fillInFilter("strike");
await listSetting.expand();
await listSetting.fillInFilter("strike");
andThen(() => {
assert.equal(listSetting.highlightedRow().value(), "strike");
});
listSetting.keyboard().enter();
await listSetting.keyboard("enter");
andThen(() => {
assert.equal(
listSetting.header().value(),
"bold,italic,underline,strike"
);
});
assert.equal(listSetting.header().value(), "bold,italic,underline,strike");
listSetting.keyboard().backspace();
listSetting.keyboard().backspace();
await listSetting.keyboard("backspace");
await listSetting.keyboard("backspace");
andThen(() => {
assert.equal(listSetting.header().value(), "bold,italic,underline");
});
}
});

View file

@ -15,14 +15,12 @@ componentTest("with objects and values", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.value(),
"1,2"
);
});
}
});
@ -34,13 +32,11 @@ componentTest("with title", {
},
test(assert) {
andThen(() =>
assert.equal(
selectKit()
.header()
.title(),
"My title"
)
);
}
});
@ -58,10 +54,9 @@ componentTest("interactions", {
this.set("values", [1, 2]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -69,11 +64,9 @@ componentTest("interactions", {
"robin",
"it highlights the first content row"
);
});
this.set("none", "test.none");
await this.set("none", "test.none");
andThen(() => {
assert.ok(
this.get("subject")
.noneRow()
@ -86,12 +79,10 @@ componentTest("interactions", {
"robin",
"it highlights the first content row"
);
});
this.get("subject").selectRowByValue(3);
this.get("subject").expand();
await this.get("subject").selectRowByValue(3);
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -99,11 +90,9 @@ componentTest("interactions", {
"none",
"it highlights none row if no content"
);
});
this.get("subject").fillInFilter("joffrey");
await this.get("subject").fillInFilter("joffrey");
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -111,13 +100,9 @@ componentTest("interactions", {
"joffrey",
"it highlights create row when filling filter"
);
});
this.get("subject")
.keyboard()
.enter();
await this.get("subject").keyboard("enter");
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -125,13 +110,9 @@ componentTest("interactions", {
"none",
"it highlights none row after creating content and no content left"
);
});
this.get("subject")
.keyboard()
.backspace();
await this.get("subject").keyboard("backspace");
andThen(() => {
const $lastSelectedName = this.get("subject")
.header()
.el()
@ -142,20 +123,16 @@ componentTest("interactions", {
$lastSelectedName.hasClass("is-highlighted"),
"it highlights the last selected name when using backspace"
);
});
this.get("subject")
.keyboard()
.backspace();
await this.get("subject").keyboard("backspace");
andThen(() => {
const $lastSelectedName = this.get("subject")
const $lastSelectedName1 = this.get("subject")
.header()
.el()
.find(".selected-name")
.last();
assert.equal(
$lastSelectedName.attr("data-name"),
$lastSelectedName1.attr("data-name"),
"robin",
"it removes the previous highlighted selected content"
);
@ -165,58 +142,39 @@ componentTest("interactions", {
.exists(),
"generated content shouldnt appear in content when removed"
);
});
this.get("subject")
.keyboard()
.selectAll();
await this.get("subject").keyboard("selectAll");
andThen(() => {
const $highlightedSelectedNames = this.get("subject")
const $highlightedSelectedNames2 = this.get("subject")
.header()
.el()
.find(".selected-name.is-highlighted");
assert.equal(
$highlightedSelectedNames.length,
$highlightedSelectedNames2.length,
3,
"it highlights each selected name"
);
});
this.get("subject")
.keyboard()
.backspace();
await this.get("subject").keyboard("backspace");
andThen(() => {
const $selectedNames = this.get("subject")
.header()
.el()
.find(".selected-name");
assert.equal($selectedNames.length, 0, "it removed all selected content");
});
andThen(() => {
assert.ok(this.get("subject").isFocused());
assert.ok(this.get("subject").isExpanded());
});
this.get("subject")
.keyboard()
.escape();
await this.get("subject").keyboard("escape");
andThen(() => {
assert.ok(this.get("subject").isFocused());
assert.notOk(this.get("subject").isExpanded());
});
this.get("subject")
.keyboard()
.escape();
await this.get("subject").keyboard("escape");
andThen(() => {
assert.notOk(this.get("subject").isFocused());
assert.notOk(this.get("subject").isExpanded());
});
}
});
@ -227,16 +185,14 @@ componentTest("with limitMatches", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(
this.get("subject")
.el()
.find(".select-kit-row").length,
2
)
);
}
});
@ -248,26 +204,22 @@ componentTest("with minimum", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(
this.get("subject").validationMessage(),
"Select at least 1 item."
)
);
this.get("subject").selectRowByValue("sam");
await this.get("subject").selectRowByValue("sam");
andThen(() => {
assert.equal(
this.get("subject")
.header()
.label(),
"sam"
);
});
}
});
@ -280,22 +232,18 @@ componentTest("with minimumLabel", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(this.get("subject").validationMessage(), "min 1")
);
assert.equal(this.get("subject").validationMessage(), "min 1");
this.get("subject").selectRowByValue("jeff");
await this.get("subject").selectRowByValue("jeff");
andThen(() => {
assert.equal(
this.get("subject")
.header()
.label(),
"jeff"
);
});
}
});

View file

@ -16,30 +16,24 @@ componentTest("updating the content refreshes the list", {
this.set("content", [{ id: 1, name: "BEFORE" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"BEFORE"
);
});
andThen(() => {
this.set("content", [{ id: 1, name: "AFTER" }]);
});
await this.set("content", [{ id: 1, name: "AFTER" }]);
andThen(() => {
assert.equal(
this.get("subject")
.rowByValue(1)
.name(),
"AFTER"
);
});
}
});
@ -51,10 +45,9 @@ componentTest("accepts a value by reference", {
this.set("content", [{ id: 1, name: "robin" }, { id: 2, name: "regis" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.selectedRow()
@ -62,13 +55,10 @@ componentTest("accepts a value by reference", {
"robin",
"it highlights the row corresponding to the value"
);
});
this.get("subject").selectRowByValue(1);
await this.get("subject").selectRowByValue(1);
andThen(() => {
assert.equal(this.get("value"), 1, "it mutates the value");
});
}
});
@ -89,10 +79,9 @@ componentTest("no default icon", {
componentTest("default search icon", {
template: "{{single-select filterable=true}}",
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.ok(
exists(
this.get("subject")
@ -101,17 +90,15 @@ componentTest("default search icon", {
),
"it has an icon"
);
});
}
});
componentTest("with no search icon", {
template: "{{single-select filterable=true filterIcon=null}}",
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.notOk(
exists(
this.get("subject")
@ -120,17 +107,15 @@ componentTest("with no search icon", {
),
"it has no icon"
);
});
}
});
componentTest("custom search icon", {
template: '{{single-select filterable=true filterIcon="shower"}}',
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.ok(
this.get("subject")
.filter()
@ -138,20 +123,19 @@ componentTest("custom search icon", {
.hasClass("d-icon-shower"),
"it has a the correct icon"
);
});
}
});
componentTest("is expandable", {
template: "{{single-select}}",
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => assert.ok(this.get("subject").isExpanded()));
assert.ok(this.get("subject").isExpanded());
this.get("subject").collapse();
await this.get("subject").collapse();
andThen(() => assert.notOk(this.get("subject").isExpanded()));
assert.notOk(this.get("subject").isExpanded());
}
});
@ -164,17 +148,15 @@ componentTest("accepts custom value/name keys", {
this.set("content", [{ identifier: 1, item: "robin" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.selectedRow()
.name(),
"robin"
);
});
}
});
@ -185,14 +167,12 @@ componentTest("doesnt render collection content before first expand", {
this.set("content", [{ value: 1, name: "robin" }]);
},
test(assert) {
async test(assert) {
assert.notOk(exists(find(".select-kit-collection")));
this.get("subject").expand();
await this.get("subject").expand();
andThen(() => {
assert.ok(exists(find(".select-kit-collection")));
});
}
});
@ -203,21 +183,18 @@ componentTest("dynamic headerText", {
this.set("content", [{ id: 1, name: "robin" }, { id: 2, name: "regis" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"robin"
);
});
this.get("subject").selectRowByValue(2);
await this.get("subject").selectRowByValue(2);
andThen(() => {
assert.equal(
this.get("subject")
.header()
@ -225,7 +202,6 @@ componentTest("dynamic headerText", {
"regis",
"it changes header text"
);
});
}
});
@ -239,10 +215,9 @@ componentTest("supports custom row template", {
});
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.rowByValue(1)
@ -251,7 +226,6 @@ componentTest("supports custom row template", {
.trim(),
"<b>robin</b>"
);
});
}
});
@ -266,23 +240,18 @@ componentTest("supports converting select value to integer", {
]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(
this.get("subject")
.selectedRow()
.name(),
"régis"
)
);
andThen(() => {
this.set("value", 1);
});
await this.set("value", 1);
andThen(() => {
assert.equal(
this.get("subject")
.selectedRow()
@ -290,7 +259,6 @@ componentTest("supports converting select value to integer", {
"robin",
"it works with dynamic content"
);
});
}
});
@ -305,23 +273,18 @@ componentTest("supports converting string as boolean to boolean", {
]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(
this.get("subject")
.selectedRow()
.name(),
"ASC"
)
);
andThen(() => {
this.set("value", false);
});
await this.set("value", false);
andThen(() => {
assert.equal(
this.get("subject")
.selectedRow()
@ -329,7 +292,6 @@ componentTest("supports converting string as boolean to boolean", {
"DESC",
"it works with dynamic content"
);
});
}
});
@ -340,13 +302,10 @@ componentTest("supports keyboard events", {
this.set("content", [{ id: 1, name: "robin" }, { id: 2, name: "regis" }]);
},
test(assert) {
this.get("subject")
.expand()
.keyboard()
.down();
async test(assert) {
await this.get("subject").expand();
await this.get("subject").keyboard("down");
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -354,13 +313,9 @@ componentTest("supports keyboard events", {
"regis",
"the next row is highlighted"
);
});
this.get("subject")
.keyboard()
.down();
await this.get("subject").keyboard("down");
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -368,13 +323,9 @@ componentTest("supports keyboard events", {
"robin",
"it returns to the first row"
);
});
this.get("subject")
.keyboard()
.up();
await this.get("subject").keyboard("up");
andThen(() => {
assert.equal(
this.get("subject")
.highlightedRow()
@ -382,13 +333,9 @@ componentTest("supports keyboard events", {
"regis",
"it highlights the last row"
);
});
this.get("subject")
.keyboard()
.enter();
await this.get("subject").keyboard("enter");
andThen(() => {
assert.equal(
this.get("subject")
.selectedRow()
@ -400,32 +347,23 @@ componentTest("supports keyboard events", {
this.get("subject").isExpanded(),
"it collapses the select box when selecting a row"
);
});
this.get("subject")
.expand()
.keyboard()
.escape();
await this.get("subject").expand();
await this.get("subject").keyboard("escape");
andThen(() => {
assert.notOk(
this.get("subject").isExpanded(),
"it collapses the select box"
);
});
this.get("subject")
.expand()
.fillInFilter("regis")
.keyboard()
.tab();
await this.get("subject").expand();
await this.get("subject").fillInFilter("regis");
await this.get("subject").keyboard("tab");
andThen(() => {
assert.notOk(
this.get("subject").isExpanded(),
"it collapses the select box when selecting a row"
);
});
}
});
@ -442,13 +380,11 @@ componentTest("with allowInitialValueMutation", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("value"),
"1",
"it mutates the value on initial rendering"
);
});
}
});
@ -464,10 +400,9 @@ componentTest("support appending content through plugin api", {
this.set("content", [{ id: "1", name: "robin" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(this.get("subject").rows().length, 2);
assert.equal(
this.get("subject")
@ -475,9 +410,8 @@ componentTest("support appending content through plugin api", {
.name(),
"regis"
);
});
andThen(() => clearCallbacks());
clearCallbacks();
}
});
@ -500,10 +434,9 @@ componentTest("support modifying content through plugin api", {
]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(this.get("subject").rows().length, 3);
assert.equal(
this.get("subject")
@ -511,9 +444,8 @@ componentTest("support modifying content through plugin api", {
.name(),
"sam"
);
});
andThen(() => clearCallbacks());
clearCallbacks();
}
});
@ -530,10 +462,9 @@ componentTest("support prepending content through plugin api", {
this.set("content", [{ id: "1", name: "robin" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(this.get("subject").rows().length, 2);
assert.equal(
this.get("subject")
@ -541,9 +472,8 @@ componentTest("support prepending content through plugin api", {
.name(),
"regis"
);
});
andThen(() => clearCallbacks());
clearCallbacks();
}
});
@ -561,16 +491,13 @@ componentTest("support modifying on select behavior through plugin api", {
this.set("content", [{ id: "1", name: "robin" }]);
},
test(assert) {
this.get("subject")
.expand()
.selectRowByValue(1);
async test(assert) {
await this.get("subject").expand();
await this.get("subject").selectRowByValue(1);
andThen(() => {
assert.equal(find(".on-select-test").html(), "1");
});
andThen(() => clearCallbacks());
clearCallbacks();
}
});
@ -582,30 +509,24 @@ componentTest("with nameChanges", {
this.set("content", [this.get("robin")]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"robin"
);
});
andThen(() => {
this.set("robin.name", "robin2");
});
await this.set("robin.name", "robin2");
andThen(() => {
assert.equal(
this.get("subject")
.header()
.name(),
"robin2"
);
});
}
});
@ -616,10 +537,9 @@ componentTest("with null value", {
this.set("content", [{ name: "robin" }]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => {
assert.equal(
this.get("subject")
.header()
@ -632,7 +552,6 @@ componentTest("with null value", {
.value(),
undefined
);
});
}
});
@ -643,10 +562,10 @@ componentTest("with collection header", {
this.set("collectionHeader", "<h2>Hello</h2>");
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() => assert.ok(exists(".collection-header h2")));
assert.ok(exists(".collection-header h2"));
}
});
@ -658,13 +577,11 @@ componentTest("with title", {
},
test(assert) {
andThen(() =>
assert.equal(
this.get("subject")
.header()
.title(),
"My title"
)
);
}
});
@ -686,16 +603,14 @@ componentTest("support modifying header computed content through plugin api", {
},
test(assert) {
andThen(() => {
assert.equal(
this.get("subject")
.header()
.title(),
"Not so evil"
);
});
andThen(() => clearCallbacks());
clearCallbacks();
}
});
@ -706,16 +621,14 @@ componentTest("with limitMatches", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(
this.get("subject")
.el()
.find(".select-kit-row").length,
2
)
);
}
});
@ -728,26 +641,22 @@ componentTest("with minimum", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(
this.get("subject").validationMessage(),
"Select at least 1 item."
)
);
this.get("subject").selectRowByValue("sam");
await this.get("subject").selectRowByValue("sam");
andThen(() => {
assert.equal(
this.get("subject")
.header()
.label(),
"sam"
);
});
}
});
@ -760,23 +669,19 @@ componentTest("with minimumLabel", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
async test(assert) {
await this.get("subject").expand();
andThen(() =>
assert.equal(this.get("subject").validationMessage(), "min 1")
);
assert.equal(this.get("subject").validationMessage(), "min 1");
this.get("subject").selectRowByValue("jeff");
await this.get("subject").selectRowByValue("jeff");
andThen(() => {
assert.equal(
this.get("subject")
.header()
.label(),
"jeff"
);
});
}
});
@ -787,11 +692,10 @@ componentTest("with accents in filter", {
this.set("content", ["sam", "jeff", "neil"]);
},
test(assert) {
this.get("subject").expand();
this.get("subject").fillInFilter("jéff");
async test(assert) {
await this.get("subject").expand();
await this.get("subject").fillInFilter("jéff");
andThen(() => {
assert.equal(this.get("subject").rows().length, 1);
assert.equal(
this.get("subject")
@ -799,7 +703,6 @@ componentTest("with accents in filter", {
.name(),
"jeff"
);
});
}
});
@ -810,11 +713,10 @@ componentTest("with accents in content", {
this.set("content", ["sam", "jéff", "neil"]);
},
test(assert) {
this.get("subject").expand();
this.get("subject").fillInFilter("jeff");
async test(assert) {
await this.get("subject").expand();
await this.get("subject").fillInFilter("jeff");
andThen(() => {
assert.equal(this.get("subject").rows().length, 1);
assert.equal(
this.get("subject")
@ -822,6 +724,5 @@ componentTest("with accents in content", {
.name(),
"jéff"
);
});
}
});

View file

@ -22,7 +22,7 @@ componentTest("default", {
},
async test(assert) {
await this.get("subject").expandAwait();
await this.get("subject").expand();
assert.equal(
this.get("subject")
@ -55,7 +55,7 @@ componentTest("default", {
"it doesnt preselect first row"
);
await this.get("subject").selectRowByValueAwait("share");
await this.get("subject").selectRowByValue("share");
assert.equal(this.get("value"), null, "it resets the value");
}

View file

@ -33,7 +33,7 @@ componentTest("regular topic notification level descriptions", {
"{{topic-notifications-options value=topic.details.notification_level topic=topic}}",
async test(assert) {
await selectKit().expandAwait();
await selectKit().expand();
await this.set("topic", buildTopic("regular"));
const uiTexts = extractDescs(selectKit().rows());
@ -59,7 +59,7 @@ componentTest("PM topic notification level descriptions", {
"{{topic-notifications-options value=topic.details.notification_level topic=topic}}",
async test(assert) {
await selectKit().expandAwait();
await selectKit().expand();
await this.set("topic", buildTopic("private_message"));
const uiTexts = extractDescs(selectKit().rows());

View file

@ -0,0 +1,15 @@
Ember.Test.registerAsyncHelper("formatTextWithSelection", function(
app,
text,
[start, len]
) {
return [
'"',
text.substr(0, start),
"<",
text.substr(start, len),
">",
text.substr(start + len),
'"'
].join("");
});

View file

@ -68,6 +68,47 @@ Ember.Test.registerAsyncHelper("selectKitSelectRowByIndex", function(
click(find(selector + " .select-kit-row").eq(index));
});
Ember.Test.registerAsyncHelper("keyboardHelper", function(
app,
value,
target,
selector
) {
function createEvent(element, keyCode, options) {
element = element || ".filter-input";
selector = find(selector).find(element);
options = options || {};
var type = options.type || "keydown";
var event = jQuery.Event(type);
event.keyCode = keyCode;
if (options && options.metaKey) {
event.metaKey = true;
}
andThen(() => {
find(selector).trigger(event);
});
}
switch (value) {
case "enter":
return createEvent(target, 13);
case "backspace":
return createEvent(target, 8);
case "selectAll":
return createEvent(target, 65, { metaKey: true });
case "escape":
return createEvent(target, 27);
case "down":
return createEvent(target, 40);
case "up":
return createEvent(target, 38);
case "tab":
return createEvent(target, 9);
}
});
// eslint-disable-next-line no-unused-vars
function selectKit(selector) {
selector = selector || ".select-kit";
@ -132,65 +173,13 @@ function selectKit(selector) {
};
}
function keyboardHelper(eventSelector) {
function createEvent(target, keyCode, options) {
target = target || ".filter-input";
eventSelector = find(eventSelector).find(target);
options = options || {};
andThen(function() {
var type = options.type || "keydown";
var event = jQuery.Event(type);
event.keyCode = keyCode;
if (options && options.metaKey) {
event.metaKey = true;
}
find(eventSelector).trigger(event);
});
}
return {
down: function(target) {
createEvent(target, 40);
},
up: function(target) {
createEvent(target, 38);
},
escape: function(target) {
createEvent(target, 27);
},
enter: function(target) {
createEvent(target, 13);
},
tab: function(target) {
createEvent(target, 9);
},
backspace: function(target) {
createEvent(target, 8);
},
selectAll: function(target) {
createEvent(target, 65, { metaKey: true });
}
};
}
return {
expandAwait: function() {
expand: function() {
return expandSelectKit(selector);
},
expand: function() {
expandSelectKit(selector);
return selectKit(selector);
},
collapseAwait: function() {
return collapseSelectKit(selector);
},
collapse: function() {
collapseSelectKit(selector);
return selectKit(selector);
return collapseSelectKit(selector);
},
selectRowByIndex: function(index) {
@ -198,13 +187,8 @@ function selectKit(selector) {
return selectKit(selector);
},
selectRowByValueAwait: function(value) {
return selectKitSelectRowByValue(value, selector);
},
selectRowByValue: function(value) {
selectKitSelectRowByValue(value, selector);
return selectKit(selector);
return selectKitSelectRowByValue(value, selector);
},
selectRowByName: function(name) {
@ -213,25 +197,15 @@ function selectKit(selector) {
},
selectNoneRow: function() {
selectKitSelectNoneRow(selector);
return selectKit(selector);
},
selectNoneRowAwait: function() {
return selectKitSelectNoneRow(selector);
},
fillInFilter: function(filter) {
selectKitFillInFilter(filter, selector);
return selectKit(selector);
},
fillInFilterAwait: function(filter) {
return selectKitFillInFilter(filter, selector);
},
keyboard: function() {
return keyboardHelper(selector);
keyboard: function(value, target) {
return keyboardHelper(value, target, selector);
},
isExpanded: function() {

View file

@ -33,6 +33,7 @@
//= require helpers/assertions
//= require helpers/select-kit-helper
//= require helpers/d-editor-helper
//= require helpers/qunit-helpers
//= require_tree ./fixtures