From 16a96635570612029c1e4de3df052c0d53a83e09 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sun, 10 Nov 2024 02:24:58 +0100 Subject: [PATCH] DEV: Use qunit-dom's `isDisabled`/`isEnabled` (#29675) --- .../tests/acceptance/create-account-test.js | 8 ++++---- .../tests/acceptance/forgot-password-test.js | 14 ++++++------- .../invite-show-user-fields-test.js | 20 +++++++++---------- .../tests/acceptance/sign-in-test.js | 20 +++++++++---------- .../tests/acceptance/tag-groups-test.js | 6 +++--- .../discourse/tests/acceptance/tags-test.js | 6 +++--- .../user-preferences-account-test.js | 4 ++-- .../components/invite-panel-test.js | 2 +- .../test/javascripts/component/poll-test.js | 2 +- 9 files changed, 38 insertions(+), 44 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/acceptance/create-account-test.js b/app/assets/javascripts/discourse/tests/acceptance/create-account-test.js index c560d3d747c..c29a476cc62 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/create-account-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/create-account-test.js @@ -48,8 +48,8 @@ acceptance("Create Account", function () { await click(".d-modal__footer .btn-primary"); assert - .dom(".d-modal__footer .btn-primary:disabled") - .exists("create account is disabled"); + .dom(".d-modal__footer .btn-primary") + .isDisabled("create account is disabled"); assert.verifySteps(["request"]); }); @@ -119,8 +119,8 @@ acceptance("Create Account - full_name_required", function (needs) { await click(".d-modal__footer .btn-primary"); assert - .dom(".d-modal__footer .btn-primary:disabled") - .exists("create account is disabled"); + .dom(".d-modal__footer .btn-primary") + .isDisabled("create account is disabled"); assert.verifySteps(["request"]); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/forgot-password-test.js b/app/assets/javascripts/discourse/tests/acceptance/forgot-password-test.js index c2dcf1912fb..0dde8ffe553 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/forgot-password-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/forgot-password-test.js @@ -19,10 +19,9 @@ acceptance("Forgot password", function (needs) { await click("header .login-button"); await click("#forgot-password-link"); - assert.ok( - query(".forgot-password-reset").disabled, - "it should disable the button until the field is filled" - ); + assert + .dom(".forgot-password-reset") + .isDisabled("disables the button until the field is filled"); await fillIn("#username-or-email", "someuser"); await click(".forgot-password-reset"); @@ -94,10 +93,9 @@ acceptance( await click("header .login-button"); await click("#forgot-password-link"); - assert.ok( - query(".forgot-password-reset").disabled, - "it should disable the button until the field is filled" - ); + assert + .dom(".forgot-password-reset") + .isDisabled("disables the button until the field is filled"); await fillIn("#username-or-email", "someuser"); await click(".forgot-password-reset"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/invite-show-user-fields-test.js b/app/assets/javascripts/discourse/tests/acceptance/invite-show-user-fields-test.js index 6bfee1b2495..4c612291ccf 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/invite-show-user-fields-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/invite-show-user-fields-test.js @@ -44,9 +44,7 @@ acceptance("Accept Invite - User Fields", function (needs) { await visit("/invites/myvalidinvitetoken"); assert.dom(".invites-show").exists("shows the accept invite page"); assert.dom(".user-field").exists("has at least one user field"); - assert - .dom(".invites-show .btn-primary:disabled") - .exists("submit is disabled"); + assert.dom(".invites-show .btn-primary").isDisabled("submit is disabled"); await fillIn("#new-account-name", "John Doe"); await fillIn("#new-account-username", "validname"); @@ -54,23 +52,23 @@ acceptance("Accept Invite - User Fields", function (needs) { assert.dom(".username-input .good").exists("username is valid"); assert - .dom(".invites-show .btn-primary:disabled") - .exists("submit is still disabled due to lack of user fields"); + .dom(".invites-show .btn-primary") + .isDisabled("submit is still disabled due to lack of user fields"); await fillIn(".user-field input[type=text]:nth-of-type(1)", "Barky"); assert - .dom(".invites-show .btn-primary:disabled") - .exists("submit is disabled because field is not checked"); + .dom(".invites-show .btn-primary") + .isDisabled("submit is disabled because field is not checked"); await click(".user-field input[type=checkbox]"); assert - .dom(".invites-show .btn-primary:disabled") - .doesNotExist("submit is enabled because field is checked"); + .dom(".invites-show .btn-primary") + .isEnabled("submit is enabled because field is checked"); await click(".user-field input[type=checkbox]"); assert - .dom(".invites-show .btn-primary:disabled") - .exists("unclicking the checkbox disables the submit"); + .dom(".invites-show .btn-primary") + .isDisabled("toggling the checkbox disables the submit"); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/sign-in-test.js b/app/assets/javascripts/discourse/tests/acceptance/sign-in-test.js index 72d22ddfa73..ffa5d394d7f 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sign-in-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sign-in-test.js @@ -14,8 +14,8 @@ acceptance("Signing In", function () { await click(".d-modal__footer .btn-primary"); assert.dom("#modal-alert").exists("displays the login error"); assert - .dom(".d-modal__footer .btn-primary:disabled") - .doesNotExist("enables the login button"); + .dom(".d-modal__footer .btn-primary") + .isEnabled("enables the login button"); // Test password unmasking assert @@ -30,8 +30,8 @@ acceptance("Signing In", function () { await fillIn("#login-account-password", "correct"); await click(".d-modal__footer .btn-primary"); assert - .dom(".d-modal__footer .btn-primary:disabled") - .exists("disables the login button"); + .dom(".d-modal__footer .btn-primary") + .isDisabled("disables the login button"); }); test("sign in - not activated", async function (assert) { @@ -92,15 +92,15 @@ acceptance("Signing In", function () { .isNotVisible("hides the username and password prompt"); assert.dom("#second-factor").isVisible("displays the second factor prompt"); assert - .dom(".d-modal__footer .btn-primary:disabled") - .doesNotExist("enables the login button"); + .dom(".d-modal__footer .btn-primary") + .isEnabled("enables the login button"); await fillIn("#login-second-factor", "123456"); await click(".d-modal__footer .btn-primary"); assert - .dom(".d-modal__footer .btn-primary:disabled") - .exists("disables the login button"); + .dom(".d-modal__footer .btn-primary") + .isDisabled("disables the login button"); }); test("security key", async function (assert) { @@ -133,9 +133,7 @@ acceptance("Signing In", function () { await fillIn("#login-second-factor", "123456"); await click(".d-modal__footer .btn-primary"); - assert - .dom(".d-modal__footer .btn-primary:disabled") - .exists("closes the modal when the code is valid"); + assert.dom(".d-modal__footer .btn-primary").isDisabled(); }); test("second factor backup - invalid token", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js b/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js index 9ac848dc101..d1b23f5ee1b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/tag-groups-test.js @@ -1,6 +1,6 @@ import { click, fillIn, visit } from "@ember/test-helpers"; import { test } from "qunit"; -import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; import { setPrefix } from "discourse-common/lib/get-url"; @@ -54,7 +54,7 @@ acceptance("Tag Groups", function (needs) { await tags.expand(); await tags.deselectItemByValue("monkey"); - assert.ok(!query(".tag-group-content .btn.btn-danger").disabled); + assert.dom(".tag-group-content .btn.btn-danger").isEnabled(); }); test("tag groups can have multiple groups added to them", async function (assert) { @@ -73,7 +73,7 @@ acceptance("Tag Groups", function (needs) { await groups.selectRowByIndex(1); await groups.selectRowByIndex(0); - assert.ok(!query(".tag-group-content .btn.btn-primary").disabled); + assert.dom(".tag-group-content .btn.btn-primary").isEnabled(); await click(".tag-group-content .btn.btn-primary"); await click(".tag-groups-sidebar li:first-child a"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js index 0e906c6a09a..ef4e61a1e65 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js @@ -235,7 +235,7 @@ acceptance("Tags listed by group", function (needs) { updateCurrentUser({ moderator: false, admin: false }); await visit("/tag/regular-tag"); - assert.dom("#create-topic:disabled").doesNotExist(); + assert.dom("#create-topic").isEnabled(); await visit("/tag/staff-only-tag"); assert.dom("#create-topic").isDisabled(); @@ -243,10 +243,10 @@ acceptance("Tags listed by group", function (needs) { updateCurrentUser({ moderator: true }); await visit("/tag/regular-tag"); - assert.dom("#create-topic:disabled").doesNotExist(); + assert.dom("#create-topic").isEnabled(); await visit("/tag/staff-only-tag"); - assert.dom("#create-topic:disabled").doesNotExist(); + assert.dom("#create-topic").isEnabled(); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js index e964a14ab81..d2cd38af86b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js @@ -78,10 +78,10 @@ acceptance("User Preferences - Account", function (needs) { await click(".username-preference__edit-username"); assert.dom(".username-preference__input").hasValue("eviltrout"); - assert.true(query(".username-preference__submit").disabled); + assert.dom(".username-preference__submit").isDisabled(); await fillIn(query(".username-preference__input"), "good_trout"); - assert.false(query(".username-preference__submit").disabled); + assert.dom(".username-preference__submit").isEnabled(); await click(".username-preference__submit"); await click(".dialog-container .btn-primary"); diff --git a/app/assets/javascripts/discourse/tests/integration/components/invite-panel-test.js b/app/assets/javascripts/discourse/tests/integration/components/invite-panel-test.js index 4f7a2ae0ff9..37b9434f949 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/invite-panel-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/invite-panel-test.js @@ -31,7 +31,7 @@ module("Integration | Component | invite-panel", function (hooks) { await input.expand(); await input.fillInFilter("eviltrout@example.com"); await input.selectRowByValue("eviltrout@example.com"); - assert.dom(".send-invite:disabled").doesNotExist(); + assert.dom(".send-invite").isEnabled(); await click(".generate-invite-link"); assert.strictEqual( diff --git a/plugins/poll/test/javascripts/component/poll-test.js b/plugins/poll/test/javascripts/component/poll-test.js index f453fa641b5..37f74a47ff3 100644 --- a/plugins/poll/test/javascripts/component/poll-test.js +++ b/plugins/poll/test/javascripts/component/poll-test.js @@ -201,7 +201,7 @@ module("Poll | Component | poll", function (hooks) { }); await render(hbs``); - assert.dom(".poll-buttons .cast-votes:disabled").exists(); + assert.dom(".poll-buttons .cast-votes").isDisabled(); await click( "li[data-poll-option-id='1f972d1df351de3ce35a787c89faad29'] button"