DEV: Use qunit-dom instead of classList/activeElement (#29676)

This commit is contained in:
Jarek Radosz 2024-11-11 11:44:42 +01:00 committed by GitHub
parent c4de8565ec
commit 429b6a4e4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 172 additions and 264 deletions

View File

@ -522,8 +522,8 @@ acceptance("Composer", function (needs) {
pretender.put("/posts/:post_id", async () => { pretender.put("/posts/:post_id", async () => {
// at this point, request is in flight, so post is staged // at this point, request is in flight, so post is staged
assert.dom(".topic-post.staged").exists(); assert.dom(".topic-post").exists();
assert.ok(query(".topic-post").classList.contains("staged")); assert.dom(".topic-post").hasClass("staged");
assert.strictEqual( assert.strictEqual(
query(".topic-post.staged .cooked").innerText.trim(), query(".topic-post.staged .cooked").innerText.trim(),
"will return empty json" "will return empty json"
@ -1103,11 +1103,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
await composer.focusComposer({ fallbackToNewTopic: true }); await composer.focusComposer({ fallbackToNewTopic: true });
await settled(); await settled();
assert.strictEqual( assert.dom(".d-editor-input").isFocused("composer is open and focused");
document.activeElement.classList.contains("d-editor-input"),
true,
"composer is opened and focused"
);
assert.strictEqual(composer.model.action, Composer.CREATE_TOPIC); assert.strictEqual(composer.model.action, Composer.CREATE_TOPIC);
}); });
@ -1121,11 +1117,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
}); });
await settled(); await settled();
assert.strictEqual( assert.dom(".d-editor-input").isFocused("composer is open and focused");
document.activeElement.classList.contains("d-editor-input"),
true,
"composer is opened and focused"
);
assert.strictEqual( assert.strictEqual(
query("textarea.d-editor-input").value.trim(), query("textarea.d-editor-input").value.trim(),
"this is appended" "this is appended"
@ -1140,11 +1132,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
await composer.focusComposer(); await composer.focusComposer();
await settled(); await settled();
assert.strictEqual( assert.dom(".d-editor-input").isFocused("composer is open and focused");
document.activeElement.classList.contains("d-editor-input"),
true,
"composer is opened and focused"
);
}); });
test("Focusing a composer which is already open and append text", async function (assert) { test("Focusing a composer which is already open and append text", async function (assert) {
@ -1155,11 +1143,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
await composer.focusComposer({ insertText: "this is some appended text" }); await composer.focusComposer({ insertText: "this is some appended text" });
await settled(); await settled();
assert.strictEqual( assert.dom(".d-editor-input").isFocused("composer is open and focused");
document.activeElement.classList.contains("d-editor-input"),
true,
"composer is opened and focused"
);
assert.strictEqual( assert.strictEqual(
query("textarea.d-editor-input").value.trim(), query("textarea.d-editor-input").value.trim(),
"this is some appended text" "this is some appended text"
@ -1177,11 +1161,7 @@ acceptance("Composer - Focus Open and Closed", function (needs) {
await composer.focusComposer({ insertText: "this is some appended text" }); await composer.focusComposer({ insertText: "this is some appended text" });
await settled(); await settled();
assert.strictEqual( assert.dom(".d-editor-input").isFocused("composer is open and focused");
document.activeElement.classList.contains("d-editor-input"),
true,
"composer is opened and focused"
);
assert.strictEqual( assert.strictEqual(
query("textarea.d-editor-input").value.trim(), query("textarea.d-editor-input").value.trim(),
"This is a dirty reply\n\nthis is some appended text" "This is a dirty reply\n\nthis is some appended text"

View File

@ -4,12 +4,13 @@ import {
getSettledState, getSettledState,
settled, settled,
visit, visit,
waitFor,
waitUntil, waitUntil,
} from "@ember/test-helpers"; } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import AboutFixtures from "discourse/tests/fixtures/about"; import AboutFixtures from "discourse/tests/fixtures/about";
import pretender from "discourse/tests/helpers/create-pretender"; import pretender from "discourse/tests/helpers/create-pretender";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
const SPINNER_SELECTOR = const SPINNER_SELECTOR =
"#main-outlet-wrapper .route-loading-spinner div.spinner"; "#main-outlet-wrapper .route-loading-spinner div.spinner";
@ -85,16 +86,11 @@ acceptance("Page Loading Indicator", function (needs) {
assert.strictEqual(currentRouteName(), "discovery.latest"); assert.strictEqual(currentRouteName(), "discovery.latest");
assert.dom(SPINNER_SELECTOR).doesNotExist(); assert.dom(SPINNER_SELECTOR).doesNotExist();
await waitUntil(() => await waitFor(".loading-indicator-container.loading");
query(".loading-indicator-container").classList.contains("loading")
);
pretender.resolve(aboutRequest); pretender.resolve(aboutRequest);
await waitUntil(() => await waitFor(".loading-indicator-container.done");
query(".loading-indicator-container").classList.contains("done")
);
await settled(); await settled();
assert.strictEqual(currentRouteName(), "about"); assert.strictEqual(currentRouteName(), "about");

View File

@ -10,10 +10,9 @@ acceptance("Sidebar - Anonymous User", function (needs) {
test("sidebar is displayed", async function (assert) { test("sidebar is displayed", async function (assert) {
await visit("/"); await visit("/");
assert.ok( assert
document.body.classList.contains("has-sidebar-page"), .dom(document.body)
"adds sidebar utility class to body" .hasClass("has-sidebar-page", "adds sidebar utility class to body");
);
assert assert
.dom(".sidebar-container") .dom(".sidebar-container")

View File

@ -182,23 +182,17 @@ acceptance("Sidebar - Plugin API", function (needs) {
.dom(links[0].children[0]) .dom(links[0].children[0])
.hasStyle({ color: "rgb(255, 0, 0)" }, "has correct prefix color"); .hasStyle({ color: "rgb(255, 0, 0)" }, "has correct prefix color");
assert.strictEqual( assert
links[0].children[0].children[0].classList.contains("d-icon-d-chat"), .dom(links[0].children[0].children[0])
true, .hasClass("d-icon-d-chat", "displays prefix icon");
"displays prefix icon"
);
assert.strictEqual( assert
links[0].children[0].children[1].classList.contains("d-icon-lock"), .dom(links[0].children[0].children[1])
true, .hasClass("d-icon-lock", "displays prefix icon badge");
"displays prefix icon badge"
);
assert.strictEqual( assert
links[0].children[2].children[0].classList.contains("d-icon-circle"), .dom(links[0].children[2].children[0])
true, .hasClass("d-icon-circle", "displays suffix icon");
"displays suffix icon"
);
assert assert
.dom(links[1].children[1]) .dom(links[1].children[1])

View File

@ -112,10 +112,9 @@ acceptance(
test("showing and hiding sidebar", async function (assert) { test("showing and hiding sidebar", async function (assert) {
await visit("/"); await visit("/");
assert.ok( assert
document.body.classList.contains("has-sidebar-page"), .dom(document.body)
"adds sidebar utility class to body" .hasClass("has-sidebar-page", "adds sidebar utility class to body");
);
assert assert
.dom(".sidebar-container") .dom(".sidebar-container")
@ -123,10 +122,12 @@ acceptance(
await click(".btn-sidebar-toggle"); await click(".btn-sidebar-toggle");
assert.ok( assert
!document.body.classList.contains("has-sidebar-page"), .dom(document.body)
"removes sidebar utility class from body" .doesNotHaveClass(
); "has-sidebar-page",
"removes sidebar utility class from body"
);
assert.dom(".sidebar-container").doesNotExist("hides the sidebar"); assert.dom(".sidebar-container").doesNotExist("hides the sidebar");

View File

@ -5,55 +5,39 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Static pages", function () { acceptance("Static pages", function () {
test("/faq", async function (assert) { test("/faq", async function (assert) {
await visit("/faq"); await visit("/faq");
assert.true( assert.dom(document.body).hasClass("static-faq", "/faq has the body class");
document.body.classList.contains("static-faq"),
"/faq has the body class"
);
assert.dom(".body-page").exists("The content is present"); assert.dom(".body-page").exists("The content is present");
}); });
test("/guidelines", async function (assert) { test("/guidelines", async function (assert) {
await visit("/guidelines"); await visit("/guidelines");
assert.true( assert
document.body.classList.contains("static-guidelines"), .dom(document.body)
"has the body class" .hasClass("static-guidelines", "has the body class");
);
assert.dom(".body-page").exists("The content is present"); assert.dom(".body-page").exists("The content is present");
}); });
test("/conduct", async function (assert) { test("/conduct", async function (assert) {
await visit("/conduct"); await visit("/conduct");
assert.true( assert.dom(document.body).hasClass("static-conduct", "has the body class");
document.body.classList.contains("static-conduct"),
"has the body class"
);
assert.dom(".body-page").exists("The content is present"); assert.dom(".body-page").exists("The content is present");
}); });
test("/tos", async function (assert) { test("/tos", async function (assert) {
await visit("/tos"); await visit("/tos");
assert.true( assert.dom(document.body).hasClass("static-tos", "has the body class");
document.body.classList.contains("static-tos"),
"has the body class"
);
assert.dom(".body-page").exists("The content is present"); assert.dom(".body-page").exists("The content is present");
}); });
test("/privacy", async function (assert) { test("/privacy", async function (assert) {
await visit("/privacy"); await visit("/privacy");
assert.true( assert.dom(document.body).hasClass("static-privacy", "has the body class");
document.body.classList.contains("static-privacy"),
"has the body class"
);
assert.dom(".body-page").exists("The content is present"); assert.dom(".body-page").exists("The content is present");
}); });
test("/rules", async function (assert) { test("/rules", async function (assert) {
await visit("/rules"); await visit("/rules");
assert.true( assert.dom(document.body).hasClass("static-rules", "has the body class");
document.body.classList.contains("static-rules"),
"has the body class"
);
assert.dom(".body-page").exists("The content is present"); assert.dom(".body-page").exists("The content is present");
}); });

View File

@ -105,10 +105,7 @@ acceptance("Tags", function (needs) {
test("list the tags", async function (assert) { test("list the tags", async function (assert) {
await visit("/tags"); await visit("/tags");
assert.ok( assert.dom(document.body).hasClass("tags-page", "has the body class");
document.body.classList.contains("tags-page"),
"has the body class"
);
assert.dom(`[data-tag-name="eviltrout"]`).exists("shows the eviltrout tag"); assert.dom(`[data-tag-name="eviltrout"]`).exists("shows the eviltrout tag");
}); });

View File

@ -25,10 +25,9 @@ acceptance("Topic Discovery", function (needs) {
test("Visit Discovery Pages", async function (assert) { test("Visit Discovery Pages", async function (assert) {
await visit("/"); await visit("/");
assert.ok( assert
document.body.classList.contains("navigation-topics"), .dom(document.body)
"has the default navigation" .hasClass("navigation-topics", "has the default navigation");
);
assert.dom(".topic-list").exists("the list of topics was rendered"); assert.dom(".topic-list").exists("the list of topics was rendered");
assert.dom(".topic-list .topic-list-item").exists("has topics"); assert.dom(".topic-list .topic-list-item").exists("has topics");
@ -52,31 +51,32 @@ acceptance("Topic Discovery", function (needs) {
assert.dom(".topic-list").exists("the list of topics was rendered"); assert.dom(".topic-list").exists("the list of topics was rendered");
assert.dom(".topic-list .topic-list-item").exists("has topics"); assert.dom(".topic-list .topic-list-item").exists("has topics");
assert.dom(".category-list").doesNotExist("doesn't render subcategories"); assert.dom(".category-list").doesNotExist("doesn't render subcategories");
assert.ok( assert
document.body.classList.contains("category-bug"), .dom(document.body)
"has a custom css class for the category id on the body" .hasClass(
); "category-bug",
"has a custom css class for the category id on the body"
);
await visit("/categories"); await visit("/categories");
assert.ok( assert
document.body.classList.contains("navigation-categories"), .dom(document.body)
"has the body class" .hasClass("navigation-categories", "has the body class");
); assert
assert.ok( .dom(document.body)
!document.body.classList.contains("category-bug"), .doesNotHaveClass("category-bug", "removes the custom category class");
"removes the custom category class"
);
assert.dom(".category").exists("has a list of categories"); assert.dom(".category").exists("has a list of categories");
assert.ok( assert
document.body.classList.contains("categories-list"), .dom(document.body)
"has a custom class to indicate categories" .hasClass("categories-list", "has a custom class to indicate categories");
);
await visit("/top"); await visit("/top");
assert.ok( assert
!document.body.classList.contains("categories-list"), .dom(document.body)
"removes the `categories-list` class" .doesNotHaveClass(
); "categories-list",
"removes the `categories-list` class"
);
assert.dom(".topic-list .topic-list-item").exists("has topics"); assert.dom(".topic-list .topic-list-item").exists("has topics");
await visit("/c/feature"); await visit("/c/feature");

View File

@ -1,27 +1,22 @@
import { click, triggerKeyEvent, visit } from "@ember/test-helpers"; import { click, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Entrance Modal", function () { acceptance("Topic Entrance Modal", function () {
test("can be closed with the esc key", async function (assert) { test("can be closed with the esc key", async function (assert) {
await visit("/"); await visit("/");
await click(".topic-list-item button.posts-map"); await click(".topic-list-item button.posts-map");
const topicEntrance = query("#topic-entrance"); assert
assert.ok( .dom("#topic-entrance")
!topicEntrance.classList.contains("hidden"), .doesNotHaveClass("hidden", "topic entrance modal appears");
"topic entrance modal appears" assert
); .dom("#topic-entrance .jump-top")
assert.equal( .isFocused("the jump top button has focus when the modal is shown");
document.activeElement,
topicEntrance.querySelector(".jump-top"),
"the jump top button has focus when the modal is shown"
);
await triggerKeyEvent(topicEntrance, "keydown", "Escape"); await triggerKeyEvent("#topic-entrance", "keydown", "Escape");
assert.ok( assert
topicEntrance.classList.contains("hidden"), .dom("#topic-entrance")
"topic entrance modal disappears after pressing esc" .hasClass("hidden", "topic entrance modal disappears after pressing esc");
);
}); });
}); });

View File

@ -6,10 +6,9 @@ acceptance("User Anonymous", function () {
test("Root URL", async function (assert) { test("Root URL", async function (assert) {
await visit("/u/eviltrout"); await visit("/u/eviltrout");
assert.ok( assert
document.body.classList.contains("user-summary-page"), .dom(document.body)
"has the body class" .hasClass("user-summary-page", "has the body class");
);
assert.strictEqual( assert.strictEqual(
currentRouteName(), currentRouteName(),
"user.summary", "user.summary",
@ -19,10 +18,9 @@ acceptance("User Anonymous", function () {
test("Filters", async function (assert) { test("Filters", async function (assert) {
await visit("/u/eviltrout/activity"); await visit("/u/eviltrout/activity");
assert.ok( assert
document.body.classList.contains("user-activity-page"), .dom(document.body)
"has the body class" .hasClass("user-activity-page", "has the body class");
);
assert.dom(".user-main .about").exists("has the about section"); assert.dom(".user-main .about").exists("has the about section");
assert.dom(".user-stream .item").exists("has stream items"); assert.dom(".user-stream .item").exists("has stream items");
@ -40,10 +38,9 @@ acceptance("User Anonymous", function () {
test("Badges", async function (assert) { test("Badges", async function (assert) {
await visit("/u/eviltrout/badges"); await visit("/u/eviltrout/badges");
assert.ok( assert
document.body.classList.contains("user-badges-page"), .dom(document.body)
"has the body class" .hasClass("user-badges-page", "has the body class");
);
assert.dom(".badge-group-list .badge-card").exists("shows a badge"); assert.dom(".badge-group-list .badge-card").exists("shows a badge");
}); });

View File

@ -35,11 +35,11 @@ acceptance("User Preferences - Interface", function (needs) {
const textSize = selectKit(".text-size .combo-box"); const textSize = selectKit(".text-size .combo-box");
await textSize.expand(); await textSize.expand();
await textSize.selectRowByValue("larger"); await textSize.selectRowByValue("larger");
assert.ok(document.documentElement.classList.contains("text-size-larger")); assert.dom(document.documentElement).hasClass("text-size-larger");
await textSize.expand(); await textSize.expand();
await textSize.selectRowByValue("largest"); await textSize.selectRowByValue("largest");
assert.ok(document.documentElement.classList.contains("text-size-largest")); assert.dom(document.documentElement).hasClass("text-size-largest");
assert.strictEqual(cookie("text_size"), undefined, "cookie is not set"); assert.strictEqual(cookie("text_size"), undefined, "cookie is not set");

View File

@ -688,7 +688,7 @@ acceptance(
const row = messagesDropdown.rowByName("test nav"); const row = messagesDropdown.rowByName("test nav");
assert.strictEqual(row.value(), "/u/eviltrout/preferences"); assert.strictEqual(row.value(), "/u/eviltrout/preferences");
assert.ok(row.icon().classList.contains("d-icon-arrow-left")); assert.dom(row.icon()).hasClass("d-icon-arrow-left");
} finally { } finally {
resetCustomUserNavMessagesDropdownRows(); resetCustomUserNavMessagesDropdownRows();
} }

View File

@ -63,19 +63,17 @@ acceptance("User Routes", function (needs) {
test("Invites", async function (assert) { test("Invites", async function (assert) {
await visit("/u/eviltrout/invited/pending"); await visit("/u/eviltrout/invited/pending");
assert.ok( assert
document.body.classList.contains("user-invites-page"), .dom(document.body)
"has the body class" .hasClass("user-invites-page", "has the body class");
);
}); });
test("Notifications", async function (assert) { test("Notifications", async function (assert) {
await visit("/u/eviltrout/notifications"); await visit("/u/eviltrout/notifications");
assert.ok( assert
document.body.classList.contains("user-notifications-page"), .dom(document.body)
"has the body class" .hasClass("user-notifications-page", "has the body class");
);
const $links = queryAll(".notification a"); const $links = queryAll(".notification a");
@ -102,10 +100,9 @@ acceptance("User Routes", function (needs) {
test("Root URL - Viewing Self", async function (assert) { test("Root URL - Viewing Self", async function (assert) {
await visit("/u/eviltrout"); await visit("/u/eviltrout");
assert.ok( assert
document.body.classList.contains("user-activity-page"), .dom(document.body)
"has the body class" .hasClass("user-activity-page", "has the body class");
);
assert.strictEqual( assert.strictEqual(
currentRouteName(), currentRouteName(),
"userActivity.index", "userActivity.index",
@ -163,10 +160,9 @@ acceptance("User Routes - Moderator viewing warnings", function (needs) {
test("Messages - Warnings", async function (assert) { test("Messages - Warnings", async function (assert) {
await visit("/u/eviltrout/messages/warnings"); await visit("/u/eviltrout/messages/warnings");
assert.ok( assert
document.body.classList.contains("user-messages-page"), .dom(document.body)
"has the body class" .hasClass("user-messages-page", "has the body class");
);
assert.dom("div.alert-info").exists("has the permissions alert"); assert.dom("div.alert-info").exists("has the permissions alert");
}); });
}); });

View File

@ -13,10 +13,7 @@ import I18n from "discourse-i18n";
acceptance("User Directory", function () { acceptance("User Directory", function () {
test("Visit Page", async function (assert) { test("Visit Page", async function (assert) {
await visit("/u"); await visit("/u");
assert.ok( assert.dom(document.body).hasClass("users-page", "has the body class");
document.body.classList.contains("users-page"),
"has the body class"
);
assert assert
.dom(".directory .directory-table .directory-table__row") .dom(".directory .directory-table .directory-table__row")
.exists("has a list of users"); .exists("has a list of users");
@ -29,10 +26,7 @@ acceptance("User Directory", function () {
test("Visit Without Usernames", async function (assert) { test("Visit Without Usernames", async function (assert) {
await visit("/u?exclude_usernames=system"); await visit("/u?exclude_usernames=system");
assert.ok( assert.dom(document.body).hasClass("users-page", "has the body class");
document.body.classList.contains("users-page"),
"has the body class"
);
assert assert
.dom(".directory .directory-table .directory-table__row") .dom(".directory .directory-table .directory-table__row")
.exists("has a list of users"); .exists("has a list of users");
@ -86,10 +80,7 @@ acceptance("User Directory", function () {
test("Visit With Group Filter", async function (assert) { test("Visit With Group Filter", async function (assert) {
await visit("/u?group=trust_level_0"); await visit("/u?group=trust_level_0");
assert.ok( assert.dom(document.body).hasClass("users-page", "has the body class");
document.body.classList.contains("users-page"),
"has the body class"
);
assert assert
.dom(".directory .directory-table .directory-table__row") .dom(".directory .directory-table .directory-table__row")
.exists("has a list of users"); .exists("has a list of users");

View File

@ -39,11 +39,9 @@ module(
"it shows the regular choice when value is not set" "it shows the regular choice when value is not set"
); );
const icon = this.subject.header().icon(); assert
assert.ok( .dom(this.subject.header().icon())
icon.classList.contains("d-icon-d-regular"), .hasClass("d-icon-d-regular", "shows the correct icon");
"it shows the correct icon"
);
}); });
} }
); );

View File

@ -2,7 +2,7 @@ import { fillIn, 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, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
import Theme, { COMPONENTS, THEMES } from "admin/models/theme"; import Theme, { COMPONENTS, THEMES } from "admin/models/theme";
@ -40,16 +40,10 @@ module("Integration | Component | themes-list", function (hooks) {
hbs`<ThemesList @themes={{this.themes}} @components={{this.components}} @currentTab={{this.currentTab}} />` hbs`<ThemesList @themes={{this.themes}} @components={{this.components}} @currentTab={{this.currentTab}} />`
); );
assert.strictEqual( assert.dom(".themes-tab").hasClass("active", "themes tab is active");
query(".themes-tab").classList.contains("active"), assert
true, .dom(".components-tab")
"themes tab is active" .doesNotHaveClass("active", "components tab is not active");
);
assert.strictEqual(
query(".components-tab").classList.contains("active"),
false,
"components tab is not active"
);
assert assert
.dom(".inactive-indicator") .dom(".inactive-indicator")
@ -120,16 +114,12 @@ module("Integration | Component | themes-list", function (hooks) {
hbs`<ThemesList @themes={{this.themes}} @components={{this.components}} @currentTab={{this.currentTab}} />` hbs`<ThemesList @themes={{this.themes}} @components={{this.components}} @currentTab={{this.currentTab}} />`
); );
assert.strictEqual( assert
query(".components-tab").classList.contains("active"), .dom(".components-tab")
true, .hasClass("active", "components tab is active");
"components tab is active" assert
); .dom(".themes-tab")
assert.strictEqual( .doesNotHaveClass("active", "themes tab is not active");
query(".themes-tab").classList.contains("active"),
false,
"themes tab is not active"
);
assert.dom(".inactive-indicator").doesNotExist("there is no separator"); assert.dom(".inactive-indicator").doesNotExist("there is no separator");
assert assert

View File

@ -20,11 +20,11 @@ module(
assert.strictEqual(items.length, 2); assert.strictEqual(items.length, 2);
assert.ok(items[0].classList.contains("notification")); assert.dom(items[0]).hasClass("notification");
assert.ok(items[0].classList.contains("unread")); assert.dom(items[0]).hasClass("unread");
assert.ok(items[0].classList.contains("bookmark-reminder")); assert.dom(items[0]).hasClass("bookmark-reminder");
assert.ok(items[1].classList.contains("bookmark")); assert.dom(items[1]).hasClass("bookmark");
}); });
test("show all button for bookmark notifications", async function (assert) { test("show all button for bookmark notifications", async function (assert) {

View File

@ -82,8 +82,7 @@ module(
getNotification(this.currentUser, this.siteSettings, this.site) getNotification(this.currentUser, this.siteSettings, this.site)
); );
await render(template); await render(template);
let item = query("li"); assert.dom("li").hasClass("mentioned");
assert.ok(item.classList.contains("mentioned"));
this.set( this.set(
"item", "item",
@ -303,24 +302,20 @@ module(
assert.dom("svg.d-icon-wrench").exists("icon is customized"); assert.dom("svg.d-icon-wrench").exists("icon is customized");
const label = query("li .item-label"); assert
assert.ok( .dom("li .item-label")
label.classList.contains("label-wrapper-1"), .hasClass("label-wrapper-1", "label wrapper has additional classes");
"label wrapper has additional classes"
);
assert.strictEqual( assert.strictEqual(
label.textContent.trim(), query("li .item-label").textContent.trim(),
"notification label 666 <span>", "notification label 666 <span>",
"label content is customized" "label content is customized"
); );
const description = query(".item-description"); assert
assert.ok( .dom(".item-description")
description.classList.contains("description-class-1"), .hasClass("description-class-1", "description has additional classes");
"description has additional classes"
);
assert.strictEqual( assert.strictEqual(
description.textContent.trim(), query(".item-description").textContent.trim(),
"notification description 123 <script>", "notification description 123 <script>",
"description content is customized" "description content is customized"
); );

View File

@ -16,9 +16,9 @@ module("Integration | Component | user-menu", function (hooks) {
const activeTab = query(".top-tabs.tabs-list .btn.active"); const activeTab = query(".top-tabs.tabs-list .btn.active");
assert.strictEqual(activeTab.id, "user-menu-button-all-notifications"); assert.strictEqual(activeTab.id, "user-menu-button-all-notifications");
const notifications = queryAll("#quick-access-all-notifications ul li"); const notifications = queryAll("#quick-access-all-notifications ul li");
assert.ok(notifications[0].classList.contains("edited")); assert.dom(notifications[0]).hasClass("edited");
assert.ok(notifications[1].classList.contains("replied")); assert.dom(notifications[1]).hasClass("replied");
assert.ok(notifications[2].classList.contains("liked-consolidated")); assert.dom(notifications[2]).hasClass("liked-consolidated");
}); });
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) {

View File

@ -107,15 +107,15 @@ module("Integration | Component | user-menu | messages-list", function (hooks) {
assert.strictEqual(items.length, 3); assert.strictEqual(items.length, 3);
assert.ok(items[0].classList.contains("notification")); assert.dom(items[0]).hasClass("notification");
assert.ok(items[0].classList.contains("unread")); assert.dom(items[0]).hasClass("unread");
assert.ok(items[0].classList.contains("private-message")); assert.dom(items[0]).hasClass("private-message");
assert.ok(items[1].classList.contains("notification")); assert.dom(items[1]).hasClass("notification");
assert.ok(items[1].classList.contains("read")); assert.dom(items[1]).hasClass("read");
assert.ok(items[1].classList.contains("group-message-summary")); assert.dom(items[1]).hasClass("group-message-summary");
assert.ok(items[2].classList.contains("message")); assert.dom(items[2]).hasClass("message");
}); });
test("does not error when there are no group_message_summary notifications", async function (assert) { test("does not error when there are no group_message_summary notifications", async function (assert) {
@ -132,11 +132,11 @@ module("Integration | Component | user-menu | messages-list", function (hooks) {
assert.strictEqual(items.length, 2); assert.strictEqual(items.length, 2);
assert.ok(items[0].classList.contains("notification")); assert.dom(items[0]).hasClass("notification");
assert.ok(items[0].classList.contains("unread")); assert.dom(items[0]).hasClass("unread");
assert.ok(items[0].classList.contains("private-message")); assert.dom(items[0]).hasClass("private-message");
assert.ok(items[1].classList.contains("message")); assert.dom(items[1]).hasClass("message");
}); });
test("does not error when there are no messages", async function (assert) { test("does not error when there are no messages", async function (assert) {
@ -154,13 +154,13 @@ module("Integration | Component | user-menu | messages-list", function (hooks) {
assert.strictEqual(items.length, 2); assert.strictEqual(items.length, 2);
assert.ok(items[0].classList.contains("notification")); assert.dom(items[0]).hasClass("notification");
assert.ok(items[0].classList.contains("unread")); assert.dom(items[0]).hasClass("unread");
assert.ok(items[0].classList.contains("private-message")); assert.dom(items[0]).hasClass("private-message");
assert.ok(items[1].classList.contains("notification")); assert.dom(items[1]).hasClass("notification");
assert.ok(items[1].classList.contains("read")); assert.dom(items[1]).hasClass("read");
assert.ok(items[1].classList.contains("group-message-summary")); assert.dom(items[1]).hasClass("group-message-summary");
}); });
test("merge-sorts group_message_summary notifications and messages", async function (assert) { test("merge-sorts group_message_summary notifications and messages", async function (assert) {

View File

@ -203,11 +203,9 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
await toggle(); await toggle();
assert.ok( assert
query( .dom("#my-dropdown .widget-dropdown-item:nth-child(3)")
"#my-dropdown .widget-dropdown-item:nth-child(3)" .hasClass("separator");
).classList.contains("separator")
);
}); });
test("hides widget if no content", async function (assert) { test("hides widget if no content", async function (assert) {
@ -225,9 +223,9 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
assert.ok(header().classList.contains("widget-dropdown-header")); assert.dom(header()).hasClass("widget-dropdown-header");
assert.ok(header().classList.contains("btn-small")); assert.dom(header()).hasClass("btn-small");
assert.ok(header().classList.contains("and-text")); assert.dom(header()).hasClass("and-text");
}); });
test("bodyClass option", async function (assert) { test("bodyClass option", async function (assert) {
@ -237,9 +235,9 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
await toggle(); await toggle();
assert.ok(body().classList.contains("widget-dropdown-body")); assert.dom(body()).hasClass("widget-dropdown-body");
assert.ok(body().classList.contains("gigantic")); assert.dom(body()).hasClass("gigantic");
assert.ok(body().classList.contains("and-yet-small")); assert.dom(body()).hasClass("and-yet-small");
}); });
test("caret option", async function (assert) { test("caret option", async function (assert) {

View File

@ -9,15 +9,15 @@ module("Integration | Helper | body-class", function (hooks) {
test("A single class", async function (assert) { test("A single class", async function (assert) {
await render(hbs`{{body-class "foo"}}`); await render(hbs`{{body-class "foo"}}`);
assert.true(document.body.classList.contains("foo")); assert.dom(document.body).hasClass("foo");
}); });
test("Multiple classes", async function (assert) { test("Multiple classes", async function (assert) {
this.set("bar", "bar"); this.set("bar", "bar");
await render(hbs`{{body-class "baz" this.bar}}`); await render(hbs`{{body-class "baz" this.bar}}`);
assert.true(document.body.classList.contains("baz")); assert.dom(document.body).hasClass("baz");
assert.true(document.body.classList.contains("bar")); assert.dom(document.body).hasClass("bar");
}); });
test("Empty classes", async function (assert) { test("Empty classes", async function (assert) {
@ -29,14 +29,13 @@ module("Integration | Helper | body-class", function (hooks) {
test("Dynamic classes", async function (assert) { test("Dynamic classes", async function (assert) {
this.set("dynamic", "bar"); this.set("dynamic", "bar");
await render(hbs`{{body-class this.dynamic}}`); await render(hbs`{{body-class this.dynamic}}`);
assert.true(document.body.classList.contains("bar"), "has .bar"); assert.dom(document.body).hasClass("bar");
this.set("dynamic", "baz"); this.set("dynamic", "baz");
await settled(); await settled();
assert.true(document.body.classList.contains("baz"), "has .baz"); assert.dom(document.body).hasClass("baz");
assert.false( assert
document.body.classList.contains("bar"), .dom(document.body)
"does not have .bar anymore" .doesNotHaveClass("bar", "does not have .bar anymore");
);
}); });
}); });

View File

@ -9,7 +9,7 @@ module("Unit | Utility | domFromString", function (hooks) {
const node = domFromString( const node = domFromString(
'<div class="foo">foo</div><div class="boo">boo</div>' '<div class="foo">foo</div><div class="boo">boo</div>'
); );
assert.ok(node[0].classList.contains("foo")); assert.dom(node[0]).hasClass("foo");
assert.ok(node[1].classList.contains("boo")); assert.dom(node[1]).hasClass("boo");
}); });
}); });

View File

@ -130,11 +130,9 @@ module("Unit | Utility | formatter", function (hooks) {
longDate(new Date()) longDate(new Date())
); );
assert.ok( assert
domFromString(formatDays(0, { format: "medium" }))[0].classList.contains( .dom(domFromString(formatDays(0, { format: "medium" }))[0])
"date" .hasClass("date");
)
);
this.clock.restore(); this.clock.restore();
this.clock = fakeTime("2012-01-09 12:00"); this.clock = fakeTime("2012-01-09 12:00");