Skip to content

A platform for community discussion. Free, open, simple.

DEV: migrate acceptance tests to async await - invite, login, mobile

Maja Komel2e966466599f
diff --git a/test/javascripts/acceptance/invite-accept-test.js.es6 b/test/javascripts/acceptance/invite-accept-test.js.es6
index 024b5ac9d7f..6078bce9ef6 100644
--- a/test/javascripts/acceptance/invite-accept-test.js.es6
+++ b/test/javascripts/acceptance/invite-accept-test.js.es6
@@ -7,7 +7,7 @@ acceptance("Invite Accept", {
}
});
-QUnit.test("Invite Acceptance Page", assert => {
+QUnit.test("Invite Acceptance Page", async assert => {
PreloadStore.store("invite_info", {
invited_by: {
id: 123,
@@ -20,56 +20,46 @@ QUnit.test("Invite Acceptance Page", assert => {
username: "invited"
});
- visit("/invites/myvalidinvitetoken");
- andThen(() => {
- assert.ok(exists("#new-account-username"), "shows the username input");
- assert.equal(
- find("#new-account-username").val(),
- "invited",
- "username is prefilled"
- );
- assert.ok(exists("#new-account-name"), "shows the name input");
- assert.ok(exists("#new-account-password"), "shows the password input");
- assert.ok(
- exists(".invites-show .btn-primary:disabled"),
- "submit is disabled because name is not filled"
- );
- });
+ await visit("/invites/myvalidinvitetoken");
+ assert.ok(exists("#new-account-username"), "shows the username input");
+ assert.equal(
+ find("#new-account-username").val(),
+ "invited",
+ "username is prefilled"
+ );
+ assert.ok(exists("#new-account-name"), "shows the name input");
+ assert.ok(exists("#new-account-password"), "shows the password input");
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is disabled because name is not filled"
+ );
- fillIn("#new-account-name", "John Doe");
- andThen(() => {
- assert.not(
- exists(".invites-show .btn-primary:disabled"),
- "submit is enabled"
- );
- });
+ await fillIn("#new-account-name", "John Doe");
+ assert.not(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is enabled"
+ );
- fillIn("#new-account-username", "a");
- andThen(() => {
- assert.ok(exists(".username-input .bad"), "username is not valid");
- assert.ok(
- exists(".invites-show .btn-primary:disabled"),
- "submit is disabled"
- );
- });
+ await fillIn("#new-account-username", "a");
+ assert.ok(exists(".username-input .bad"), "username is not valid");
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is disabled"
+ );
- fillIn("#new-account-password", "aaa");
- andThen(() => {
- assert.ok(exists(".password-input .bad"), "password is not valid");
- assert.ok(
- exists(".invites-show .btn-primary:disabled"),
- "submit is disabled"
- );
- });
+ await fillIn("#new-account-password", "aaa");
+ assert.ok(exists(".password-input .bad"), "password is not valid");
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is disabled"
+ );
- fillIn("#new-account-username", "validname");
- fillIn("#new-account-password", "secur3ty4Y0uAndMe");
- andThen(() => {
- assert.ok(exists(".username-input .good"), "username is valid");
- assert.ok(exists(".password-input .good"), "password is valid");
- assert.not(
- exists(".invites-show .btn-primary:disabled"),
- "submit is enabled"
- );
- });
+ await fillIn("#new-account-username", "validname");
+ await fillIn("#new-account-password", "secur3ty4Y0uAndMe");
+ assert.ok(exists(".username-input .good"), "username is valid");
+ assert.ok(exists(".password-input .good"), "password is valid");
+ assert.not(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is enabled"
+ );
});
diff --git a/test/javascripts/acceptance/invite-show-user-fields-test.js.es6 b/test/javascripts/acceptance/invite-show-user-fields-test.js.es6
index f007687955f..e8ff05d8e03 100644
--- a/test/javascripts/acceptance/invite-show-user-fields-test.js.es6
+++ b/test/javascripts/acceptance/invite-show-user-fields-test.js.es6
@@ -25,51 +25,41 @@ acceptance("Accept Invite - User Fields", {
}
});
-QUnit.test("accept invite with user fields", assert => {
- visit("/invites/myvalidinvitetoken");
- andThen(() => {
- assert.ok(exists(".invites-show"), "shows the accept invite page");
- assert.ok(exists(".user-field"), "it has at least one user field");
- assert.ok(
- exists(".invites-show .btn-primary:disabled"),
- "submit is disabled"
- );
- });
+QUnit.test("accept invite with user fields", async assert => {
+ await visit("/invites/myvalidinvitetoken");
+ assert.ok(exists(".invites-show"), "shows the accept invite page");
+ assert.ok(exists(".user-field"), "it has at least one user field");
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is disabled"
+ );
- fillIn("#new-account-name", "John Doe");
- fillIn("#new-account-username", "validname");
- fillIn("#new-account-password", "secur3ty4Y0uAndMe");
+ await fillIn("#new-account-name", "John Doe");
+ await fillIn("#new-account-username", "validname");
+ await fillIn("#new-account-password", "secur3ty4Y0uAndMe");
- andThen(() => {
- assert.ok(exists(".username-input .good"), "username is valid");
- assert.ok(
- exists(".invites-show .btn-primary:disabled"),
- "submit is still disabled due to lack of user fields"
- );
- });
+ assert.ok(exists(".username-input .good"), "username is valid");
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit 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(
- exists(".invites-show .btn-primary:disabled"),
- "submit is disabled because field is not checked"
- );
- });
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is disabled because field is not checked"
+ );
- click(".user-field input[type=checkbox]");
- andThen(() => {
- assert.not(
- exists(".invites-show .btn-primary:disabled"),
- "submit is enabled because field is checked"
- );
- });
+ await click(".user-field input[type=checkbox]");
+ assert.not(
+ exists(".invites-show .btn-primary:disabled"),
+ "submit is enabled because field is checked"
+ );
- click(".user-field input[type=checkbox]");
- andThen(() => {
- assert.ok(
- exists(".invites-show .btn-primary:disabled"),
- "unclicking the checkbox disables the submit"
- );
- });
+ await click(".user-field input[type=checkbox]");
+ assert.ok(
+ exists(".invites-show .btn-primary:disabled"),
+ "unclicking the checkbox disables the submit"
+ );
});
diff --git a/test/javascripts/acceptance/login-required-test.js.es6 b/test/javascripts/acceptance/login-required-test.js.es6
index f508e9612ff..ba03527a56a 100644
--- a/test/javascripts/acceptance/login-required-test.js.es6
+++ b/test/javascripts/acceptance/login-required-test.js.es6
@@ -6,28 +6,16 @@ acceptance("Login Required", {
}
});
-QUnit.test("redirect", assert => {
- visit("/latest");
- andThen(() => {
- assert.equal(currentPath(), "login", "it redirects them to login");
- });
+QUnit.test("redirect", async assert => {
+ await visit("/latest");
+ assert.equal(currentPath(), "login", "it redirects them to login");
- click("#site-logo");
- andThen(() => {
- assert.equal(
- currentPath(),
- "login",
- "clicking the logo keeps them on login"
- );
- });
+ await click("#site-logo");
+ assert.equal(currentPath(), "login", "clicking the logo keeps them on login");
- click("header .login-button");
- andThen(() => {
- assert.ok(exists(".login-modal"), "they can still access the login modal");
- });
+ await click("header .login-button");
+ assert.ok(exists(".login-modal"), "they can still access the login modal");
- click(".modal-header .close");
- andThen(() => {
- assert.ok(invisible(".login-modal"), "it closes the login modal");
- });
+ await click(".modal-header .close");
+ assert.ok(invisible(".login-modal"), "it closes the login modal");
});
diff --git a/test/javascripts/acceptance/login-with-email-disabled-test.js.es6 b/test/javascripts/acceptance/login-with-email-disabled-test.js.es6
index 28b59a2f2c3..ca8b3dbfb9c 100644
--- a/test/javascripts/acceptance/login-with-email-disabled-test.js.es6
+++ b/test/javascripts/acceptance/login-with-email-disabled-test.js.es6
@@ -7,19 +7,17 @@ acceptance("Login with email disabled", {
}
});
-QUnit.test("with email button", assert => {
- visit("/");
- click("header .login-button");
+QUnit.test("with email button", async assert => {
+ await visit("/");
+ await click("header .login-button");
- andThen(() => {
- assert.ok(
- exists(".btn-social.facebook"),
- "it displays the facebook login button"
- );
+ assert.ok(
+ exists(".btn-social.facebook"),
+ "it displays the facebook login button"
+ );
- assert.notOk(
- exists(".login-with-email-button"),
- "it displays the login with email button"
- );
- });
+ assert.notOk(
+ exists(".login-with-email-button"),
+ "it displays the login with email button"
+ );
});
diff --git a/test/javascripts/acceptance/mobile-discovery-test.js.es6 b/test/javascripts/acceptance/mobile-discovery-test.js.es6
index 76237d227b2..9accdfd1af5 100644
--- a/test/javascripts/acceptance/mobile-discovery-test.js.es6
+++ b/test/javascripts/acceptance/mobile-discovery-test.js.es6
@@ -1,15 +1,11 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Topic Discovery - Mobile", { mobileView: true });
-QUnit.test("Visit Discovery Pages", assert => {
- visit("/");
- andThen(() => {
- assert.ok(exists(".topic-list"), "The list of topics was rendered");
- assert.ok(exists(".topic-list .topic-list-item"), "has topics");
- });
+QUnit.test("Visit Discovery Pages", async assert => {
+ await visit("/");
+ assert.ok(exists(".topic-list"), "The list of topics was rendered");
+ assert.ok(exists(".topic-list .topic-list-item"), "has topics");
- visit("/categories");
- andThen(() => {
- assert.ok(exists(".category"), "has a list of categories");
- });
+ await visit("/categories");
+ assert.ok(exists(".category"), "has a list of categories");
});
diff --git a/test/javascripts/acceptance/mobile-sign-in-test.js.es6 b/test/javascripts/acceptance/mobile-sign-in-test.js.es6
index 7d3760d8fb7..fae44c50209 100644
--- a/test/javascripts/acceptance/mobile-sign-in-test.js.es6
+++ b/test/javascripts/acceptance/mobile-sign-in-test.js.es6
@@ -2,10 +2,8 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Signing In - Mobile", { mobileView: true });
-QUnit.test("sign in", assert => {
- visit("/");
- click("header .login-button");
- andThen(() => {
- assert.ok(exists("#login-form"), "it shows the login modal");
- });
+QUnit.test("sign in", async assert => {
+ await visit("/");
+ await click("header .login-button");
+ assert.ok(exists("#login-form"), "it shows the login modal");
});
diff --git a/test/javascripts/acceptance/mobile-users-test.js.es6 b/test/javascripts/acceptance/mobile-users-test.js.es6
index f94226e4ac1..e35f7910699 100644
--- a/test/javascripts/acceptance/mobile-users-test.js.es6
+++ b/test/javascripts/acceptance/mobile-users-test.js.es6
@@ -2,9 +2,7 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("User Directory - Mobile", { mobileView: true });
-QUnit.test("Visit Page", assert => {
- visit("/users");
- andThen(() => {
- assert.ok(exists(".directory .user"), "has a list of users");
- });
+QUnit.test("Visit Page", async assert => {
+ await visit("/users");
+ assert.ok(exists(".directory .user"), "has a list of users");
});
diff --git a/test/javascripts/acceptance/modal-test.js.es6 b/test/javascripts/acceptance/modal-test.js.es6
index 9075a29f730..11754b8b52a 100644
--- a/test/javascripts/acceptance/modal-test.js.es6
+++ b/test/javascripts/acceptance/modal-test.js.es6
@@ -3,62 +3,48 @@ import showModal from "discourse/lib/show-modal";
acceptance("Modal");
-QUnit.test("modal", assert => {
- visit("/");
+QUnit.test("modal", async assert => {
+ await visit("/");
- andThen(() => {
- assert.ok(
- find(".d-modal:visible").length === 0,
- "there is no modal at first"
- );
- });
+ assert.ok(
+ find(".d-modal:visible").length === 0,
+ "there is no modal at first"
+ );
- click(".login-button");
- andThen(() => {
- assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
- });
+ await click(".login-button");
+ assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
- click(".modal-outer-container");
- andThen(() => {
- assert.ok(
- find(".d-modal:visible").length === 0,
- "modal should disappear when you click outside"
- );
- });
+ await click(".modal-outer-container");
+ assert.ok(
+ find(".d-modal:visible").length === 0,
+ "modal should disappear when you click outside"
+ );
- click(".login-button");
- andThen(() => {
- assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
- });
+ await click(".login-button");
+ assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
- keyEvent("#main-outlet", "keydown", 27);
- andThen(() => {
- assert.ok(
- find(".d-modal:visible").length === 0,
- "ESC should close the modal"
- );
- });
- andThen(() => {
- Ember.TEMPLATES["modal/not-dismissable"] = Ember.HTMLBars.compile(
- '{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}'
- );
- showModal("not-dismissable", {});
- });
- andThen(() => {
- assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
- });
- click(".modal-outer-container");
- andThen(() => {
- assert.ok(
- find(".d-modal:visible").length === 1,
- "modal should not disappear when you click outside"
- );
- });
- keyEvent("#main-outlet", "keydown", 27);
- andThen(() => {
- assert.ok(
- find(".d-modal:visible").length === 1,
- "ESC should not close the modal"
- );
- });
+ await keyEvent("#main-outlet", "keydown", 27);
+ assert.ok(
+ find(".d-modal:visible").length === 0,
+ "ESC should close the modal"
+ );
+
+ Ember.TEMPLATES["modal/not-dismissable"] = Ember.HTMLBars.compile(
+ '{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}'
+ );
+
+ Ember.run(() => showModal("not-dismissable", {}));
+
+ assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
+
+ await click(".modal-outer-container");
+ assert.ok(
+ find(".d-modal:visible").length === 1,
+ "modal should not disappear when you click outside"
+ );
+ await keyEvent("#main-outlet", "keydown", 27);
+ assert.ok(
+ find(".d-modal:visible").length === 1,
+ "ESC should not close the modal"
+ );
});