DEV: Modernize chat's component tests (#19577)

1. `test()` and `render()` instead of `componentTest()`
2. Angle brackets
3. `strictEqual()`/`true()`/`false()` assertions

This removes all remaining uses of `componentTest` from core
This commit is contained in:
Jarek Radosz
2022-12-22 14:35:18 +01:00
committed by GitHub
parent 8546c2084a
commit dc3473fe06
34 changed files with 1397 additions and 1762 deletions

View File

@ -1,10 +1,8 @@
import componentTest, {
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 hbs from "htmlbars-inline-precompile";
import { module } from "qunit";
import { settled } from "@ember/test-helpers";
import { module, test } from "qunit";
import { render, settled } from "@ember/test-helpers";
const IMAGE_FIXTURE = {
id: 290,
@ -54,65 +52,53 @@ const TXT_FIXTURE = {
module("Discourse Chat | Component | chat-upload", function (hooks) {
setupRenderingTest(hooks);
componentTest("with an image", {
template: hbs`{{chat-upload upload=upload}}`,
test("with an image", async function (assert) {
this.set("upload", IMAGE_FIXTURE);
beforeEach() {
this.set("upload", IMAGE_FIXTURE);
},
await render(hbs`<ChatUpload @upload={{this.upload}} />`);
async test(assert) {
assert.true(exists("img.chat-img-upload"), "displays as an image");
const image = query("img.chat-img-upload");
assert.strictEqual(image.loading, "lazy", "is lazy loading");
assert.true(exists("img.chat-img-upload"), "displays as an image");
const image = query("img.chat-img-upload");
assert.strictEqual(image.loading, "lazy", "is lazy loading");
assert.strictEqual(
image.style.backgroundColor,
"rgb(120, 131, 112)",
"sets background to dominant color"
);
assert.strictEqual(
image.style.backgroundColor,
"rgb(120, 131, 112)",
"sets background to dominant color"
);
image.dispatchEvent(new Event("load")); // Fake that the image has loaded
await settled();
image.dispatchEvent(new Event("load")); // Fake that the image has loaded
await settled();
assert.strictEqual(
image.style.backgroundColor,
"",
"removes the background color once the image has loaded"
);
},
assert.strictEqual(
image.style.backgroundColor,
"",
"removes the background color once the image has loaded"
);
});
componentTest("with a video", {
template: hbs`{{chat-upload upload=upload}}`,
test("with a video", async function (assert) {
this.set("upload", VIDEO_FIXTURE);
beforeEach() {
this.set("upload", VIDEO_FIXTURE);
},
await render(hbs`<ChatUpload @upload={{this.upload}} />`);
async test(assert) {
assert.true(exists("video.chat-video-upload"), "displays as an video");
const video = query("video.chat-video-upload");
assert.ok(video.hasAttribute("controls"), "has video controls");
assert.strictEqual(
video.getAttribute("preload"),
"metadata",
"video has correct preload settings"
);
},
assert.true(exists("video.chat-video-upload"), "displays as an video");
const video = query("video.chat-video-upload");
assert.true(video.hasAttribute("controls"), "has video controls");
assert.strictEqual(
video.getAttribute("preload"),
"metadata",
"video has correct preload settings"
);
});
componentTest("non image upload", {
template: hbs`{{chat-upload upload=upload}}`,
test("non image upload", async function (assert) {
this.set("upload", TXT_FIXTURE);
beforeEach() {
this.set("upload", TXT_FIXTURE);
},
await render(hbs`<ChatUpload @upload={{this.upload}} />`);
async test(assert) {
assert.true(exists("a.chat-other-upload"), "displays as a link");
const link = query("a.chat-other-upload");
assert.strictEqual(link.href, TXT_FIXTURE.url, "has the correct URL");
},
assert.true(exists("a.chat-other-upload"), "displays as a link");
const link = query("a.chat-other-upload");
assert.strictEqual(link.href, TXT_FIXTURE.url, "has the correct URL");
});
});