DEV: Use the new `hasHtml`/`includesHtml` from qunit-dom (#29680)

This commit is contained in:
Jarek Radosz 2024-11-11 13:06:12 +01:00 committed by GitHub
parent 95fa997e4b
commit e68905510d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 404 additions and 495 deletions

View File

@ -481,10 +481,9 @@ acceptance("Prioritize Full Name", function (needs) {
await visit("/t/short-topic-with-two-posts/54079");
await click("article#post_3 button.reply");
assert.strictEqual(
query(".action-title .user-link").innerHTML.trim(),
"<h1>Tim Stone</h1>"
);
assert
.dom(".action-title .user-link")
.hasHtml("<h1>Tim Stone</h1>");
});
test("Quotes use full name", async function (assert) {

View File

@ -44,13 +44,11 @@ acceptance("Composer - Messages", function (needs) {
assert.dom(".composer-popup").exists("shows composer warning message");
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.user_not_seen_in_a_while.single", {
usernames: ['<a class="mention" href="/u/charlie">@charlie</a>'],
time_ago: "1 year ago",
})
),
assert.dom(".composer-popup").includesHtml(
I18n.t("composer.user_not_seen_in_a_while.single", {
usernames: ['<a class="mention" href="/u/charlie">@charlie</a>'],
time_ago: "1 year ago",
}),
"warning message has correct body"
);
@ -96,12 +94,10 @@ acceptance("Composer - Messages - Cannot see group", function (needs) {
await fillIn(".d-editor-input", "Mention @staff");
assert.dom(".composer-popup").exists("shows composer warning message");
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.cannot_see_group_mention.not_allowed", {
group: "staff",
})
),
assert.dom(".composer-popup").includesHtml(
I18n.t("composer.cannot_see_group_mention.not_allowed", {
group: "staff",
}),
"warning message has correct body"
);
});
@ -115,13 +111,11 @@ acceptance("Composer - Messages - Cannot see group", function (needs) {
await fillIn(".d-editor-input", "Mention @staff2");
assert.dom(".composer-popup").exists("shows composer warning message");
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.cannot_see_group_mention.some_not_allowed", {
group: "staff2",
count: 10,
})
),
assert.dom(".composer-popup").includesHtml(
I18n.t("composer.cannot_see_group_mention.some_not_allowed", {
group: "staff2",
count: 10,
}),
"warning message has correct body"
);
});
@ -237,18 +231,18 @@ acceptance("Composer - Messages - Private Messages", function (needs) {
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
assert.dom(".composer-popup").exists("shows composer warning message");
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.yourself_confirm.title")
),
"warning message has correct title"
);
assert.true(
query(".composer-popup").innerHTML.includes(
I18n.t("composer.yourself_confirm.body")
),
"warning message has correct body"
);
assert
.dom(".composer-popup")
.includesHtml(
I18n.t("composer.yourself_confirm.title"),
"warning message has correct title"
);
assert
.dom(".composer-popup")
.includesHtml(
I18n.t("composer.yourself_confirm.body"),
"warning message has correct body"
);
});
test("Does not show a warning in the composer if the message is sent to other users", async function (assert) {

View File

@ -1,6 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Composer - Onebox", function (needs) {
needs.user();
@ -29,17 +29,13 @@ http://www.example.com/has-title.html
);
assert.dom(".d-editor-preview").exists();
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
`
assert.dom(".d-editor-preview").hasHtml(`
<p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\" tabindex=\"-1\">An interesting article</a></h3></article></aside><br>
This is another test <a href=\"http://www.example.com/has-title.html\" class=\"inline-onebox\" tabindex=\"-1\">This is a great title</a></p>
<p><a href=\"http://www.example.com/no-title.html\" class=\"onebox\" target=\"_blank\" tabindex=\"-1\">http://www.example.com/no-title.html</a></p>
<p>This is another test <a href=\"http://www.example.com/no-title.html\" class=\"\" tabindex=\"-1\">http://www.example.com/no-title.html</a><br>
This is another test <a href=\"http://www.example.com/has-title.html\" class=\"inline-onebox\" tabindex=\"-1\">This is a great title</a></p>
<p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\" tabindex=\"-1\">An interesting article</a></h3></article></aside></p>
`.trim()
);
<p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\" tabindex=\"-1\">An interesting article</a></h3></article></aside></p>`);
});
});
@ -68,16 +64,18 @@ acceptance("Composer - Inline Onebox", function (needs) {
await fillIn(".d-editor-input", `Test www.example.com/page`);
assert.strictEqual(requestsCount, 1);
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
'<p>Test <a href="http://www.example.com/page" class="inline-onebox-loading" tabindex="-1">www.example.com/page</a></p>'
);
assert
.dom(".d-editor-preview")
.hasHtml(
'<p>Test <a href="http://www.example.com/page" class="inline-onebox-loading" tabindex="-1">www.example.com/page</a></p>'
);
await fillIn(".d-editor-input", `Test www.example.com/page Test`);
assert.strictEqual(requestsCount, 1);
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
'<p>Test <a href="http://www.example.com/page" tabindex="-1">www.example.com/page</a> Test</p>'
);
assert
.dom(".d-editor-preview")
.hasHtml(
'<p>Test <a href="http://www.example.com/page" tabindex="-1">www.example.com/page</a> Test</p>'
);
});
});

View File

@ -195,11 +195,12 @@ acceptance("Composer", function (needs) {
.exists("body error is dismissed via keyboard");
await fillIn(".d-editor-input", "this is the *content* of a post");
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
"<p>this is the <em>content</em> of a post</p>",
"it previews content"
);
assert
.dom(".d-editor-preview")
.hasHtml(
"<p>this is the <em>content</em> of a post</p>",
"previews content"
);
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("the body is now good");

View File

@ -14,10 +14,9 @@ acceptance("Composer topic featured links", function (needs) {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"it pastes the link into the body and previews it"
);
assert
.dom(".d-editor-preview")
.includesHtml("onebox", "pastes the link into the body and previews it");
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("the body is now good");
@ -32,10 +31,9 @@ acceptance("Composer topic featured links", function (needs) {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/no-title.html");
assert.ok(
query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"it pastes the link into the body and previews it"
);
assert
.dom(".d-editor-preview")
.includesHtml("onebox", "pastes the link into the body and previews it");
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("the body is now good");
@ -61,10 +59,9 @@ acceptance("Composer topic featured links", function (needs) {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/nope-onebox.html");
assert.ok(
query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"it pastes the link into the body and previews it"
);
assert
.dom(".d-editor-preview")
.includesHtml("onebox", "pastes the link into the body and previews it");
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("link is pasted into body");
@ -80,10 +77,9 @@ acceptance("Composer topic featured links", function (needs) {
await click("#create-topic");
const title = "http://" + window.location.hostname + "/internal-page.html";
await fillIn("#reply-title", title);
assert.ok(
!query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"onebox preview doesn't show"
);
assert
.dom(".d-editor-preview")
.doesNotIncludeHtml("onebox", "onebox preview doesn't show");
assert.strictEqual(
query(".d-editor-input").value.length,
0,
@ -103,10 +99,9 @@ acceptance("Composer topic featured links", function (needs) {
"#reply-title",
"http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"
);
assert.ok(
query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"it pastes the link into the body and previews it"
);
assert
.dom(".d-editor-preview")
.includesHtml("onebox", "pastes the link into the body and previews it");
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("the body is now good");
@ -121,10 +116,9 @@ acceptance("Composer topic featured links", function (needs) {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html test");
assert.ok(
!query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"onebox preview doesn't show"
);
assert
.dom(".d-editor-preview")
.doesNotIncludeHtml("onebox", "onebox preview doesn't show");
assert.strictEqual(
query(".d-editor-input").value.length,
0,
@ -144,10 +138,9 @@ acceptance("Composer topic featured links", function (needs) {
"#reply-title",
"https://twitter.com/discourse/status/1357664660724482048"
);
assert.ok(
query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"it pastes the link into the body and previews it"
);
assert
.dom(".d-editor-preview")
.includesHtml("onebox", "pastes the link into the body and previews it");
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("the body is now good");
@ -173,10 +166,12 @@ acceptance(
.dom(".d-editor-textarea-wrapper.disabled")
.exists("textarea is disabled");
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
query(".d-editor-preview").innerHTML.trim().includes("onebox"),
"it pastes the link into the body and previews it"
);
assert
.dom(".d-editor-preview")
.includesHtml(
"onebox",
"pastes the link into the body and previews it"
);
assert
.dom(".d-editor-textarea-wrapper .popup-tip.good")
.exists("the body is now good");

View File

@ -61,10 +61,16 @@ acceptance("DStyles - category backgrounds", function (needs) {
test("CSS classes are generated", async function (assert) {
await visit("/");
const css =
"body.category-foo { background-image: url(/uploads/default/original/1X/c5c84b16ebf745ab848d1498267c541facbf1ff0.png); }\n" +
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/684c104edc18a7e9cef1fa31f41215f3eec5d92b.png); }";
assert.ok(document.querySelector("#d-styles").innerHTML.includes(css));
assert
.dom("#d-styles")
.includesHtml(
"body.category-foo { background-image: url(/uploads/default/original/1X/c5c84b16ebf745ab848d1498267c541facbf1ff0.png); }"
);
assert
.dom("#d-styles")
.includesHtml(
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/684c104edc18a7e9cef1fa31f41215f3eec5d92b.png); }"
);
});
});
@ -87,14 +93,15 @@ acceptance("DStyles - category backgrounds (dark)", function (needs) {
test("CSS classes are generated", async function (assert) {
await visit("/");
const css =
"body.category-foo { background-image: url(/uploads/default/original/1X/c5c84b16ebf745ab848d1498267c541facbf1ff0.png); }\n" +
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/684c104edc18a7e9cef1fa31f41215f3eec5d92b.png); }\n" +
"@media (prefers-color-scheme: dark) {\n" +
"body.category-bar { background-image: url(/uploads/default/original/1X/f9fdb0ad108f2aed178c40f351bbb2c7cb2571e3.png); }\n" +
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/89b1a2641e91604c32b21db496be11dba7a253e6.png); }\n" +
"}";
assert.ok(document.querySelector("#d-styles").innerHTML.includes(css));
const css = [
"body.category-foo { background-image: url(/uploads/default/original/1X/c5c84b16ebf745ab848d1498267c541facbf1ff0.png); }",
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/684c104edc18a7e9cef1fa31f41215f3eec5d92b.png); }",
"@media (prefers-color-scheme: dark) {",
"body.category-bar { background-image: url(/uploads/default/original/1X/f9fdb0ad108f2aed178c40f351bbb2c7cb2571e3.png); }",
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/89b1a2641e91604c32b21db496be11dba7a253e6.png); }",
"}",
].join(" ");
assert.dom("#d-styles").includesHtml(css);
});
});
@ -119,11 +126,12 @@ acceptance(
test("CSS classes are generated", async function (assert) {
await visit("/");
const css =
"body.category-foo { background-image: url(/uploads/default/original/1X/c5c84b16ebf745ab848d1498267c541facbf1ff0.png); }\n" +
"body.category-bar { background-image: url(/uploads/default/original/1X/f9fdb0ad108f2aed178c40f351bbb2c7cb2571e3.png); }\n" +
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/89b1a2641e91604c32b21db496be11dba7a253e6.png); }";
assert.ok(document.querySelector("#d-styles").innerHTML.includes(css));
const css = [
"body.category-foo { background-image: url(/uploads/default/original/1X/c5c84b16ebf745ab848d1498267c541facbf1ff0.png); }",
"body.category-bar { background-image: url(/uploads/default/original/1X/f9fdb0ad108f2aed178c40f351bbb2c7cb2571e3.png); }",
"body.category-foo-baz { background-image: url(/uploads/default/original/1X/89b1a2641e91604c32b21db496be11dba7a253e6.png); }",
].join(" ");
assert.dom("#d-styles").includesHtml(css);
});
}
);
@ -148,23 +156,25 @@ acceptance("DStyles - category badges", function (needs) {
test("category CSS variables are generated", async function (assert) {
await visit("/");
const css =
":root {\n" +
"--category-1-color: #ff0000;\n" +
"--category-2-color: #333;\n" +
"--category-4-color: #2B81AF;\n" +
"}";
assert.ok(document.querySelector("style#d-styles").innerHTML.includes(css));
const css = [
":root {",
"--category-1-color: #ff0000;",
"--category-2-color: #333;",
"--category-4-color: #2B81AF;",
"}",
].join(" ");
assert.dom("style#d-styles").includesHtml(css);
});
test("category badge CSS variables are generated", async function (assert) {
await visit("/");
const css =
'.badge-category[data-category-id="1"] { --category-badge-color: var(--category-1-color); --category-badge-text-color: #ffffff; }\n' +
'.badge-category[data-parent-category-id="1"] { --parent-category-badge-color: var(--category-1-color); }\n' +
'.badge-category[data-category-id="2"] { --category-badge-color: var(--category-2-color); --category-badge-text-color: #ffffff; }\n' +
'.badge-category[data-category-id="4"] { --category-badge-color: var(--category-4-color); --category-badge-text-color: #ffffff; }';
assert.ok(document.querySelector("style#d-styles").innerHTML.includes(css));
const css = [
'.badge-category[data-category-id="1"] { --category-badge-color: var(--category-1-color); --category-badge-text-color: #ffffff; }',
'.badge-category[data-parent-category-id="1"] { --parent-category-badge-color: var(--category-1-color); }',
'.badge-category[data-category-id="2"] { --category-badge-color: var(--category-2-color); --category-badge-text-color: #ffffff; }',
'.badge-category[data-category-id="4"] { --category-badge-color: var(--category-4-color); --category-badge-text-color: #ffffff; }',
].join(" ");
assert.dom("style#d-styles").includesHtml(css);
});
});

View File

@ -3,7 +3,6 @@ import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
import { test } from "qunit";
import {
acceptance,
normalizeHtml,
query,
simulateKey,
simulateKeys,
@ -18,12 +17,11 @@ acceptance("Emoji", function (needs) {
await simulateKeys(".d-editor-input", "a :blonde_wo\t");
assert.strictEqual(
normalizeHtml(query(".d-editor-preview").innerHTML.trim()),
normalizeHtml(
assert
.dom(".d-editor-preview")
.hasHtml(
`<p>a <img src="/images/emoji/twitter/blonde_woman.png?v=${v}" title=":blonde_woman:" class="emoji" alt=":blonde_woman:" loading="lazy" width="20" height="20" style="aspect-ratio: 20 / 20;"></p>`
)
);
);
});
test("emoji can be picked from the emoji-picker using the mouse", async function (assert) {
@ -37,12 +35,11 @@ acceptance("Emoji", function (needs) {
assert.dom(".emoji-picker.opened.has-filter").exists();
await click(".emoji-picker .results img:first-of-type");
assert.strictEqual(
normalizeHtml(query(".d-editor-preview").innerHTML.trim()),
normalizeHtml(
assert
.dom(".d-editor-preview")
.hasHtml(
`<p>an <img src="/images/emoji/twitter/arrow_backward.png?v=${v}" title=":arrow_backward:" class="emoji" alt=":arrow_backward:" loading="lazy" width="20" height="20" style="aspect-ratio: 20 / 20;"></p>`
)
);
);
});
test("skin toned emoji is cooked properly", async function (assert) {
@ -51,12 +48,11 @@ acceptance("Emoji", function (needs) {
await fillIn(".d-editor-input", "a :blonde_woman:t5:");
assert.strictEqual(
normalizeHtml(query(".d-editor-preview").innerHTML.trim()),
normalizeHtml(
assert
.dom(".d-editor-preview")
.hasHtml(
`<p>a <img src="/images/emoji/twitter/blonde_woman/5.png?v=${v}" title=":blonde_woman:t5:" class="emoji" alt=":blonde_woman:t5:" loading="lazy" width="20" height="20" style="aspect-ratio: 20 / 20;"></p>`
)
);
);
});
needs.settings({ emoji_autocomplete_min_chars: 2 });

View File

@ -1,6 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
let userFound = false;
@ -26,23 +26,21 @@ acceptance("Forgot password", function (needs) {
await fillIn("#username-or-email", "someuser");
await click(".forgot-password-reset");
assert.strictEqual(
query(".alert-error").innerHTML.trim(),
assert.dom(".alert-error").hasHtml(
I18n.t("forgot_password.complete_username_not_found", {
username: "someuser",
}),
"it should display an error for an invalid username"
"displays an error for an invalid username"
);
await fillIn("#username-or-email", "someuser@gmail.com");
await click(".forgot-password-reset");
assert.strictEqual(
query(".alert-error").innerHTML.trim(),
assert.dom(".alert-error").hasHtml(
I18n.t("forgot_password.complete_email_not_found", {
email: "someuser@gmail.com",
}),
"it should display an error for an invalid email"
"displays an error for an invalid email"
);
await fillIn("#username-or-email", "someuser");
@ -55,12 +53,11 @@ acceptance("Forgot password", function (needs) {
.dom(".alert-error")
.doesNotExist("it should remove the flash error when succeeding");
assert.strictEqual(
query(".d-modal__body").innerHTML.trim(),
assert.dom(".d-modal__body").hasHtml(
I18n.t("forgot_password.complete_username_found", {
username: "someuser",
}),
"it should display a success message for a valid username"
"displays a success message for a valid username"
);
await visit("/");
@ -69,12 +66,11 @@ acceptance("Forgot password", function (needs) {
await fillIn("#username-or-email", "someuser@gmail.com");
await click(".forgot-password-reset");
assert.strictEqual(
query(".d-modal__body").innerHTML.trim(),
assert.dom(".d-modal__body").hasHtml(
I18n.t("forgot_password.complete_email_found", {
email: "someuser@gmail.com",
}),
"it should display a success message for a valid email"
"displays a success message for a valid email"
);
});
});
@ -100,12 +96,11 @@ acceptance(
await fillIn("#username-or-email", "someuser");
await click(".forgot-password-reset");
assert.strictEqual(
query(".d-modal__body").innerHTML.trim(),
assert.dom(".d-modal__body").hasHtml(
I18n.t("forgot_password.complete_username", {
username: "someuser",
}),
"it should display a success message"
"displays a success message"
);
});
}

View File

@ -22,12 +22,13 @@ acceptance("Hashtag CSS Generator", function (needs) {
test("classes are generated", async function (assert) {
await visit("/");
const cssTag = document.querySelector("style#hashtag-css-generator");
assert.equal(
cssTag.innerHTML,
".hashtag-category-badge { background-color: var(--primary-medium); }\n" +
".hashtag-color--category-1 { background-color: #ff0000; }\n" +
".hashtag-color--category-2 { background-color: #333; }\n" +
".hashtag-color--category-4 { background: linear-gradient(-90deg, #2B81AF 50%, #ff0000 50%); }"
);
assert
.dom(cssTag)
.hasHtml(
".hashtag-category-badge { background-color: var(--primary-medium); }\n" +
".hashtag-color--category-1 { background-color: #ff0000; }\n" +
".hashtag-color--category-2 { background-color: #333; }\n" +
".hashtag-color--category-4 { background: linear-gradient(-90deg, #2B81AF 50%, #ff0000 50%); }"
);
});
});

View File

@ -1,6 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
acceptance("Login with email - hide email address taken", function (needs) {
@ -21,12 +21,11 @@ acceptance("Login with email - hide email address taken", function (needs) {
await fillIn("#login-account-name", "someuser@example.com");
await click("#email-login-link");
assert.strictEqual(
query(".alert-success").innerHTML.trim(),
assert.dom(".alert-success").hasHtml(
I18n.t("email_login.complete_email_found", {
email: "someuser@example.com",
}),
"it should display the success message for any email address"
"displays the success message for any email address"
);
});
});

View File

@ -2,7 +2,7 @@ import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import sinon from "sinon";
import DiscourseURL from "discourse/lib/url";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
const TOKEN = "sometoken";
@ -49,23 +49,21 @@ acceptance("Login with email", function (needs) {
await fillIn("#login-account-name", "someuser");
await click("#email-login-link");
assert.strictEqual(
query("#modal-alert").innerHTML.trim(),
assert.dom("#modal-alert").hasHtml(
I18n.t("email_login.complete_username_not_found", {
username: "someuser",
}),
"it should display an error for an invalid username"
"displays an error for an invalid username"
);
await fillIn("#login-account-name", "someuser@gmail.com");
await click("#email-login-link");
assert.strictEqual(
query("#modal-alert").innerHTML.trim(),
assert.dom("#modal-alert").hasHtml(
I18n.t("email_login.complete_email_not_found", {
email: "someuser@gmail.com",
}),
"it should display an error for an invalid email"
"displays an error for an invalid email"
);
await fillIn("#login-account-name", "someuser");
@ -74,23 +72,23 @@ acceptance("Login with email", function (needs) {
await click("#email-login-link");
assert.strictEqual(
query(".alert-success").innerHTML.trim(),
I18n.t("email_login.complete_username_found", { username: "someuser" }),
"it should display a success message for a valid username"
);
assert
.dom(".alert-success")
.hasHtml(
I18n.t("email_login.complete_username_found", { username: "someuser" }),
"displays a success message for a valid username"
);
await visit("/");
await click("header .login-button");
await fillIn("#login-account-name", "someuser@gmail.com");
await click("#email-login-link");
assert.strictEqual(
query(".alert-success").innerHTML.trim(),
assert.dom(".alert-success").hasHtml(
I18n.t("email_login.complete_email_found", {
email: "someuser@gmail.com",
}),
"it should display a success message for a valid email"
"displays a success message for a valid email"
);
userFound = false;

View File

@ -4,7 +4,7 @@ import sinon from "sinon";
import PreloadStore from "discourse/lib/preload-store";
import DiscourseURL from "discourse/lib/url";
import { parsePostData } from "discourse/tests/helpers/create-pretender";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
acceptance("Password Reset", function (needs) {
@ -72,24 +72,22 @@ acceptance("Password Reset", function (needs) {
await fillIn(".password-reset input", "123");
assert.dom(".password-reset .tip.bad").exists("input is not valid");
assert.ok(
query(".password-reset .tip.bad").innerHTML.includes(
I18n.t("user.password.too_short", {
count: this.siteSettings.min_password_length,
})
),
assert.dom(".password-reset .tip.bad").includesHtml(
I18n.t("user.password.too_short", {
count: this.siteSettings.min_password_length,
}),
"password too short"
);
await fillIn(".password-reset input", "jonesyAlienSlayer");
await click(".password-reset form button[type='submit']");
assert.dom(".password-reset .tip.bad").exists("input is not valid");
assert.ok(
query(".password-reset .tip.bad").innerHTML.includes(
"Password is the name of your cat"
),
"server validation error message shows"
);
assert
.dom(".password-reset .tip.bad")
.includesHtml(
"Password is the name of your cat",
"server validation error message shows"
);
assert
.dom("#new-account-password[type='password']")
@ -121,10 +119,9 @@ acceptance("Password Reset", function (needs) {
assert.dom(".alert-error").exists("shows 2FA error");
assert.ok(
query(".alert-error").innerHTML.includes("invalid token"),
"shows server validation error message"
);
assert
.dom(".alert-error")
.includesHtml("invalid token", "shows server validation error message");
await fillIn("input#second-factor", "123123");
await click(".password-reset form button");

View File

@ -1,6 +1,6 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Reports", function (needs) {
needs.user();
@ -10,21 +10,15 @@ acceptance("Reports", function (needs) {
assert.dom(".admin-reports-list__report").exists({ count: 1 });
const report = query(".admin-reports-list__report:first-child");
assert
.dom(".admin-reports-list__report .admin-reports-list__report-title")
.hasHtml("My report");
assert.strictEqual(
report
.querySelector(".admin-reports-list__report-title")
.innerHTML.trim(),
"My report"
);
assert.strictEqual(
report
.querySelector(".admin-reports-list__report-description")
.innerHTML.trim(),
"List of my activities"
);
assert
.dom(
".admin-reports-list__report .admin-reports-list__report-description"
)
.hasHtml("List of my activities");
});
test("Visit report page", async function (assert) {

View File

@ -62,24 +62,24 @@ acceptance("Review", function (needs) {
await reviewableActionDropdown.selectRowByValue("reject_user_delete");
assert.dom(".reject-reason-reviewable-modal").exists();
assert.ok(
query(
".reject-reason-reviewable-modal .d-modal__title"
).innerHTML.includes(I18n.t("review.reject_reason.title")),
"it opens reject reason modal when user is rejected"
);
assert
.dom(".reject-reason-reviewable-modal .d-modal__title")
.includesHtml(
I18n.t("review.reject_reason.title"),
"opens reject reason modal when user is rejected"
);
await click(".d-modal__footer .cancel");
await reviewableActionDropdown.expand();
await reviewableActionDropdown.selectRowByValue("reject_user_block");
assert.dom(".reject-reason-reviewable-modal").exists();
assert.ok(
query(
".reject-reason-reviewable-modal .d-modal__title"
).innerHTML.includes(I18n.t("review.reject_reason.title")),
"it opens reject reason modal when user is rejected and blocked"
);
assert
.dom(".reject-reason-reviewable-modal .d-modal__title")
.includesHtml(
I18n.t("review.reject_reason.title"),
"opens reject reason modal when user is rejected and blocked"
);
});
test("Settings", async function (assert) {
@ -104,10 +104,9 @@ acceptance("Review", function (needs) {
.dom(".reviewable-flagged-post .post-contents .username a[href]")
.exists("it has a link to the user");
assert.strictEqual(
query(".reviewable-flagged-post .post-body").innerHTML.trim(),
"<b>cooked content</b>"
);
assert
.dom(".reviewable-flagged-post .post-body")
.hasHtml("<b>cooked content</b>");
assert
.dom(".reviewable-flagged-post .reviewable-score")

View File

@ -1,6 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
acceptance("Topic move posts", function (needs) {
@ -28,33 +28,30 @@ acceptance("Topic move posts", function (needs) {
await click(".selected-posts .move-to-topic");
assert.ok(
query(".choose-topic-modal .d-modal__title").innerHTML.includes(
I18n.t("topic.move_to.title")
),
"it opens move to modal"
);
assert
.dom(".choose-topic-modal .d-modal__title")
.includesHtml(I18n.t("topic.move_to.title"), "opens move to modal");
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.split_topic.radio_label")
),
"it shows an option to move to new topic"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.split_topic.radio_label"),
"shows an option to move to new topic"
);
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.merge_topic.radio_label")
),
"it shows an option to move to existing topic"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.merge_topic.radio_label"),
"shows an option to move to existing topic"
);
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.move_to_new_message.radio_label")
),
"it shows an option to move to new message"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.move_to_new_message.radio_label"),
"shows an option to move to new message"
);
});
test("display error when new topic has invalid title", async function (assert) {
@ -75,33 +72,30 @@ acceptance("Topic move posts", function (needs) {
await click(".select-all");
await click(".selected-posts .move-to-topic");
assert.ok(
query(".choose-topic-modal .d-modal__title").innerHTML.includes(
I18n.t("topic.move_to.title")
),
"it opens move to modal"
);
assert
.dom(".choose-topic-modal .d-modal__title")
.includesHtml(I18n.t("topic.move_to.title"), "opens move to modal");
assert.notOk(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.split_topic.radio_label")
),
"it does not show an option to move to new topic"
);
assert
.dom(".choose-topic-modal .radios")
.doesNotIncludeHtml(
I18n.t("topic.split_topic.radio_label"),
"does not show an option to move to new topic"
);
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.merge_topic.radio_label")
),
"it shows an option to move to existing topic"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.merge_topic.radio_label"),
"shows an option to move to existing topic"
);
assert.notOk(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.move_to_new_message.radio_label")
),
"it does not show an option to move to new message"
);
assert
.dom(".choose-topic-modal .radios")
.doesNotIncludeHtml(
I18n.t("topic.move_to_new_message.radio_label"),
"does not show an option to move to new message"
);
});
test("moving posts to existing topic", async function (assert) {
@ -112,12 +106,12 @@ acceptance("Topic move posts", function (needs) {
await click(".selected-posts .move-to-topic");
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.merge_topic.radio_label")
),
"it shows an option to move to an existing topic"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.merge_topic.radio_label"),
"shows an option to move to an existing topic"
);
await click(".choose-topic-modal .radios #move-to-existing-topic");
@ -131,12 +125,12 @@ acceptance("Topic move posts", function (needs) {
await click(".choose-topic-list .existing-topic:first-child input");
assert.ok(
query(".choose-topic-modal .checkbox-label").innerHTML.includes(
I18n.t("topic.merge_topic.chronological_order")
),
"it shows a checkbox to merge posts in chronological order"
);
assert
.dom(".choose-topic-modal .checkbox-label")
.includesHtml(
I18n.t("topic.merge_topic.chronological_order"),
"shows a checkbox to merge posts in chronological order"
);
});
test("moving posts from personal message", async function (assert) {
@ -154,26 +148,23 @@ acceptance("Topic move posts", function (needs) {
await click(".selected-posts .move-to-topic");
assert.ok(
query(".choose-topic-modal .d-modal__title").innerHTML.includes(
I18n.t("topic.move_to.title")
),
"it opens move to modal"
);
assert
.dom(".choose-topic-modal .d-modal__title")
.includesHtml(I18n.t("topic.move_to.title"), "opens move to modal");
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.move_to_new_message.radio_label")
),
"it shows an option to move to new message"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.move_to_new_message.radio_label"),
"shows an option to move to new message"
);
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.move_to_existing_message.radio_label")
),
"it shows an option to move to existing message"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.move_to_existing_message.radio_label"),
"shows an option to move to existing message"
);
});
test("group moderator moving posts", async function (assert) {
@ -191,12 +182,9 @@ acceptance("Topic move posts", function (needs) {
await click(".selected-posts .move-to-topic");
assert.ok(
query(".choose-topic-modal .d-modal__title").innerHTML.includes(
I18n.t("topic.move_to.title")
),
"it opens move to modal"
);
assert
.dom(".choose-topic-modal .d-modal__title")
.includesHtml(I18n.t("topic.move_to.title"), "opens move to modal");
});
test("moving posts from personal message to existing message", async function (assert) {
@ -207,12 +195,12 @@ acceptance("Topic move posts", function (needs) {
await click(".selected-posts .move-to-topic");
assert.ok(
query(".choose-topic-modal .radios").innerHTML.includes(
I18n.t("topic.move_to_existing_message.radio_label")
),
"it shows an option to move to an existing message"
);
assert
.dom(".choose-topic-modal .radios")
.includesHtml(
I18n.t("topic.move_to_existing_message.radio_label"),
"shows an option to move to an existing message"
);
await click(".choose-topic-modal .radios #move-to-existing-message");
@ -226,11 +214,11 @@ acceptance("Topic move posts", function (needs) {
await click(".choose-topic-modal .existing-message:first-of-type input");
assert.ok(
query(".choose-topic-modal .checkbox-label").innerHTML.includes(
I18n.t("topic.merge_topic.chronological_order")
),
"it shows a checkbox to merge posts in chronological order"
);
assert
.dom(".choose-topic-modal .checkbox-label")
.includesHtml(
I18n.t("topic.merge_topic.chronological_order"),
"shows a checkbox to merge posts in chronological order"
);
});
});

View File

@ -168,10 +168,9 @@ acceptance("Topic", function (needs) {
await click("#topic-title .submit-edit");
assert.ok(
query(".fancy-title").innerHTML.trim().includes("bike.png"),
"it displays the new title with emojis"
);
assert
.dom(".fancy-title")
.includesHtml("bike.png", "displays the new title with emojis");
});
test("Updating the topic title with unicode emojis", async function (assert) {
@ -182,10 +181,9 @@ acceptance("Topic", function (needs) {
await click("#topic-title .submit-edit");
assert.ok(
query(".fancy-title").innerHTML.trim().includes("man_farmer.png"),
"it displays the new title with emojis"
);
assert
.dom(".fancy-title")
.includesHtml("man_farmer.png", "displays the new title with emojis");
});
test("Updating the topic title with unicode emojis without whitespace", async function (assert) {
@ -197,12 +195,12 @@ acceptance("Topic", function (needs) {
await click("#topic-title .submit-edit");
assert.ok(
query(".fancy-title")
.innerHTML.trim()
.includes("slightly_smiling_face.png"),
"it displays the new title with emojis"
);
assert
.dom(".fancy-title")
.includesHtml(
"slightly_smiling_face.png",
"displays the new title with emojis"
);
});
test("Suggested topics", async function (assert) {
@ -346,21 +344,21 @@ acceptance("Topic featured links", function (needs) {
await click(".topic-admin-multi-select .btn");
await click("#post_3 .select-below");
assert.ok(
query(".selected-posts").innerHTML.includes(
I18n.t("topic.multi_select.description", { count: 18 })
),
"it should select the right number of posts"
);
assert
.dom(".selected-posts")
.includesHtml(
I18n.t("topic.multi_select.description", { count: 18 }),
"selects the right number of posts"
);
await click("#post_2 .select-below");
assert.ok(
query(".selected-posts").innerHTML.includes(
I18n.t("topic.multi_select.description", { count: 19 })
),
"it should select the right number of posts"
);
assert
.dom(".selected-posts")
.includesHtml(
I18n.t("topic.multi_select.description", { count: 19 }),
"selects the right number of posts"
);
});
test("View Hidden Replies", async function (assert) {

View File

@ -1,11 +1,7 @@
import { click, visit } from "@ember/test-helpers";
import { IMAGE_VERSION } from "pretty-text/emoji/version";
import { test } from "qunit";
import {
acceptance,
normalizeHtml,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Drafts", function (needs) {
needs.user();
@ -47,15 +43,12 @@ acceptance("User Drafts", function (needs) {
query(".user-stream-item:nth-child(3) .category").textContent,
"meta"
);
assert.strictEqual(
normalizeHtml(
query(".user-stream-item:nth-child(3) .excerpt").innerHTML.trim()
),
normalizeHtml(
`here goes a reply to a PM <img src="/images/emoji/twitter/slight_smile.png?v=${IMAGE_VERSION}" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20" style="aspect-ratio: 20 / 20;">`
),
"shows the excerpt"
);
assert
.dom(".user-stream-item:nth-child(3) .excerpt")
.hasHtml(
`here goes a reply to a PM <img src="/images/emoji/twitter/slight_smile.png?v=${IMAGE_VERSION}" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20" style="aspect-ratio: 20 / 20;">`,
"shows the excerpt"
);
assert
.dom(".user-stream-item:nth-child(2) a.avatar-link")

View File

@ -121,22 +121,19 @@ acceptance("User Preferences - Account", function (needs) {
.dom(".pref-associated-accounts")
.exists("it has the connected accounts section");
assert.ok(
query(
assert
.dom(
".pref-associated-accounts table tr:nth-of-type(1) td:nth-of-type(1)"
).innerHTML.includes("Facebook"),
"it lists facebook"
);
)
.includesHtml("Facebook", "lists facebook");
await click(
".pref-associated-accounts table tr:nth-of-type(1) td:last-child button"
);
assert.ok(
query(
".pref-associated-accounts table tr:nth-of-type(1) td:last-of-type"
).innerHTML.includes("Connect")
);
assert
.dom(".pref-associated-accounts table tr:nth-of-type(1) td:last-of-type")
.includesHtml("Connect");
});
test("avatars are selectable for staff user when `selectable_avatars_mode` site setting is set to `staff`", async function (assert) {

View File

@ -8,7 +8,6 @@ import {
import { test } from "qunit";
import {
acceptance,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
@ -74,10 +73,12 @@ acceptance("User Preferences - Second Factor", function (needs) {
.exists("displays second factor key");
await click(".add-totp");
assert.ok(
query(".alert-error").innerHTML.includes("provide a name and the code"),
"shows name/token missing error message"
);
assert
.dom(".alert-error")
.includesHtml(
"provide a name and the code",
"shows name/token missing error message"
);
});
test("second factor security keys", async function (assert) {
@ -93,10 +94,9 @@ acceptance("User Preferences - Second Factor", function (needs) {
if (typeof PublicKeyCredential !== "undefined") {
await click(".add-security-key");
assert.ok(
query(".alert-error").innerHTML.includes("provide a name"),
"shows name missing error message"
);
assert
.dom(".alert-error")
.includesHtml("provide a name", "shows name missing error message");
}
});

View File

@ -3,7 +3,6 @@ import { module, test } from "qunit";
import ComposerEditor from "discourse/components/composer-editor";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { query } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Component | ComposerEditor", function (hooks) {
setupRenderingTest(hooks);
@ -52,9 +51,6 @@ module("Integration | Component | ComposerEditor", function (hooks) {
</template>);
await fillIn(".d-editor-input", `"><svg onload="prompt(/xss/)"></svg>`);
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
'<p>"&gt;<svg></svg></p>'
);
assert.dom(".d-editor-preview").hasHtml('<p>"&gt;<svg></svg></p>');
});
});

View File

@ -4,7 +4,6 @@ import { resetCache } from "pretty-text/upload-short-url";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { query } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Component | cook-text", function (hooks) {
setupRenderingTest(hooks);
@ -16,8 +15,7 @@ module("Integration | Component | cook-text", function (hooks) {
test("renders markdown", async function (assert) {
await render(hbs`<CookText @rawText="_foo_" class="post-body" />`);
const html = query(".post-body").innerHTML.trim();
assert.strictEqual(html, "<p><em>foo</em></p>");
assert.dom(".post-body").hasHtml("<p><em>foo</em></p>");
});
test("resolves short URLs", async function (assert) {
@ -35,10 +33,8 @@ module("Integration | Component | cook-text", function (hooks) {
hbs`<CookText @rawText="![an image](upload://a.png)" class="post-body" />`
);
const html = query(".post-body").innerHTML.trim();
assert.strictEqual(
html,
'<p><img src="/images/avatar.png" alt="an image"></p>'
);
assert
.dom(".post-body")
.hasHtml('<p><img src="/images/avatar.png" alt="an image"></p>');
});
});

View File

@ -30,10 +30,9 @@ module("Integration | Component | d-editor", function (hooks) {
await fillIn(".d-editor-input", "hello **world**");
assert.strictEqual(this.value, "hello **world**");
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
"<p>hello <strong>world</strong></p>"
);
assert
.dom(".d-editor-preview")
.hasHtml("<p>hello <strong>world</strong></p>");
});
test("links in preview are not tabbable", async function (assert) {
@ -41,10 +40,11 @@ module("Integration | Component | d-editor", function (hooks) {
await fillIn(".d-editor-input", "[discourse](https://www.discourse.org)");
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
'<p><a href="https://www.discourse.org" tabindex="-1">discourse</a></p>'
);
assert
.dom(".d-editor-preview")
.hasHtml(
'<p><a href="https://www.discourse.org" tabindex="-1">discourse</a></p>'
);
});
test("updating the value refreshes the preview", async function (assert) {
@ -52,18 +52,12 @@ module("Integration | Component | d-editor", function (hooks) {
await render(hbs`<DEditor @value={{this.value}} />`);
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
"<p>evil trout</p>"
);
assert.dom(".d-editor-preview").hasHtml("<p>evil trout</p>");
this.set("value", "zogstrip");
await settled();
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
"<p>zogstrip</p>"
);
assert.dom(".d-editor-preview").hasHtml("<p>zogstrip</p>");
});
function jumpEnd(textarea) {

View File

@ -192,9 +192,9 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
this.setProperties(DEFAULT_CONTENT);
await render(TEMPLATE);
await toggle();
assert.strictEqual(rowById(4).innerHTML.trim(), "<span><b>baz</b></span>");
assert.dom(rowById(4)).hasHtml("<span><b>baz</b></span>");
});
test("separator", async function (assert) {

View File

@ -2,7 +2,6 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Helper | d-icon", function (hooks) {
setupRenderingTest(hooks);
@ -10,20 +9,20 @@ module("Integration | Helper | d-icon", function (hooks) {
test("default", async function (assert) {
await render(hbs`<div class="test">{{d-icon "bars"}}</div>`);
const html = query(".test").innerHTML.trim();
assert.strictEqual(
html,
'<svg class="fa d-icon d-icon-bars svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#bars"></use></svg>'
);
assert
.dom(".test")
.hasHtml(
'<svg class="fa d-icon d-icon-bars svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#bars"></use></svg>'
);
});
test("with replacement", async function (assert) {
await render(hbs`<div class="test">{{d-icon "d-watching"}}</div>`);
const html = query(".test").innerHTML.trim();
assert.strictEqual(
html,
'<svg class="fa d-icon d-icon-d-watching svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-bell-exclamation"></use></svg>'
);
assert
.dom(".test")
.hasHtml(
'<svg class="fa d-icon d-icon-d-watching svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-bell-exclamation"></use></svg>'
);
});
});

View File

@ -18,8 +18,7 @@ function generateClickEventOn(selector) {
function badgeClickCount(assert, id, expected) {
track(generateClickEventOn(`#${id}`));
const badge = fixture(`#${id}`).querySelector("span.badge");
assert.strictEqual(parseInt(badge.innerHTML, 10), expected);
assert.dom("span.badge", fixture(`#${id}`)).hasHtml(String(expected));
}
function testOpenInANewTab(description, clickEventModifier) {

View File

@ -250,16 +250,16 @@ module("Unit | Utility | formatter", function (hooks) {
assert.strictEqual(elem.dataset.format, "medium-with-ago");
assert.strictEqual(elem.dataset.time, d.getTime().toString());
assert.dom(elem).hasAttribute("title", longDate(d));
assert.strictEqual(elem.innerHTML, "1 day ago");
assert.dom(elem).hasHtml("1 day ago");
elem = domFromString(autoUpdatingRelativeAge(d, { format: "medium" }))[0];
assert.strictEqual(elem.dataset.format, "medium");
assert.strictEqual(elem.dataset.time, d.getTime().toString());
assert.dom(elem).doesNotHaveAttribute("title");
assert.strictEqual(elem.innerHTML, "1 day");
assert.dom(elem).hasHtml("1 day");
elem = domFromString(autoUpdatingRelativeAge(d, { prefix: "test" }))[0];
assert.strictEqual(elem.innerHTML, "test 1d");
assert.dom(elem).hasHtml("test 1d");
});
test("updateRelativeAge", function (assert) {
@ -269,7 +269,7 @@ module("Unit | Utility | formatter", function (hooks) {
updateRelativeAge(elem);
assert.strictEqual(elem.innerHTML, "2m");
assert.dom(elem).hasHtml("2m");
d = new Date();
elem = domFromString(
@ -279,7 +279,7 @@ module("Unit | Utility | formatter", function (hooks) {
updateRelativeAge(elem);
assert.strictEqual(elem.innerHTML, "2 mins ago");
assert.dom(elem).hasHtml("2 mins ago");
});
test("number", function (assert) {

View File

@ -44,9 +44,6 @@ module("Unit | Utility | link-mentions", function (hooks) {
root.querySelector("a[data-mentionable-user-count]").innerText,
"@mentionable_group"
);
assert.strictEqual(
root.querySelector("span.mention").innerHTML,
"@invalid"
);
assert.dom("span.mention", root).hasHtml("@invalid");
});
});

View File

@ -65,13 +65,13 @@ acceptance("Chat | Hashtag CSS Generator", function (needs) {
test("hashtag CSS classes are generated", async function (assert) {
await visit("/");
const cssTag = document.querySelector("style#hashtag-css-generator");
assert.equal(
cssTag.innerHTML,
".hashtag-category-badge { background-color: var(--primary-medium); }\n" +
".hashtag-color--category-1 { background-color: #ff0000; }\n" +
".hashtag-color--category-2 { background-color: #333; }\n" +
".hashtag-color--category-4 { background: linear-gradient(-90deg, #2B81AF 50%, #ff0000 50%); }"
);
assert
.dom("style#hashtag-css-generator", document.head)
.hasHtml(
".hashtag-category-badge { background-color: var(--primary-medium); }\n" +
".hashtag-color--category-1 { background-color: #ff0000; }\n" +
".hashtag-color--category-2 { background-color: #333; }\n" +
".hashtag-color--category-4 { background: linear-gradient(-90deg, #2B81AF 50%, #ff0000 50%); }"
);
});
});

View File

@ -53,11 +53,9 @@ module("Discourse Chat | Component | chat message collapser", function (hooks) {
this.set("uploads", [{ original_filename: evilString }]);
await render(hbs`<ChatMessageCollapser @uploads={{this.uploads}} />`);
assert.true(
query(".chat-message-collapser-link-small").innerHTML.includes(
evilStringEscaped
)
);
assert
.dom(".chat-message-collapser-link-small")
.includesHtml(evilStringEscaped);
});
});
@ -399,16 +397,14 @@ module(
);
await render(hbs`<ChatMessageCollapser @cooked={{this.cooked}} />`);
assert.true(
queryAll(".chat-message-collapser-link-small")[0].innerHTML.includes(
evilStringEscaped
)
);
assert.true(
queryAll(".chat-message-collapser-link-small")[1].innerHTML.includes(
"&lt;script&gt;someeviltitle&lt;/script&gt;"
)
);
const links = [
...document.querySelectorAll(".chat-message-collapser-link-small"),
];
assert.dom(links[0]).includesHtml(evilStringEscaped);
assert
.dom(links[1])
.includesHtml("&lt;script&gt;someeviltitle&lt;/script&gt;");
});
test("shows alt or links (if no alt) for linked image", async function (assert) {
@ -511,10 +507,7 @@ module(
assert
.dom(".chat-message-collapser-link-small")
.hasProperty("href", /%3Cscript%3Esomeeviltitle%3C\/script%3E$/);
assert.strictEqual(
query(".chat-message-collapser-link-small").innerHTML.trim(),
"someeviltitle"
);
assert.dom(".chat-message-collapser-link-small").hasHtml("someeviltitle");
});
test("removes album title overlay", async function (assert) {

View File

@ -4,7 +4,6 @@ import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import CoreFabricators from "discourse/lib/fabricators";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-message", function (hooks) {
@ -64,11 +63,9 @@ module("Discourse Chat | Component | chat-message", function (hooks) {
await this.message.cook();
await render(template);
assert.true(
query(".chat-message-text")
.innerHTML.trim()
.includes("<p>what <mark>test</mark></p>")
);
assert
.dom(".chat-message-text")
.includesHtml("<p>what <mark>test</mark></p>");
});
test("Message with reply", async function (assert) {

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module(
@ -20,11 +19,9 @@ module(
hbs`<Chat::Modal::ArchiveChannel @inline={{true}} @model={{hash channel=this.channel}} />`
);
assert.true(
query(".chat-modal-archive-channel").innerHTML.includes(
"&lt;script&gt;someeviltitle&lt;/script&gt;"
)
);
assert
.dom(".chat-modal-archive-channel")
.includesHtml("&lt;script&gt;someeviltitle&lt;/script&gt;");
});
}
);

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module(
@ -20,11 +19,9 @@ module(
hbs`<Chat::Modal::DeleteChannel @inline={{true}} @model={{hash channel=this.channel}} />`
);
assert.true(
query(".chat-modal-delete-channel__instructions").innerHTML.includes(
"&lt;script&gt;someeviltitle&lt;/script&gt;"
)
);
assert
.dom(".chat-modal-delete-channel__instructions")
.includesHtml("&lt;script&gt;someeviltitle&lt;/script&gt;");
});
}
);

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module(
@ -24,11 +23,9 @@ module(
/>
`);
assert.true(
query(".chat-modal-move-message-to-channel").innerHTML.includes(
"&lt;script&gt;someeviltitle&lt;/script&gt;"
)
);
assert
.dom(".chat-modal-move-message-to-channel")
.includesHtml("&lt;script&gt;someeviltitle&lt;/script&gt;");
});
}
);

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-thread-header", function (hooks) {
@ -17,10 +16,8 @@ module("Discourse Chat | Component | chat-thread-header", function (hooks) {
<Chat::Thread::Header @thread={{this.thread}} @channel={{this.thread.channel}} />
`);
assert.ok(
query(".c-navbar__title")
.innerHTML.trim()
.includes("&lt;style&gt;body { background: red;}&lt;/style&gt;")
);
assert
.dom(".c-navbar__title")
.includesHtml("&lt;style&gt;body { background: red;}&lt;/style&gt;");
});
});

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-thread-list-item", function (hooks) {
@ -17,9 +16,8 @@ module("Discourse Chat | Component | chat-thread-list-item", function (hooks) {
<Chat::ThreadList::Item @thread={{this.thread}} />
`);
assert.equal(
query(".chat-thread-list-item__title").innerHTML.trim(),
"&lt;style&gt;body { background: red;}&lt;/style&gt;"
);
assert
.dom(".chat-thread-list-item__title")
.hasHtml("&lt;style&gt;body { background: red;}&lt;/style&gt;");
});
});