DEV: Use hasAttribute/hasAria/hasStyle in tests (#29568)

This commit is contained in:
Jarek Radosz
2024-11-04 11:30:38 +01:00
committed by GitHub
parent 9694d2477a
commit 380974ce00
31 changed files with 462 additions and 551 deletions

View File

@ -12,7 +12,6 @@ import {
acceptance, acceptance,
count, count,
exists, exists,
query,
queryAll, queryAll,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -55,11 +54,13 @@ acceptance("Admin - Site Settings", function (needs) {
test("links to staff action log", async function (assert) { test("links to staff action log", async function (assert) {
await visit("/admin/site_settings"); await visit("/admin/site_settings");
assert.strictEqual( assert
query(".row.setting .setting-label h3 a").getAttribute("href"), .dom(".row.setting .setting-label h3 a")
"/admin/logs/staff_action_logs?filters=%7B%22subject%22%3A%22title%22%2C%22action_name%22%3A%22change_site_setting%22%7D&force_refresh=true", .hasAttribute(
"it links to the staff action log" "href",
); "/admin/logs/staff_action_logs?filters=%7B%22subject%22%3A%22title%22%2C%22action_name%22%3A%22change_site_setting%22%7D&force_refresh=true",
"it links to the staff action log"
);
}); });
test("changing value updates dirty state", async function (assert) { test("changing value updates dirty state", async function (assert) {

View File

@ -68,10 +68,9 @@ acceptance("Composer Actions", function (needs) {
assert assert
.dom(".action-title .topic-link") .dom(".action-title .topic-link")
.hasText("Internationalization / localization"); .hasText("Internationalization / localization");
assert.strictEqual( assert
query(".action-title .topic-link").getAttribute("href"), .dom(".action-title .topic-link")
"/t/internationalization-localization/280" .hasAttribute("href", "/t/internationalization-localization/280");
);
assert.strictEqual( assert.strictEqual(
query(".d-editor-input").value, query(".d-editor-input").value,
"test replying to topic when initially replied to post" "test replying to topic when initially replied to post"

View File

@ -935,11 +935,13 @@ acceptance("Composer", function (needs) {
await click("#post_1 .d-icon-pencil"); await click("#post_1 .d-icon-pencil");
await fillIn(".d-editor-input", ""); await fillIn(".d-editor-input", "");
assert.strictEqual( assert
query(".d-editor-container textarea").getAttribute("placeholder"), .dom(".d-editor-container textarea")
I18n.t("composer.reply_placeholder"), .hasAttribute(
"it should not block because of missing category" "placeholder",
); I18n.t("composer.reply_placeholder"),
"it should not block because of missing category"
);
}); });
test("reply button has envelope icon when replying to private message", async function (assert) { test("reply button has envelope icon when replying to private message", async function (assert) {

View File

@ -125,13 +125,9 @@ acceptance("EmojiPicker", function (needs) {
"it has multiple recent emojis" "it has multiple recent emojis"
); );
assert.strictEqual( assert
/grinning/.test( .dom(".section.recent .section-group img.emoji")
query(".section.recent .section-group img.emoji").getAttribute("src") .hasAttribute("src", /grinning/, "puts the last used emoji in first");
),
true,
"it puts the last used emoji in first"
);
}); });
test("updates the recent list when selecting from it (after you close re-open it or select other emoji)", async function (assert) { test("updates the recent list when selecting from it (after you close re-open it or select other emoji)", async function (assert) {

View File

@ -4,7 +4,6 @@ import {
acceptance, acceptance,
count, count,
exists, exists,
query,
queryAll, queryAll,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -26,11 +25,13 @@ acceptance("Group Members - Anonymous", function () {
.dom(".group-member-dropdown") .dom(".group-member-dropdown")
.doesNotExist("it does not allow anon user to manage group members"); .doesNotExist("it does not allow anon user to manage group members");
assert.strictEqual( assert
query(".group-username-filter").getAttribute("placeholder"), .dom(".group-username-filter")
I18n.t("groups.members.filter_placeholder"), .hasAttribute(
"it should display the right filter placeholder" "placeholder",
); I18n.t("groups.members.filter_placeholder"),
"it should display the right filter placeholder"
);
}); });
}); });
@ -63,11 +64,13 @@ acceptance("Group Members", function (needs) {
.dom(".group-member-dropdown") .dom(".group-member-dropdown")
.exists("it allows admin user to manage group members"); .exists("it allows admin user to manage group members");
assert.strictEqual( assert
query(".group-username-filter").getAttribute("placeholder"), .dom(".group-username-filter")
I18n.t("groups.members.filter_placeholder_admin"), .hasAttribute(
"it should display the right filter placeholder" "placeholder",
); I18n.t("groups.members.filter_placeholder_admin"),
"it should display the right filter placeholder"
);
}); });
test("Shows bulk actions as an admin user", async function (assert) { test("Shows bulk actions as an admin user", async function (assert) {

View File

@ -4,11 +4,8 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Meta Tag Updater", function (needs) { acceptance("Meta Tag Updater", function (needs) {
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
server.get("/about", () => { server.get("/about", () => helper.response({}));
return helper.response({});
});
}); });
needs.site({});
test("updates OG title and URL", async function (assert) { test("updates OG title and URL", async function (assert) {
await visit("/"); await visit("/");
@ -17,40 +14,20 @@ acceptance("Meta Tag Updater", function (needs) {
); );
await click("a[href='/about']"); await click("a[href='/about']");
assert.strictEqual( assert
document .dom("meta[property='og:title']", document)
.querySelector("meta[property='og:title']") .hasAttribute("content", document.title, "updates OG title");
.getAttribute("content"), assert
document.title, .dom("meta[property='og:url']", document)
"it should update OG title" .hasAttribute("content", /\/about$/, "updates OG URL");
); assert
assert.ok( .dom("meta[name='twitter:title']", document)
document .hasAttribute("content", document.title, "updates Twitter title");
.querySelector("meta[property='og:url']") assert
.getAttribute("content") .dom("meta[name='twitter:url']", document)
.endsWith("/about"), .hasAttribute("content", /\/about$/, "updates Twitter URL");
"it should update OG URL" assert
); .dom("link[rel='canonical']", document)
assert.strictEqual( .hasAttribute("href", /\/about$/, "updates the canonical URL");
document
.querySelector("meta[name='twitter:title']")
.getAttribute("content"),
document.title,
"it should update Twitter title"
);
assert.ok(
document
.querySelector("meta[name='twitter:url']")
.getAttribute("content")
.endsWith("/about"),
"it should update Twitter URL"
);
assert.ok(
document
.querySelector("link[rel='canonical']")
.getAttribute("href")
.endsWith("/about"),
"it should update the canonical URL"
);
}); });
}); });

View File

@ -1,10 +1,6 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
acceptance,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Discovery - Mobile", function (needs) { acceptance("Topic Discovery - Mobile", function (needs) {
needs.mobileView(); needs.mobileView();
@ -13,13 +9,13 @@ acceptance("Topic Discovery - Mobile", function (needs) {
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.strictEqual( assert
query("a[data-user-card=codinghorror] img.avatar").getAttribute( .dom("a[data-user-card=codinghorror] img.avatar")
"loading" .hasAttribute(
), "loading",
"lazy", "lazy",
"it adds loading=`lazy` to topic list avatars" "it adds loading=`lazy` to topic list avatars"
); );
await visit("/categories"); await visit("/categories");
assert.ok(exists(".category"), "has a list of categories"); assert.ok(exists(".category"), "has a list of categories");

View File

@ -1,115 +1,95 @@
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
acceptance("Post controls", function () { acceptance("Post controls", function () {
test("accessibility of the likes list below the post", async function (assert) { test("accessibility of the likes list below the post", async function (assert) {
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
const showLikesButton = query("#post_2 button.like-count"); assert
assert.equal( .dom("#post_2 button.like-count")
showLikesButton.getAttribute("aria-pressed"), .hasAria("pressed", "false", "show likes button isn't pressed");
"false", assert
"show likes button isn't pressed" .dom("#post_2 button.like-count")
); .hasAria(
assert.equal( "label",
showLikesButton.getAttribute("aria-label"), I18n.t("post.sr_post_like_count_button", { count: 4 }),
I18n.t("post.sr_post_like_count_button", { count: 4 }), "show likes button has aria-label"
"show likes button has aria-label"
);
await click(showLikesButton);
assert.equal(
showLikesButton.getAttribute("aria-pressed"),
"true",
"show likes button is now pressed"
);
const likesContainer = query("#post_2 .small-user-list.who-liked");
assert.equal(
likesContainer.getAttribute("role"),
"list",
"likes container has list role"
);
assert.equal(
likesContainer.getAttribute("aria-label"),
I18n.t("post.actions.people.sr_post_likers_list_description"),
"likes container has aria-label"
);
assert.equal(
likesContainer
.querySelector(".list-description")
.getAttribute("aria-hidden"),
"true",
"list description is aria-hidden"
);
const likesAvatars = likesContainer.querySelectorAll("a.trigger-user-card");
assert.ok(likesAvatars.length > 0, "avatars are rendered");
likesAvatars.forEach((avatar) => {
assert.equal(
avatar.getAttribute("aria-hidden"),
"false",
"avatars are not aria-hidden"
); );
assert.equal(
avatar.getAttribute("role"), await click("#post_2 button.like-count");
"listitem", assert
"avatars have listitem role" .dom("#post_2 button.like-count")
.hasAria("pressed", "true", "show likes button is now pressed");
assert
.dom("#post_2 .small-user-list.who-liked")
.hasAttribute("role", "list", "likes container has list role");
assert
.dom("#post_2 .small-user-list.who-liked")
.hasAria(
"label",
I18n.t("post.actions.people.sr_post_likers_list_description"),
"likes container has aria-label"
); );
}); assert
.dom("#post_2 .small-user-list.who-liked .list-description")
.hasAria("hidden", "true", "list description is aria-hidden");
assert
.dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
.exists("avatars are rendered");
assert
.dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
.hasAria("hidden", "false", "avatars are not aria-hidden");
assert
.dom("#post_2 .small-user-list.who-liked a.trigger-user-card")
.hasAttribute("role", "listitem", "avatars have listitem role");
}); });
test("accessibility of the embedded replies below the post", async function (assert) { test("accessibility of the embedded replies below the post", async function (assert) {
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
const showRepliesButton = query("#post_1 button.show-replies"); assert
assert.equal( .dom("#post_1 button.show-replies")
showRepliesButton.getAttribute("aria-pressed"), .hasAria("pressed", "false", "show replies button isn't pressed");
"false", assert
"show replies button isn't pressed" .dom("#post_1 button.show-replies")
); .hasAria(
assert.equal( "label",
showRepliesButton.getAttribute("aria-label"), I18n.t("post.sr_expand_replies", { count: 1 }),
I18n.t("post.sr_expand_replies", { count: 1 }), "show replies button has aria-label"
"show replies button has aria-label"
);
await click(showRepliesButton);
assert.equal(
showRepliesButton.getAttribute("aria-pressed"),
"true",
"show replies button is now pressed"
);
const replies = Array.from(queryAll("#post_1 .embedded-posts .reply"));
assert.equal(replies.length, 1, "replies are rendered");
replies.forEach((reply) => {
assert.equal(
reply.getAttribute("role"),
"region",
"replies have region role"
); );
assert.equal(
reply.getAttribute("aria-label"), await click("#post_1 button.show-replies");
I18n.t("post.sr_embedded_reply_description", { assert
post_number: 1, .dom("#post_1 button.show-replies")
username: "somebody", .hasAria("pressed", "true", "show replies button is now pressed");
}),
"replies have aria-label" // const replies = Array.from(queryAll("#post_1 .embedded-posts .reply"));
); assert
}); .dom("#post_1 .embedded-posts .reply")
assert.equal( .exists({ count: 1 }, "replies are rendered");
query("#post_1 .embedded-posts .btn.collapse-up").getAttribute(
"aria-label" assert
), .dom("#post_1 .embedded-posts .reply")
I18n.t("post.sr_collapse_replies"), .hasAttribute("role", "region", "replies have region role");
"collapse button has aria-label" assert.dom("#post_1 .embedded-posts .reply").hasAria(
"label",
I18n.t("post.sr_embedded_reply_description", {
post_number: 1,
username: "somebody",
}),
"replies have aria-label"
); );
assert
.dom("#post_1 .embedded-posts .btn.collapse-up")
.hasAria(
"label",
I18n.t("post.sr_collapse_replies"),
"collapse button has aria-label"
);
}); });
}); });

View File

@ -536,18 +536,14 @@ acceptance("Search - Authenticated", function (needs) {
await fillIn("#search-term", "Development"); await fillIn("#search-term", "Development");
await triggerKeyEvent(document.activeElement, "keyup", "Enter"); await triggerKeyEvent(document.activeElement, "keyup", "Enter");
const firstSearchResult = assert
".search-menu .results li:nth-of-type(1) a.search-link"; .dom(".search-menu .results li a.search-link")
const firstTopicResultUrl = "/t/development-mode-super-slow/2179"; .hasAttribute("href", "/t/development-mode-super-slow/2179");
assert.strictEqual(
query(firstSearchResult).getAttribute("href"),
firstTopicResultUrl
);
await click(firstSearchResult); await click(".search-menu .results li a.search-link");
assert.strictEqual( assert.strictEqual(
currentURL(), currentURL(),
firstTopicResultUrl, "/t/development-mode-super-slow/2179",
"redirects to clicked search result url" "redirects to clicked search result url"
); );
}); });
@ -579,29 +575,27 @@ acceptance("Search - Authenticated", function (needs) {
.exists("has topic results"); .exists("has topic results");
await triggerKeyEvent("#search-term", "keyup", "ArrowDown"); await triggerKeyEvent("#search-term", "keyup", "ArrowDown");
assert.strictEqual( assert
document.activeElement.getAttribute("href"), .dom(`${container} li:first-child a`)
query(`${container} li:first-child a`).getAttribute("href"), .isFocused("arrow down selects first element");
"arrow down selects first element"
);
await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
assert.strictEqual( assert
document.activeElement.getAttribute("href"), .dom(`${container} li:nth-child(2) a`)
query(`${container} li:nth-child(2) a`).getAttribute("href"), .isFocused("arrow down selects next element");
"arrow down selects next element"
);
// navigate to the `more link` // navigate to the `more link`
await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
assert.strictEqual( assert
document.activeElement.getAttribute("href"), .dom(document.activeElement)
"/search?q=dev", .hasAttribute(
"arrow down sets focus to more results link" "href",
); "/search?q=dev",
"arrow down sets focus to more results link"
);
await triggerKeyEvent("#search-term", "keydown", "Escape"); await triggerKeyEvent("#search-term", "keydown", "Escape");
assert.strictEqual( assert.strictEqual(
@ -673,17 +667,18 @@ acceptance("Search - Authenticated", function (needs) {
await triggerKeyEvent(document.activeElement, "keyup", "Enter"); await triggerKeyEvent(document.activeElement, "keyup", "Enter");
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown");
const firstTopicResultUrl = "/t/development-mode-super-slow/2179"; assert
assert.strictEqual( .dom(document.activeElement)
document.activeElement.getAttribute("href"), .hasAttribute(
firstTopicResultUrl, "href",
"first search result is highlighted" "/t/development-mode-super-slow/2179",
); "first search result is highlighted"
);
await triggerKeyEvent(document.activeElement, "keydown", "Enter"); await triggerKeyEvent(document.activeElement, "keydown", "Enter");
assert.strictEqual( assert.strictEqual(
currentURL(), currentURL(),
firstTopicResultUrl, "/t/development-mode-super-slow/2179",
"redirects to selected search result url" "redirects to selected search result url"
); );
}); });

View File

@ -212,18 +212,25 @@ acceptance("Tags listed by group", function (needs) {
["focus", "Escort"], ["focus", "Escort"],
"shows the tags in default sort (by count)" "shows the tags in default sort (by count)"
); );
assert.deepEqual(
[...queryAll(".tag-list:nth-of-type(1) .discourse-tag")].map((el) => assert
el.getAttribute("href") .dom(".tag-list .tag-box:nth-of-type(1) .discourse-tag")
), .hasAttribute("href", "/tag/focus");
["/tag/focus", "/tag/escort"], assert
"always uses lowercase URLs for mixed case tags" .dom(".tag-list .tag-box:nth-of-type(2) .discourse-tag")
); .hasAttribute(
assert.strictEqual( "href",
query(`a[data-tag-name="private"]`).getAttribute("href"), "/tag/escort",
"/u/eviltrout/messages/tags/private", "uses a lowercase URL for a mixed case tag"
"links to private messages" );
);
assert
.dom(`a[data-tag-name="private"]`)
.hasAttribute(
"href",
"/u/eviltrout/messages/tags/private",
"links to private messages"
);
}); });
test("new topic button is not available for staff-only tags", async function (assert) { test("new topic button is not available for staff-only tags", async function (assert) {

View File

@ -33,17 +33,21 @@ acceptance("Topic Discovery", function (needs) {
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.strictEqual( assert
query("a[data-user-card=eviltrout] img.avatar").getAttribute("title"), .dom("a[data-user-card=eviltrout] img.avatar")
"eviltrout - Most Posts", .hasAttribute(
"it shows user's full name in avatar title" "title",
); "eviltrout - Most Posts",
"it shows user's full name in avatar title"
);
assert.strictEqual( assert
query("a[data-user-card=eviltrout] img.avatar").getAttribute("loading"), .dom("a[data-user-card=eviltrout] img.avatar")
"lazy", .hasAttribute(
"it adds loading=`lazy` to topic list avatars" "loading",
); "lazy",
"it adds loading=`lazy` to topic list avatars"
);
await visit("/c/bug"); await visit("/c/bug");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");

View File

@ -2,7 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
import { clearCustomLastUnreadUrlCallbacks } from "discourse/models/topic"; import { clearCustomLastUnreadUrlCallbacks } from "discourse/models/topic";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic list plugin API", function () { acceptance("Topic list plugin API", function () {
function customLastUnreadUrl(context) { function customLastUnreadUrl(context) {
@ -16,12 +16,12 @@ acceptance("Topic list plugin API", function () {
}); });
await visit("/"); await visit("/");
assert.strictEqual( assert
query( .dom(".topic-list .topic-list-item:first-child a.raw-topic-link")
".topic-list .topic-list-item:first-child a.raw-topic-link" .hasAttribute(
).getAttribute("href"), "href",
"/t/error-after-upgrade-to-0-9-7-9/11557/1?overridden" "/t/error-after-upgrade-to-0-9-7-9/11557/1?overridden"
); );
} finally { } finally {
clearCustomLastUnreadUrlCallbacks(); clearCustomLastUnreadUrlCallbacks();
} }

View File

@ -282,7 +282,9 @@ acceptance("Topic featured links", function (needs) {
const link = query(".title-wrapper .topic-featured-link"); const link = query(".title-wrapper .topic-featured-link");
assert.strictEqual(link.innerText, "example.com"); assert.strictEqual(link.innerText, "example.com");
assert.strictEqual(link.getAttribute("rel"), "ugc"); assert
.dom(".title-wrapper .topic-featured-link")
.hasAttribute("rel", "ugc");
}); });
test("remove featured link", async function (assert) { test("remove featured link", async function (assert) {

View File

@ -62,36 +62,35 @@ acceptance("User menu", function (needs) {
test("notifications panel has a11y attributes", async function (assert) { test("notifications panel has a11y attributes", async function (assert) {
await visit("/"); await visit("/");
await click(".d-header-icons .current-user button"); await click(".d-header-icons .current-user button");
const panel = query("#quick-access-all-notifications");
assert.strictEqual(panel.getAttribute("tabindex"), "-1"); assert
assert.strictEqual( .dom("#quick-access-all-notifications")
panel.querySelector("ul").getAttribute("aria-labelledby"), .hasAttribute("tabindex", "-1");
"user-menu-button-all-notifications" assert
); .dom("#quick-access-all-notifications ul")
.hasAria("labelledby", "user-menu-button-all-notifications");
}); });
test("replies notifications panel has a11y attributes", async function (assert) { test("replies notifications panel has a11y attributes", async function (assert) {
await visit("/"); await visit("/");
await click(".d-header-icons .current-user button"); await click(".d-header-icons .current-user button");
await click("#user-menu-button-replies"); await click("#user-menu-button-replies");
const panel = query("#quick-access-replies");
assert.strictEqual(panel.getAttribute("tabindex"), "-1"); assert.dom("#quick-access-replies").hasAttribute("tabindex", "-1");
assert.strictEqual( assert
panel.querySelector("ul").getAttribute("aria-labelledby"), .dom("#quick-access-replies ul")
"user-menu-button-replies" .hasAria("labelledby", "user-menu-button-replies");
);
}); });
test("profile panel has a11y attributes", async function (assert) { test("profile panel has a11y attributes", async function (assert) {
await visit("/"); await visit("/");
await click(".d-header-icons .current-user button"); await click(".d-header-icons .current-user button");
await click("#user-menu-button-profile"); await click("#user-menu-button-profile");
const panel = query("#quick-access-profile");
assert.strictEqual(panel.getAttribute("tabindex"), "-1"); assert.dom("#quick-access-profile").hasAttribute("tabindex", "-1");
assert.strictEqual( assert
panel.querySelector("ul").getAttribute("aria-labelledby"), .dom("#quick-access-profile ul")
"user-menu-button-profile" .hasAria("labelledby", "user-menu-button-profile");
);
}); });
test("clicking on an unread notification", async function (assert) { test("clicking on an unread notification", async function (assert) {

View File

@ -3,7 +3,7 @@ import { click, render, triggerKeyEvent } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { exists, query } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated"; import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
@ -15,11 +15,7 @@ module("Integration | Component | d-button", function (hooks) {
assert.ok(exists("button.btn.btn-icon.no-text"), "it has all the classes"); assert.ok(exists("button.btn.btn-icon.no-text"), "it has all the classes");
assert.ok(exists("button .d-icon.d-icon-plus"), "it has the icon"); assert.ok(exists("button .d-icon.d-icon-plus"), "it has the icon");
assert.strictEqual( assert.dom("button").hasAttribute("tabindex", "3", "it has the tabindex");
query("button").getAttribute("tabindex"),
"3",
"it has the tabindex"
);
}); });
test("icon and text button", async function (assert) { test("icon and text button", async function (assert) {
@ -117,17 +113,14 @@ module("Integration | Component | d-button", function (hooks) {
this.set("ariaLabel", "test.fooAriaLabel"); this.set("ariaLabel", "test.fooAriaLabel");
assert.strictEqual( assert.dom("button").hasAria("label", I18n.t("test.fooAriaLabel"));
query("button").getAttribute("aria-label"),
I18n.t("test.fooAriaLabel")
);
this.setProperties({ this.setProperties({
ariaLabel: null, ariaLabel: null,
translatedAriaLabel: "bar", translatedAriaLabel: "bar",
}); });
assert.dom("button").hasAttribute("aria-label", "bar"); assert.dom("button").hasAria("label", "bar");
}); });
test("title", async function (assert) { test("title", async function (assert) {
@ -138,10 +131,7 @@ module("Integration | Component | d-button", function (hooks) {
); );
this.set("title", "test.fooTitle"); this.set("title", "test.fooTitle");
assert.strictEqual( assert.dom("button").hasAttribute("title", I18n.t("test.fooTitle"));
query("button").getAttribute("title"),
I18n.t("test.fooTitle")
);
this.setProperties({ this.setProperties({
title: null, title: null,
@ -192,10 +182,7 @@ module("Integration | Component | d-button", function (hooks) {
await render(hbs`<DButton @ariaControls={{this.ariaControls}} />`); await render(hbs`<DButton @ariaControls={{this.ariaControls}} />`);
this.set("ariaControls", "foo-bar"); this.set("ariaControls", "foo-bar");
assert.strictEqual( assert.dom("button").hasAria("controls", "foo-bar");
query("button").getAttribute("aria-controls"),
"foo-bar"
);
}); });
test("onKeyDown callback", async function (assert) { test("onKeyDown callback", async function (assert) {

View File

@ -621,29 +621,17 @@ third line`
assert.strictEqual(textarea.selectionEnd, 18); assert.strictEqual(textarea.selectionEnd, 18);
}); });
test("clicking the toggle-direction changes dir from ltr to rtl", async function (assert) { test("clicking the toggle-direction changes dir from ltr to rtl and back", async function (assert) {
this.siteSettings.support_mixed_text_direction = true; this.siteSettings.support_mixed_text_direction = true;
this.siteSettings.default_locale = "en"; this.siteSettings.default_locale = "en";
await render(hbs`<DEditor @value={{this.value}} />`); await render(hbs`<DEditor @value={{this.value}} />`);
await click("button.toggle-direction"); await click("button.toggle-direction");
assert.strictEqual( assert.dom("textarea.d-editor-input").hasAttribute("dir", "rtl");
query("textarea.d-editor-input").getAttribute("dir"),
"rtl"
);
});
test("clicking the toggle-direction changes dir from ltr to rtl", async function (assert) {
this.siteSettings.support_mixed_text_direction = true;
this.siteSettings.default_locale = "en";
await render(hbs`<DEditor @value={{this.value}} />`);
const textarea = query("textarea.d-editor-input");
textarea.setAttribute("dir", "ltr");
await click("button.toggle-direction"); await click("button.toggle-direction");
assert.strictEqual(textarea.getAttribute("dir"), "rtl"); assert.dom("textarea.d-editor-input").hasAttribute("dir", "ltr");
}); });
test("toolbar event supports replaceText", async function (assert) { test("toolbar event supports replaceText", async function (assert) {
@ -757,12 +745,10 @@ third line`
await render(hbs`<DEditor />`); await render(hbs`<DEditor />`);
const buttons = queryAll(".d-editor-button-bar .btn"); const buttons = queryAll(".d-editor-button-bar .btn");
assert.strictEqual( assert
buttons[0].getAttribute("tabindex"), .dom(buttons[0])
"0", .hasAttribute("tabindex", "0", "it makes the first button focusable");
"it makes the first button focusable" assert.dom(buttons[1]).hasAttribute("tabindex", "-1");
);
assert.strictEqual(buttons[1].getAttribute("tabindex"), "-1");
}); });
testCase("replace-text event by default", async function (assert) { testCase("replace-text event by default", async function (assert) {

View File

@ -5,7 +5,6 @@ import { setupLightboxes } from "discourse/lib/lightbox";
import { SELECTORS } from "discourse/lib/lightbox/constants"; import { SELECTORS } from "discourse/lib/lightbox/constants";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { generateLightboxMarkup } from "discourse/tests/helpers/lightbox-helpers"; import { generateLightboxMarkup } from "discourse/tests/helpers/lightbox-helpers";
import { query } from "discourse/tests/helpers/qunit-helpers";
import domFromString from "discourse-common/lib/dom-from-string"; import domFromString from "discourse-common/lib/dom-from-string";
module("Integration | Component | d-lightbox", function (hooks) { module("Integration | Component | d-lightbox", function (hooks) {
@ -56,12 +55,13 @@ module("Integration | Component | d-lightbox", function (hooks) {
// the content has an aria-labelledby attribute // the content has an aria-labelledby attribute
assert.dom(SELECTORS.LIGHTBOX_CONTENT).hasAttribute("aria-labelledby"); assert.dom(SELECTORS.LIGHTBOX_CONTENT).hasAttribute("aria-labelledby");
assert.true( assert
query(SELECTORS.LIGHTBOX_CONTENT) .dom(SELECTORS.LIGHTBOX_CONTENT)
.getAttribute("style") .hasAttribute(
.match(/--d-lightbox/g).length > 0, "style",
"the content has the correct css variables added" /--d-lightbox/,
); "the content has the correct css variables added"
);
// it has focus traps for keyboard navigation // it has focus traps for keyboard navigation
assert.dom(SELECTORS.FOCUS_TRAP).exists(); assert.dom(SELECTORS.FOCUS_TRAP).exists();

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { exists, query } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
module("Integration | Component | d-toggle-switch", function (hooks) { module("Integration | Component | d-toggle-switch", function (hooks) {
@ -14,10 +14,7 @@ module("Integration | Component | d-toggle-switch", function (hooks) {
await render(hbs`<DToggleSwitch @state={{this.state}}/>`); await render(hbs`<DToggleSwitch @state={{this.state}}/>`);
assert.ok(exists(".d-toggle-switch"), "it renders a toggle switch"); assert.ok(exists(".d-toggle-switch"), "it renders a toggle switch");
assert.strictEqual( assert.dom(".d-toggle-switch__checkbox").hasAria("checked", "false");
query(".d-toggle-switch__checkbox").getAttribute("aria-checked"),
"false"
);
}); });
test("it renders a toggle button in a enabled state", async function (assert) { test("it renders a toggle button in a enabled state", async function (assert) {
@ -26,10 +23,7 @@ module("Integration | Component | d-toggle-switch", function (hooks) {
await render(hbs`<DToggleSwitch @state={{this.state}}/>`); await render(hbs`<DToggleSwitch @state={{this.state}}/>`);
assert.ok(exists(".d-toggle-switch"), "it renders a toggle switch"); assert.ok(exists(".d-toggle-switch"), "it renders a toggle switch");
assert.strictEqual( assert.dom(".d-toggle-switch__checkbox").hasAria("checked", "true");
query(".d-toggle-switch__checkbox").getAttribute("aria-checked"),
"true"
);
}); });
test("it renders a checkmark icon when enabled", async function (assert) { test("it renders a checkmark icon when enabled", async function (assert) {

View File

@ -2,7 +2,6 @@ import { click, render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Component | emoji-picker", function (hooks) { module("Integration | Component | emoji-picker", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
@ -18,10 +17,9 @@ module("Integration | Component | emoji-picker", function (hooks) {
`); `);
await click(".emoji-picker-anchor"); await click(".emoji-picker-anchor");
assert.strictEqual( assert
query(".emoji-picker.opened").getAttribute("data-popper-placement"), .dom(".emoji-picker.opened")
"bottom" .hasAttribute("data-popper-placement", "bottom");
);
}); });
test("when placement == right, places the picker on the right", async function (assert) { test("when placement == right, places the picker on the right", async function (assert) {
@ -35,9 +33,8 @@ module("Integration | Component | emoji-picker", function (hooks) {
`); `);
await click(".emoji-picker-anchor"); await click(".emoji-picker-anchor");
assert.strictEqual( assert
query(".emoji-picker.opened").getAttribute("data-popper-placement"), .dom(".emoji-picker.opened")
"right" .hasAttribute("data-popper-placement", "right");
);
}); });
}); });

View File

@ -1,7 +1,6 @@
import { getOwner } from "@ember/owner"; import { getOwner } from "@ember/owner";
import { import {
click, click,
find,
render, render,
triggerEvent, triggerEvent,
triggerKeyEvent, triggerKeyEvent,
@ -220,17 +219,15 @@ module("Integration | Component | FloatKit | d-menu", function (hooks) {
); );
await open(); await open();
assert.ok( assert.dom(".fk-d-menu").hasStyle({ maxWidth: "20px" });
find(".fk-d-menu").getAttribute("style").includes("max-width: 20px;")
);
}); });
test("applies position", async function (assert) { test("applies position", async function (assert) {
await render(hbs`<DMenu @inline={{true}} @label="label" />`); await render(hbs`<DMenu @inline={{true}} @label="label" />`);
await open(); await open();
assert.dom(".fk-d-menu").hasAttribute("style", /left: /); assert.dom(".fk-d-menu").hasAttribute("style", /top: [\d.]+?px/);
assert.ok(find(".fk-d-menu").getAttribute("style").includes("top: ")); assert.dom(".fk-d-menu").hasAttribute("style", /left: [\d.]+?px/);
}); });
test("content close argument", async function (assert) { test("content close argument", async function (assert) {

View File

@ -78,11 +78,13 @@ module(
.dom(".selected-name", this.subject.header().el()) .dom(".selected-name", this.subject.header().el())
.doesNotExist("hides the text of the selected item"); .doesNotExist("hides the text of the selected item");
assert.strictEqual( assert
this.subject.header().el().getAttribute("title"), .dom(this.subject.header().el())
"[en.test_none]", .hasAttribute(
"it adds a title attribute to the button" "title",
); "[en.test_none]",
"it adds a title attribute to the button"
);
}); });
test("options.showFullTitle=true", async function (assert) { test("options.showFullTitle=true", async function (assert) {

View File

@ -425,16 +425,15 @@ module("Integration | Component | select-kit/single-select", function (hooks) {
hbs`<SingleSelect @value={{this.value}} @content={{this.content}} />` hbs`<SingleSelect @value={{this.value}} @content={{this.content}} />`
); );
assert.strictEqual( assert
this.subject.header().el().getAttribute("name"), .dom(this.subject.header().el())
I18n.t("select_kit.select_to_filter") .hasAttribute("name", I18n.t("select_kit.select_to_filter"));
);
await this.subject.expand(); await this.subject.expand();
await this.subject.selectRowByValue(1); await this.subject.selectRowByValue(1);
assert.strictEqual( assert.dom(this.subject.header().el()).hasAttribute(
this.subject.header().el().getAttribute("name"), "name",
I18n.t("select_kit.filter_by", { I18n.t("select_kit.filter_by", {
name: this.content.firstObject.name, name: this.content.firstObject.name,
}) })

View File

@ -3,7 +3,7 @@ import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { resetFlair } from "discourse/lib/avatar-flair"; import { resetFlair } from "discourse/lib/avatar-flair";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { exists, query } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
function setupSiteGroups(that) { function setupSiteGroups(that) {
that.site.groups = [ that.site.groups = [
@ -62,11 +62,10 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
assert.ok(exists(".avatar-flair"), "it has the tag"); assert.ok(exists(".avatar-flair"), "it has the tag");
assert.ok(exists("svg.d-icon-bars"), "it has the svg icon"); assert.ok(exists("svg.d-icon-bars"), "it has the svg icon");
assert.strictEqual( assert.dom(".avatar-flair").hasStyle({
query(".avatar-flair").getAttribute("style"), backgroundColor: "rgb(204, 0, 10)",
"background-color: #CC000A; color: #FFFFFA; ", color: "rgb(255, 255, 250)",
"it has styles" });
);
}); });
test("avatar flair for moderator user with fallback to staff", async function (assert) { test("avatar flair for moderator user with fallback to staff", async function (assert) {
@ -82,11 +81,10 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
assert.ok(exists(".avatar-flair"), "it has the tag"); assert.ok(exists(".avatar-flair"), "it has the tag");
assert.ok(exists("svg.d-icon-bars"), "it has the svg icon"); assert.ok(exists("svg.d-icon-bars"), "it has the svg icon");
assert.strictEqual( assert.dom(".avatar-flair").hasStyle({
query(".avatar-flair").getAttribute("style"), backgroundColor: "rgb(204, 0, 5)",
"background-color: #CC0005; color: #FFFFF5; ", color: "rgb(255, 255, 245)",
"it has styles" });
);
}); });
test("avatar flair for trust level", async function (assert) { test("avatar flair for trust level", async function (assert) {
@ -102,11 +100,10 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
assert.ok(exists(".avatar-flair"), "it has the tag"); assert.ok(exists(".avatar-flair"), "it has the tag");
assert.ok(exists("svg.d-icon-dice-two"), "it has the svg icon"); assert.ok(exists("svg.d-icon-dice-two"), "it has the svg icon");
assert.strictEqual( assert.dom(".avatar-flair").hasStyle({
query(".avatar-flair").getAttribute("style"), backgroundColor: "rgb(204, 0, 2)",
"background-color: #CC0002; color: #FFFFF2; ", color: "rgb(255, 255, 242)",
"it has styles" });
);
}); });
test("avatar flair for trust level when set to none", async function (assert) { test("avatar flair for trust level when set to none", async function (assert) {
@ -136,11 +133,10 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
assert.ok(exists(".avatar-flair"), "it has the tag"); assert.ok(exists(".avatar-flair"), "it has the tag");
assert.ok(exists("svg.d-icon-dice-two"), "it has the svg icon"); assert.ok(exists("svg.d-icon-dice-two"), "it has the svg icon");
assert.strictEqual( assert.dom(".avatar-flair").hasStyle({
query(".avatar-flair").getAttribute("style"), backgroundColor: "rgb(204, 0, 2)",
"background-color: #CC0002; color: #FFFFF2; ", color: "rgb(255, 255, 242)",
"it has styles" });
);
}); });
test("avatar flair for login-required site, before login", async function (assert) { test("avatar flair for login-required site, before login", async function (assert) {
@ -176,11 +172,10 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
assert.ok(exists(".avatar-flair"), "it has the tag"); assert.ok(exists(".avatar-flair"), "it has the tag");
assert.ok(exists("svg.d-icon-xmark"), "it has the svg icon"); assert.ok(exists("svg.d-icon-xmark"), "it has the svg icon");
assert.strictEqual( assert.dom(".avatar-flair").hasStyle({
query(".avatar-flair").getAttribute("style"), backgroundColor: "rgb(18, 52, 86)",
"background-color: #123456; color: #B0B0B0; ", color: "rgb(176, 176, 176)",
"it has styles" });
);
}); });
test("user-avatar-flair for user with no flairs", async function (assert) { test("user-avatar-flair for user with no flairs", async function (assert) {

View File

@ -23,16 +23,18 @@ module("Integration | Component | user-menu", function (hooks) {
test("active tab has a11y attributes that indicate it's active", async function (assert) { test("active tab has a11y attributes that indicate it's active", async function (assert) {
await render(template); await render(template);
const activeTab = query(".top-tabs.tabs-list .btn.active"); assert.dom(".top-tabs.tabs-list .btn.active").hasAttribute("tabindex", "0");
assert.strictEqual(activeTab.getAttribute("tabindex"), "0"); assert.dom(".top-tabs.tabs-list .btn.active").hasAria("selected", "true");
assert.strictEqual(activeTab.getAttribute("aria-selected"), "true");
}); });
test("inactive tab has a11y attributes that indicate it's inactive", async function (assert) { test("inactive tab has a11y attributes that indicate it's inactive", async function (assert) {
await render(template); await render(template);
const inactiveTab = query(".top-tabs.tabs-list .btn:not(.active)"); assert
assert.strictEqual(inactiveTab.getAttribute("tabindex"), "-1"); .dom(".top-tabs.tabs-list .btn:not(.active)")
assert.strictEqual(inactiveTab.getAttribute("aria-selected"), "false"); .hasAttribute("tabindex", "-1");
assert
.dom(".top-tabs.tabs-list .btn:not(.active)")
.hasAria("selected", "false");
}); });
test("the menu has a group of tabs at the top", async function (assert) { test("the menu has a group of tabs at the top", async function (assert) {
@ -44,10 +46,7 @@ module("Integration | Component | user-menu", function (hooks) {
(tab, index) => { (tab, index) => {
assert.strictEqual(tabs[index].id, `user-menu-button-${tab}`); assert.strictEqual(tabs[index].id, `user-menu-button-${tab}`);
assert.strictEqual(tabs[index].dataset.tabNumber, index.toString()); assert.strictEqual(tabs[index].dataset.tabNumber, index.toString());
assert.strictEqual( assert.dom(tabs[index]).hasAria("controls", `quick-access-${tab}`);
tabs[index].getAttribute("aria-controls"),
`quick-access-${tab}`
);
} }
); );
}); });
@ -60,7 +59,7 @@ module("Integration | Component | user-menu", function (hooks) {
const profileTab = tabs[0]; const profileTab = tabs[0];
assert.strictEqual(profileTab.id, "user-menu-button-profile"); assert.strictEqual(profileTab.id, "user-menu-button-profile");
assert.strictEqual(profileTab.dataset.tabNumber, "6"); assert.strictEqual(profileTab.dataset.tabNumber, "6");
assert.strictEqual(profileTab.getAttribute("tabindex"), "-1"); assert.dom(profileTab).hasAttribute("tabindex", "-1");
}); });
test("likes tab is hidden if current user's like notifications frequency is 'never'", async function (assert) { test("likes tab is hidden if current user's like notifications frequency is 'never'", async function (assert) {

View File

@ -88,11 +88,13 @@ module(
I18n.t("user.dismiss"), I18n.t("user.dismiss"),
"dismiss button has a label" "dismiss button has a label"
); );
assert.strictEqual( assert
dismissButton.getAttribute("title"), .dom(".panel-body-bottom .btn.notifications-dismiss")
I18n.t("user.dismiss_notifications_tooltip"), .hasAttribute(
"dismiss button has title attribute" "title",
); I18n.t("user.dismiss_notifications_tooltip"),
"dismiss button has title attribute"
);
}); });
test("doesn't have a dismiss button if all notifications are read", async function (assert) { test("doesn't have a dismiss button if all notifications are read", async function (assert) {

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { exists, query } from "discourse/tests/helpers/qunit-helpers"; import { exists } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Component | Widget | avatar-flair", function (hooks) { module("Integration | Component | Widget | avatar-flair", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
@ -20,11 +20,10 @@ module("Integration | Component | Widget | avatar-flair", function (hooks) {
assert.ok(exists(".avatar-flair"), "it has the tag"); assert.ok(exists(".avatar-flair"), "it has the tag");
assert.ok(exists("svg.d-icon-bars"), "it has the svg icon"); assert.ok(exists("svg.d-icon-bars"), "it has the svg icon");
assert.strictEqual( assert.dom(".avatar-flair").hasStyle({
query(".avatar-flair").getAttribute("style"), backgroundColor: "rgb(204, 0, 0)",
"background-color: #CC0000; color: #FFFFFF; ", color: "rgb(255, 255, 255)",
"it has styles" });
);
}); });
test("avatar flair with an image", async function (assert) { test("avatar flair with an image", async function (assert) {

View File

@ -4,12 +4,7 @@ import { click, render, triggerEvent } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { import { count, exists, query } from "discourse/tests/helpers/qunit-helpers";
count,
exists,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
module("Integration | Component | Widget | post", function (hooks) { module("Integration | Component | Widget | post", function (hooks) {
@ -44,14 +39,8 @@ module("Integration | Component | Widget | post", function (hooks) {
hbs`<MountWidget @widget="post-contents" @args={{this.args}} />` hbs`<MountWidget @widget="post-contents" @args={{this.args}} />`
); );
assert.strictEqual( assert.dom("a[data-clicks='1']").hasAttribute("data-clicks", "1");
queryAll("a[data-clicks='1']")[0].getAttribute("data-clicks"), assert.dom("a[data-clicks='2']").hasAttribute("data-clicks", "2");
"1"
);
assert.strictEqual(
queryAll("a[data-clicks='2']")[0].getAttribute("data-clicks"),
"2"
);
}); });
test("post - onebox links", async function (assert) { test("post - onebox links", async function (assert) {
@ -78,16 +67,20 @@ module("Integration | Component | Widget | post", function (hooks) {
hbs`<MountWidget @widget="post-contents" @args={{this.args}} />` hbs`<MountWidget @widget="post-contents" @args={{this.args}} />`
); );
assert.strictEqual( assert
queryAll("a[data-clicks='1']")[0].getAttribute("data-clicks"), .dom("a[data-clicks='1']")
"1", .hasAttribute(
"First link has correct data attribute and content" "data-clicks",
); "1",
assert.strictEqual( "First link has correct data attribute and content"
queryAll("a[data-clicks='2']")[0].getAttribute("data-clicks"), );
"2", assert
"Second link has correct data attribute and content" .dom("a[data-clicks='2']")
); .hasAttribute(
"data-clicks",
"2",
"Second link has correct data attribute and content"
);
}); });
test("wiki", async function (assert) { test("wiki", async function (assert) {
@ -279,11 +272,13 @@ module("Integration | Component | Widget | post", function (hooks) {
assert.dom(".actions button.like").exists(); assert.dom(".actions button.like").exists();
assert.dom(".actions button.like-count").doesNotExist(); assert.dom(".actions button.like-count").doesNotExist();
assert.strictEqual( assert
query("button.like").getAttribute("title"), .dom("button.like")
I18n.t("post.controls.like"), .hasAttribute(
`shows the right button title for anonymous users` "title",
); I18n.t("post.controls.like"),
"shows the right button title for anonymous users"
);
await click(".actions button.like"); await click(".actions button.like");
assert.ok(this.loginShown); assert.ok(this.loginShown);
@ -354,11 +349,13 @@ module("Integration | Component | Widget | post", function (hooks) {
assert.strictEqual(count("button.create-flag"), 1, `button is displayed`); assert.strictEqual(count("button.create-flag"), 1, `button is displayed`);
assert.strictEqual(count("button.delete"), 1, `button is displayed`); assert.strictEqual(count("button.delete"), 1, `button is displayed`);
assert.strictEqual( assert
query("button.delete").getAttribute("title"), .dom("button.delete")
I18n.t("post.controls.delete_topic_disallowed"), .hasAttribute(
`shows the right button title for users without permissions` "title",
); I18n.t("post.controls.delete_topic_disallowed"),
"shows the right button title for users without permissions"
);
}); });
test("recover topic button", async function (assert) { test("recover topic button", async function (assert) {
@ -1002,10 +999,9 @@ module("Integration | Component | Widget | post", function (hooks) {
const link = query(".group-request a"); const link = query(".group-request a");
assert.strictEqual(link.innerText.trim(), I18n.t("groups.requests.handle")); assert.strictEqual(link.innerText.trim(), I18n.t("groups.requests.handle"));
assert.strictEqual( assert
link.getAttribute("href"), .dom(".group-request a")
"/g/testGroup/requests?filter=foo" .hasAttribute("href", "/g/testGroup/requests?filter=foo");
);
}); });
test("shows user status if enabled in site settings", async function (assert) { test("shows user status if enabled in site settings", async function (assert) {

View File

@ -27,10 +27,6 @@ function quoteHtml() {
`; `;
} }
function assertDirection(assert, elem, expected, message) {
assert.strictEqual(elem.getAttribute("dir"), expected, message);
}
module("Unit | Utility | text-direction", function (hooks) { module("Unit | Utility | text-direction", function (hooks) {
setupTest(hooks); setupTest(hooks);
@ -62,18 +58,20 @@ module("Unit | Utility | text-direction", function (hooks) {
const [englishTitle, arabicTitle] = Array.from( const [englishTitle, arabicTitle] = Array.from(
cooked.querySelectorAll(".title") cooked.querySelectorAll(".title")
); );
assertDirection( assert
assert, .dom(englishTitle)
englishTitle, .hasAttribute(
"ltr", "dir",
"quote title always matches site direction regardless of its content" "ltr",
); "quote title always matches site direction regardless of its content"
assertDirection( );
assert, assert
arabicTitle, .dom(arabicTitle)
"ltr", .hasAttribute(
"quote title always matches site direction regardless of its content" "dir",
); "ltr",
"quote title always matches site direction regardless of its content"
);
const [ const [
quotedRtl, quotedRtl,
@ -84,41 +82,39 @@ module("Unit | Utility | text-direction", function (hooks) {
notQuotedRtl, notQuotedRtl,
] = Array.from(cooked.querySelectorAll("p")); ] = Array.from(cooked.querySelectorAll("p"));
assertDirection( assert
assert, .dom(quotedRtl)
quotedRtl, .hasAttribute("dir", "auto", "RTL paragraphs inside quote have auto dir");
"auto", assert
"RTL paragraphs inside quote have auto dir" .dom(quotedLtr)
); .hasAttribute("dir", "auto", "LTR paragraphs inside quote have auto dir");
assertDirection( assert
assert, .dom(quotedLtrNested)
quotedLtr, .hasAttribute(
"auto", "dir",
"LTR paragraphs inside quote have auto dir" "auto",
); "LTR paragraphs inside nested quote have auto dir"
assertDirection( );
assert, assert
quotedLtrNested, .dom(quotedRtlNested)
"auto", .hasAttribute(
"LTR paragraphs inside nested quote have auto dir" "dir",
); "auto",
assertDirection( "RTL paragraphs inside nested quote have auto dir"
assert, );
quotedRtlNested, assert
"auto", .dom(notQuotedLtr)
"RTL paragraphs inside nested quote have auto dir" .hasAttribute(
); "dir",
assertDirection( "auto",
assert, "LTR paragraphs outside quotes have auto dir"
notQuotedLtr, );
"auto", assert
"LTR paragraphs outside quotes have auto dir" .dom(notQuotedRtl)
); .hasAttribute(
assertDirection( "dir",
assert, "auto",
notQuotedRtl, "RTL paragraphs outside quotes have auto dir"
"auto", );
"RTL paragraphs outside quotes have auto dir"
);
}); });
}); });

View File

@ -155,17 +155,15 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
let video = fixture().querySelector("video"); let video = fixture().querySelector("video");
let link = fixture().querySelector("a"); let link = fixture().querySelector("a");
assert.strictEqual(image1.getAttribute("src"), "/images/avatar.png?a"); assert.dom(image1).hasAttribute("src", "/images/avatar.png?a");
assert.strictEqual(image2.getAttribute("src"), "/images/avatar.png?b"); assert.dom(image2).hasAttribute("src", "/images/avatar.png?b");
assert.strictEqual(link.getAttribute("href"), "/uploads/short-url/c.pdf"); assert.dom(link).hasAttribute("href", "/uploads/short-url/c.pdf");
assert.strictEqual( assert
video.querySelector("source").getAttribute("src"), .dom("source", video)
"/uploads/default/original/3X/c/b/4.mp4" .hasAttribute("src", "/uploads/default/original/3X/c/b/4.mp4");
); assert
assert.strictEqual( .dom("source", audio)
audio.querySelector("source").getAttribute("src"), .hasAttribute("src", "/uploads/default/original/3X/c/b/5.mp3");
"/uploads/default/original/3X/c/b/5.mp3"
);
}); });
test("resolveAllShortUrls - url with full origin replaced correctly", async function (assert) { test("resolveAllShortUrls - url with full origin replaced correctly", async function (assert) {
@ -174,10 +172,12 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
await settled(); await settled();
let video = fixture().querySelectorAll("video")[1]; let video = fixture().querySelectorAll("video")[1];
assert.strictEqual( assert
video.querySelector("source").getAttribute("src"), .dom("source", video)
"http://localhost:3000/uploads/default/original/3X/c/b/6.mp4" .hasAttribute(
); "src",
"http://localhost:3000/uploads/default/original/3X/c/b/6.mp4"
);
}); });
test("resolveAllShortUrls - when secure uploads is enabled use the attachment full URL", async function (assert) { test("resolveAllShortUrls - when secure uploads is enabled use the attachment full URL", async function (assert) {
@ -196,10 +196,9 @@ module("Unit | Utility | pretty-text/upload-short-url", function (hooks) {
await settled(); await settled();
let link = fixture().querySelector("a"); let link = fixture().querySelector("a");
assert.strictEqual( assert
link.getAttribute("href"), .dom(link)
"/secure-uploads/default/original/3X/c/b/3.pdf" .hasAttribute("href", "/secure-uploads/default/original/3X/c/b/3.pdf");
);
}); });
test("resolveAllShortUrls - scoped", async function (assert) { test("resolveAllShortUrls - scoped", async function (assert) {

View File

@ -99,13 +99,14 @@ module("Discourse Chat | Component | chat-upload", function (hooks) {
await render(hbs`<ChatUpload @upload={{this.upload}} />`); await render(hbs`<ChatUpload @upload={{this.upload}} />`);
assert.true(exists("video.chat-video-upload"), "displays as an video"); assert.true(exists("video.chat-video-upload"), "displays as an video");
const video = query("video.chat-video-upload"); assert.dom("video.chat-video-upload").hasAttribute("controls");
assert.true(video.hasAttribute("controls"), "has video controls"); assert
assert.strictEqual( .dom("video.chat-video-upload")
video.getAttribute("preload"), .hasAttribute(
"metadata", "preload",
"video has correct preload settings" "metadata",
); "video has correct preload settings"
);
}); });
test("with a audio", async function (assert) { test("with a audio", async function (assert) {
@ -114,13 +115,14 @@ module("Discourse Chat | Component | chat-upload", function (hooks) {
await render(hbs`<ChatUpload @upload={{this.upload}} />`); await render(hbs`<ChatUpload @upload={{this.upload}} />`);
assert.true(exists("audio.chat-audio-upload"), "displays as an audio"); assert.true(exists("audio.chat-audio-upload"), "displays as an audio");
const audio = query("audio.chat-audio-upload"); assert.dom("audio.chat-audio-upload").hasAttribute("controls");
assert.true(audio.hasAttribute("controls"), "has audio controls"); assert
assert.strictEqual( .dom("audio.chat-audio-upload")
audio.getAttribute("preload"), .hasAttribute(
"metadata", "preload",
"audio has correct preload settings" "metadata",
); "audio has correct preload settings"
);
}); });
test("non image upload", async function (assert) { test("non image upload", async function (assert) {

View File

@ -15,12 +15,6 @@ acceptance("Local Dates - composer", function (needs) {
}); });
test("composer bbcode", async function (assert) { test("composer bbcode", async function (assert) {
const getAttr = (attr) => {
return query(
".d-editor-preview .discourse-local-date.cooked-date"
).getAttribute(`data-${attr}`);
};
await visit("/"); await visit("/");
await click("#create-topic"); await click("#create-topic");
const categoryChooser = selectKit(".category-chooser"); const categoryChooser = selectKit(".category-chooser");
@ -32,45 +26,51 @@ acceptance("Local Dates - composer", function (needs) {
'[date=2017-10-23 time=01:30:00 displayedTimezone="America/Chicago" format="LLLL" calendar="off" recurring="1.weeks" timezone=" Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]' '[date=2017-10-23 time=01:30:00 displayedTimezone="America/Chicago" format="LLLL" calendar="off" recurring="1.weeks" timezone=" Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
); );
assert.strictEqual( assert
getAttr("date"), .dom(".d-editor-preview .discourse-local-date.cooked-date")
"2017-10-23", .hasAttribute("data-date", "2017-10-23", "has the correct date");
"it has the correct date" assert
); .dom(".d-editor-preview .discourse-local-date.cooked-date")
assert.strictEqual(getAttr("time"), "01:30:00", "it has the correct time"); .hasAttribute("data-time", "01:30:00", "has the correct time");
assert.strictEqual( assert
getAttr("displayed-timezone"), .dom(".d-editor-preview .discourse-local-date.cooked-date")
"America/Chicago", .hasAttribute(
"it has the correct displayed timezone" "data-displayed-timezone",
); "America/Chicago",
assert.strictEqual(getAttr("format"), "LLLL", "it has the correct format"); "has the correct displayed timezone"
assert.strictEqual( );
getAttr("timezones"), assert
"Europe/Paris|America/Los_Angeles", .dom(".d-editor-preview .discourse-local-date.cooked-date")
"it has the correct timezones" .hasAttribute("data-format", "LLLL", "has the correct format");
); assert
assert.strictEqual( .dom(".d-editor-preview .discourse-local-date.cooked-date")
getAttr("recurring"), .hasAttribute(
"1.weeks", "data-timezones",
"it has the correct recurring" "Europe/Paris|America/Los_Angeles",
); "has the correct timezones"
assert.strictEqual( );
getAttr("timezone"), assert
"Asia/Calcutta", .dom(".d-editor-preview .discourse-local-date.cooked-date")
"it has the correct timezone" .hasAttribute("data-recurring", "1.weeks", "has the correct recurring");
); assert
.dom(".d-editor-preview .discourse-local-date.cooked-date")
.hasAttribute(
"data-timezone",
"Asia/Calcutta",
"has the correct timezone"
);
await fillIn( await fillIn(
".d-editor-input", ".d-editor-input",
'[date=2017-10-24 format="LL" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]' '[date=2017-10-24 format="LL" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
); );
assert.strictEqual( assert
getAttr("date"), .dom(".d-editor-preview .discourse-local-date.cooked-date")
"2017-10-24", .hasAttribute("data-date", "2017-10-24", "has the correct date");
"it has the correct date" assert
); .dom(".d-editor-preview .discourse-local-date.cooked-date")
assert.notOk(getAttr("time"), "it doesn’t have time"); .doesNotHaveAttribute("data-time", "doesn’t have time");
}); });
test("date modal", async function (assert) { test("date modal", async function (assert) {