mirror of
https://github.com/discourse/discourse.git
synced 2026-08-10 23:00:09 +08:00
Follow up to https://github.com/discourse/discourse/pull/41586 1. **Bulk of the PR diff** -- there's a mix of usages for "description" and "caption", we'll stick to V1 terminology and keep "AI caption" instead of bringing in "description". 2. Move image caption out of AI helper, into its own dedicated "AI Feature" for consolidated settings 3. Update default values for the existing image caption agent - vision_enabled was default off, now on - update description 4. Validations and problem checks - via Site Setting validation - agent / llm - when enabling the feature - or when selecting invalid agent - inform admin when they've enabled the setting but the agent is misconfigured via ProblemCheck
78 lines
2.2 KiB
Text
Vendored
78 lines
2.2 KiB
Text
Vendored
import Service from "@ember/service";
|
|
import { click, render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import AiPostImageCaptionEditorButton from "discourse/plugins/discourse-ai/discourse/components/ai-post-image-caption-editor-button";
|
|
|
|
class PostImageCaptionEditorStub extends Service {
|
|
openedBase62Sha1 = null;
|
|
|
|
captionFor(base62Sha1) {
|
|
if (base62Sha1 === "abc123") {
|
|
return "A stored description";
|
|
}
|
|
}
|
|
}
|
|
|
|
class ModalStub extends Service {
|
|
show(_modal, options) {
|
|
this.model = options.model;
|
|
}
|
|
}
|
|
|
|
module(
|
|
"Integration | Component | AiPostImageCaptionEditorButton",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.owner.unregister("service:post-image-caption-editor");
|
|
this.owner.unregister("service:modal");
|
|
this.owner.register(
|
|
"service:post-image-caption-editor",
|
|
PostImageCaptionEditorStub
|
|
);
|
|
this.owner.register("service:modal", ModalStub);
|
|
});
|
|
|
|
test("renders when the image has an editable description", async function (assert) {
|
|
await render(
|
|
<template>
|
|
<AiPostImageCaptionEditorButton @base62Sha1="abc123" />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".ai-post-image-caption-editor__button")
|
|
.exists("the edit button is shown");
|
|
});
|
|
|
|
test("opens the editor modal for the image", async function (assert) {
|
|
await render(
|
|
<template>
|
|
<AiPostImageCaptionEditorButton @base62Sha1="abc123" />
|
|
</template>
|
|
);
|
|
|
|
await click(".ai-post-image-caption-editor__button");
|
|
|
|
const modal = this.owner.lookup("service:modal");
|
|
assert.deepEqual(modal.model, {
|
|
base62Sha1: "abc123",
|
|
description: "A stored description",
|
|
});
|
|
});
|
|
|
|
test("does not render without an editable description", async function (assert) {
|
|
await render(
|
|
<template>
|
|
<AiPostImageCaptionEditorButton @base62Sha1="missing" />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".ai-post-image-caption-editor__button")
|
|
.doesNotExist("the edit button is hidden");
|
|
});
|
|
}
|
|
);
|