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,158 +1,132 @@
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 I18n from "I18n";
import { click } from "@ember/test-helpers";
import { module } from "qunit";
import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
module("Discourse Chat | Component | chat-composer-upload", function (hooks) {
setupRenderingTest(hooks);
componentTest("file - uploading in progress", {
template: hbs`{{chat-composer-upload upload=upload}}`,
test("file - uploading in progress", async function (assert) {
this.set("upload", {
progress: 50,
extension: ".pdf",
fileName: "test.pdf",
});
beforeEach() {
this.set("upload", {
progress: 50,
extension: ".pdf",
fileName: "test.pdf",
});
},
await render(hbs`<ChatComposerUpload @upload={{this.upload}} />`);
async test(assert) {
assert.ok(exists(".upload-progress[value=50]"));
assert.strictEqual(
query(".uploading").innerText.trim(),
I18n.t("uploading")
);
},
assert.true(exists(".upload-progress[value=50]"));
assert.strictEqual(
query(".uploading").innerText.trim(),
I18n.t("uploading")
);
});
componentTest("image - uploading in progress", {
template: hbs`{{chat-composer-upload upload=upload}}`,
test("image - uploading in progress", async function (assert) {
this.set("upload", {
extension: ".png",
progress: 78,
fileName: "test.png",
});
beforeEach() {
this.set("upload", {
extension: ".png",
progress: 78,
fileName: "test.png",
});
},
await render(hbs`<ChatComposerUpload @upload={{this.upload}} />`);
async test(assert) {
assert.ok(exists(".d-icon-far-image"));
assert.ok(exists(".upload-progress[value=78]"));
assert.strictEqual(
query(".uploading").innerText.trim(),
I18n.t("uploading")
);
},
assert.true(exists(".d-icon-far-image"));
assert.true(exists(".upload-progress[value=78]"));
assert.strictEqual(
query(".uploading").innerText.trim(),
I18n.t("uploading")
);
});
componentTest("image - preprocessing upload in progress", {
template: hbs`{{chat-composer-upload upload=upload}}`,
test("image - preprocessing upload in progress", async function (assert) {
this.set("upload", {
extension: ".png",
progress: 78,
fileName: "test.png",
processing: true,
});
beforeEach() {
this.set("upload", {
extension: ".png",
progress: 78,
fileName: "test.png",
processing: true,
});
},
await render(hbs`<ChatComposerUpload @upload={{this.upload}} />`);
async test(assert) {
assert.strictEqual(
query(".processing").innerText.trim(),
I18n.t("processing")
);
},
assert.strictEqual(
query(".processing").innerText.trim(),
I18n.t("processing")
);
});
componentTest("file - upload complete", {
template: hbs`{{chat-composer-upload isDone=true upload=upload}}`,
test("file - upload complete", async function (assert) {
this.set("upload", {
type: ".pdf",
original_filename: "some file.pdf",
extension: "pdf",
});
beforeEach() {
this.set("upload", {
type: ".pdf",
original_filename: "some file.pdf",
extension: "pdf",
});
},
await render(
hbs`<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} />`
);
async test(assert) {
assert.ok(exists(".d-icon-file-alt"));
assert.strictEqual(query(".file-name").innerText.trim(), "some file.pdf");
assert.strictEqual(query(".extension-pill").innerText.trim(), "pdf");
},
assert.true(exists(".d-icon-file-alt"));
assert.strictEqual(query(".file-name").innerText.trim(), "some file.pdf");
assert.strictEqual(query(".extension-pill").innerText.trim(), "pdf");
});
componentTest("image - upload complete", {
template: hbs`{{chat-composer-upload isDone=true upload=upload}}`,
test("image - upload complete", async function (assert) {
this.set("upload", {
type: ".png",
original_filename: "bar_image.png",
extension: "png",
short_path: "/images/avatar.png",
});
beforeEach() {
this.set("upload", {
type: ".png",
original_filename: "bar_image.png",
extension: "png",
short_path: "/images/avatar.png",
});
},
await render(
hbs`<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} />`
);
async test(assert) {
assert.ok(exists("img.preview-img[src='/images/avatar.png']"));
assert.strictEqual(query(".file-name").innerText.trim(), "bar_image.png");
assert.strictEqual(query(".extension-pill").innerText.trim(), "png");
},
assert.true(exists("img.preview-img[src='/images/avatar.png']"));
assert.strictEqual(query(".file-name").innerText.trim(), "bar_image.png");
assert.strictEqual(query(".extension-pill").innerText.trim(), "png");
});
componentTest("removing completed upload", {
template: hbs`{{chat-composer-upload isDone=true upload=upload onCancel=(action "removeUpload" upload)}}`,
test("removing completed upload", async function (assert) {
this.set("uploadRemoved", false);
this.set("removeUpload", () => {
this.set("uploadRemoved", true);
});
this.set("upload", {
type: ".png",
original_filename: "bar_image.png",
extension: "png",
short_path: "/images/avatar.png",
});
beforeEach() {
this.set("uploadRemoved", false);
this.set("actions", {
removeUpload: () => {
this.set("uploadRemoved", true);
},
});
this.set("upload", {
type: ".png",
original_filename: "bar_image.png",
extension: "png",
short_path: "/images/avatar.png",
});
},
await render(
hbs`<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} @onCancel={{fn this.removeUpload this.upload}} />`
);
async test(assert) {
await click(".remove-upload");
assert.strictEqual(this.uploadRemoved, true);
},
await click(".remove-upload");
assert.strictEqual(this.uploadRemoved, true);
});
componentTest("cancelling in progress upload", {
template: hbs`{{chat-composer-upload upload=upload onCancel=(action "removeUpload" upload)}}`,
test("cancelling in progress upload", async function (assert) {
this.set("uploadRemoved", false);
this.set("removeUpload", () => {
this.set("uploadRemoved", true);
});
this.set("upload", {
type: ".png",
original_filename: "bar_image.png",
extension: "png",
short_path: "/images/avatar.png",
});
beforeEach() {
this.set("uploadRemoved", false);
this.set("actions", {
removeUpload: () => {
this.set("uploadRemoved", true);
},
});
this.set("upload", {
type: ".png",
original_filename: "bar_image.png",
extension: "png",
short_path: "/images/avatar.png",
});
},
await render(
hbs`<ChatComposerUpload @upload={{this.upload}} @onCancel={{fn this.removeUpload this.upload}} />`
);
async test(assert) {
await click(".remove-upload");
assert.strictEqual(this.uploadRemoved, true);
},
await click(".remove-upload");
assert.strictEqual(this.uploadRemoved, true);
});
});