mirror of
https://github.com/discourse/discourse.git
synced 2026-08-14 13:58:53 +08:00
Currently, most of the JS test modules follow this
convention:
```
module("Integration | Component | topic-dismiss-buttons"
```
Which is a legacy from when ember components etc were
rendered in templates like this:
```
{{d-button title="foo"}}
```
Instead, this commit updates all of them to follow this
PascalCase convention:
```
module("Integration | Component | TopicDismissButtons", function (hooks) {
```
No linting is added to enforce this, we suspect that it's
mostly a result of cargo culting, and people will add new
tests following PascalCase convention.
Also adds an initial AI skill for writing JS tests.
170 lines
4.5 KiB
Text
Vendored
170 lines
4.5 KiB
Text
Vendored
import { fn } from "@ember/helper";
|
|
import { click, render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { restoreBaseUri, setupURL } from "discourse/lib/get-url";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { i18n } from "discourse-i18n";
|
|
import ChatComposerUpload from "discourse/plugins/chat/discourse/components/chat-composer-upload";
|
|
|
|
module("Component | ChatComposerUpload", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("file - uploading in progress", async function (assert) {
|
|
this.set("upload", {
|
|
progress: 50,
|
|
extension: ".pdf",
|
|
fileName: "test.pdf",
|
|
});
|
|
|
|
await render(
|
|
<template><ChatComposerUpload @upload={{this.upload}} /></template>
|
|
);
|
|
|
|
assert.dom(".upload-progress[value='50']").exists();
|
|
assert.dom(".uploading").hasText(i18n("uploading"));
|
|
});
|
|
|
|
test("image - uploading in progress", async function (assert) {
|
|
this.set("upload", {
|
|
extension: ".png",
|
|
progress: 78,
|
|
fileName: "test.png",
|
|
});
|
|
|
|
await render(
|
|
<template><ChatComposerUpload @upload={{this.upload}} /></template>
|
|
);
|
|
|
|
assert.dom(".d-icon-far-image").exists();
|
|
assert.dom(".upload-progress[value='78']").exists();
|
|
assert.dom(".uploading").hasText(i18n("uploading"));
|
|
});
|
|
|
|
test("image - preprocessing upload in progress", async function (assert) {
|
|
this.set("upload", {
|
|
extension: ".png",
|
|
progress: 78,
|
|
fileName: "test.png",
|
|
processing: true,
|
|
});
|
|
|
|
await render(
|
|
<template><ChatComposerUpload @upload={{this.upload}} /></template>
|
|
);
|
|
|
|
assert.dom(".processing").hasText(i18n("processing"));
|
|
});
|
|
|
|
test("file - upload complete", async function (assert) {
|
|
this.set("upload", {
|
|
type: ".pdf",
|
|
original_filename: "some file.pdf",
|
|
extension: "pdf",
|
|
});
|
|
|
|
await render(
|
|
<template>
|
|
<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} />
|
|
</template>
|
|
);
|
|
|
|
assert.dom(".d-icon-file-lines").exists();
|
|
assert.dom(".file-name").hasText("some file.pdf");
|
|
assert.dom(".extension-pill").hasText("pdf");
|
|
});
|
|
|
|
test("image - upload complete", async function (assert) {
|
|
this.set("upload", {
|
|
type: ".png",
|
|
original_filename: "bar_image.png",
|
|
extension: "png",
|
|
url: "/images/avatar.png",
|
|
});
|
|
|
|
await render(
|
|
<template>
|
|
<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} />
|
|
</template>
|
|
);
|
|
|
|
assert.dom("img.preview-img[src='/images/avatar.png']").exists();
|
|
});
|
|
|
|
test("image - upload complete uses CDN in preview", async function (assert) {
|
|
try {
|
|
setupURL("//cdn.example.com", "http://test.local", "", {
|
|
snapshot: true,
|
|
});
|
|
|
|
this.set("upload", {
|
|
type: ".png",
|
|
original_filename: "bar_image.png",
|
|
extension: "png",
|
|
url: "/images/avatar.png",
|
|
});
|
|
|
|
await render(
|
|
<template>
|
|
<ChatComposerUpload @isDone={{true}} @upload={{this.upload}} />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom("img.preview-img")
|
|
.hasAttribute("src", "//cdn.example.com/images/avatar.png");
|
|
} finally {
|
|
restoreBaseUri();
|
|
}
|
|
});
|
|
|
|
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(
|
|
<template>
|
|
<ChatComposerUpload
|
|
@isDone={{true}}
|
|
@upload={{this.upload}}
|
|
@onCancel={{fn this.removeUpload this.upload}}
|
|
/>
|
|
</template>
|
|
);
|
|
|
|
await click(".chat-composer-upload__remove-btn");
|
|
assert.true(this.uploadRemoved);
|
|
});
|
|
|
|
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(
|
|
<template>
|
|
<ChatComposerUpload
|
|
@upload={{this.upload}}
|
|
@onCancel={{fn this.removeUpload this.upload}}
|
|
/>
|
|
</template>
|
|
);
|
|
|
|
await click(".chat-composer-upload__remove-btn");
|
|
assert.true(this.uploadRemoved);
|
|
});
|
|
});
|