discourse/plugins/discourse-ai/test/javascripts/integration/components/ai-admin-dashboard-highlight-test.gjs
Natalie Tay 035ce20c43
FEATURE: AI highlights for new dashboard (#40740)
Adds an AI feature, agent, to discourse-ai.

This feature is meant to be used on the new admin dashboard, but is
owned by the discourse-ai plugin. The PR includes an outlet for
discourse-ai to hook up to.

The agent introduced will take crafted data in for now to formulate the
headline and we will adjust this accordingly.

Note, we're not doing any streaming here for now. The results are cached
for 6h and per locale.

The AI feature is "hidden" for now
2026-06-10 23:00:35 +08:00

75 lines
2.2 KiB
Text
Vendored

import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender from "discourse/tests/helpers/create-pretender";
import AiAdminDashboardHighlight from "discourse/plugins/discourse-ai/discourse/connectors/admin-dashboard-highlights-before-kpis/ai-admin-dashboard-highlight";
const OUTLET_ARGS = {
period: "last_30_days",
startDate: "2026-05-01",
endDate: "2026-06-01",
kpis: [],
};
module("Integration | Component | AiAdminDashboardHighlight", function (hooks) {
setupRenderingTest(hooks);
test("renders the highlight returned by the endpoint", async function (assert) {
pretender.get(
"/admin/plugins/discourse-ai/admin-dashboard-highlights.json",
() => [
200,
{ "Content-Type": "application/json" },
{ highlight: "Your community grew to 1,100 new members." },
]
);
await render(
<template>
<AiAdminDashboardHighlight @outletArgs={{OUTLET_ARGS}} />
</template>
);
assert
.dom(".ai-admin-dashboard-highlight__text")
.hasText(
"Your community grew to 1,100 new members.",
"it renders the returned highlight"
);
assert
.dom(".ai-admin-dashboard-highlight")
.hasAttribute("aria-live", "polite", "it announces the loaded highlight");
});
test("renders nothing when the endpoint fails", async function (assert) {
pretender.get(
"/admin/plugins/discourse-ai/admin-dashboard-highlights.json",
() => [500, { "Content-Type": "application/json" }, {}]
);
await render(
<template>
<AiAdminDashboardHighlight @outletArgs={{OUTLET_ARGS}} />
</template>
);
assert
.dom(".ai-admin-dashboard-highlight")
.doesNotExist("it hides the highlight region after a failed request");
});
test("shouldRender follows the admin dashboard AI setting", function (assert) {
assert.true(
AiAdminDashboardHighlight.shouldRender(
{},
{ siteSettings: { ai_admin_dashboard_enabled: true } }
)
);
assert.false(
AiAdminDashboardHighlight.shouldRender(
{},
{ siteSettings: { ai_admin_dashboard_enabled: false } }
)
);
});
});