2023-10-11 02:38:59 +08:00
|
|
|
import { click, render } from "@ember/test-helpers";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from 'discourse-i18n';
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-composer-upload", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("file - uploading in progress", async function (assert) {
|
|
|
|
this.set("upload", {
|
|
|
|
progress: 50,
|
|
|
|
extension: ".pdf",
|
|
|
|
fileName: "test.pdf",
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<ChatComposerUpload @upload={{this.upload}} />`);
|
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom(".upload-progress[value='50']").exists();
|
2024-11-20 04:45:18 +08:00
|
|
|
assert.dom(".uploading").hasText(i18n("uploading"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("image - uploading in progress", async function (assert) {
|
|
|
|
this.set("upload", {
|
|
|
|
extension: ".png",
|
|
|
|
progress: 78,
|
|
|
|
fileName: "test.png",
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<ChatComposerUpload @upload={{this.upload}} />`);
|
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom(".d-icon-far-image").exists();
|
|
|
|
assert.dom(".upload-progress[value='78']").exists();
|
2024-11-20 04:45:18 +08:00
|
|
|
assert.dom(".uploading").hasText(i18n("uploading"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("image - preprocessing upload in progress", async function (assert) {
|
|
|
|
this.set("upload", {
|
|
|
|
extension: ".png",
|
|
|
|
progress: 78,
|
|
|
|
fileName: "test.png",
|
|
|
|
processing: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<ChatComposerUpload @upload={{this.upload}} />`);
|
|
|
|
|
2024-11-20 04:45:18 +08:00
|
|
|
assert.dom(".processing").hasText(i18n("processing"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("file - upload complete", async function (assert) {
|
|
|
|
this.set("upload", {
|
|
|
|
type: ".pdf",
|
|
|
|
original_filename: "some file.pdf",
|
|
|
|
extension: "pdf",
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} />`
|
|
|
|
);
|
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom(".d-icon-file-lines").exists();
|
2024-10-15 23:11:20 +08:00
|
|
|
assert.dom(".file-name").hasText("some file.pdf");
|
|
|
|
assert.dom(".extension-pill").hasText("pdf");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("image - upload complete", async function (assert) {
|
|
|
|
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}} />`
|
|
|
|
);
|
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom("img.preview-img[src='/images/avatar.png']").exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
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",
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} @onCancel={{fn this.removeUpload this.upload}} />`
|
|
|
|
);
|
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
await click(".chat-composer-upload__remove-btn");
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(this.uploadRemoved, true);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
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",
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<ChatComposerUpload @upload={{this.upload}} @onCancel={{fn this.removeUpload this.upload}} />`
|
|
|
|
);
|
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
await click(".chat-composer-upload__remove-btn");
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(this.uploadRemoved, true);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
});
|