2024-07-02 11:51:59 -04:00
|
|
|
import { click, visit } from "@ember/test-helpers";
|
2024-09-18 13:36:42 -04:00
|
|
|
import { skip, test } from "qunit";
|
2024-07-02 11:51:59 -04:00
|
|
|
import topicFixtures from "discourse/tests/fixtures/topic";
|
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
publishToMessageBus,
|
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import { cloneJSON } from "discourse-common/lib/object";
|
|
|
|
|
|
|
|
acceptance("Topic - Summary", function (needs) {
|
|
|
|
const currentUserId = 5;
|
|
|
|
|
|
|
|
needs.user();
|
|
|
|
needs.pretender((server, helper) => {
|
|
|
|
server.get("/t/1.json", () => {
|
|
|
|
const json = cloneJSON(topicFixtures["/t/130.json"]);
|
|
|
|
json.id = 1;
|
|
|
|
json.summarizable = true;
|
|
|
|
|
|
|
|
return helper.response(json);
|
|
|
|
});
|
|
|
|
|
|
|
|
server.get("/discourse-ai/summarization/t/1", () => {
|
|
|
|
return helper.response({});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
needs.hooks.beforeEach(() => {
|
|
|
|
updateCurrentUser({ id: currentUserId });
|
|
|
|
});
|
|
|
|
|
2024-08-29 18:07:07 -04:00
|
|
|
skip("displays streamed summary", async function (assert) {
|
2024-07-02 11:51:59 -04:00
|
|
|
await visit("/t/-/1");
|
|
|
|
|
|
|
|
const partialSummary = "This a";
|
|
|
|
await publishToMessageBus("/discourse-ai/summaries/topic/1", {
|
|
|
|
done: false,
|
|
|
|
ai_topic_summary: { summarized_text: partialSummary },
|
|
|
|
});
|
|
|
|
|
|
|
|
await click(".ai-topic-summarization");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".ai-summary-box .generated-summary p")
|
|
|
|
.hasText(partialSummary, "Updates the summary with a partial result");
|
|
|
|
|
|
|
|
const finalSummary = "This is a completed summary";
|
|
|
|
await publishToMessageBus("/discourse-ai/summaries/topic/1", {
|
|
|
|
done: true,
|
|
|
|
ai_topic_summary: {
|
|
|
|
summarized_text: finalSummary,
|
|
|
|
summarized_on: "2023-01-01T04:00:00.000Z",
|
|
|
|
algorithm: "OpenAI GPT-4",
|
|
|
|
outdated: false,
|
|
|
|
new_posts_since_summary: false,
|
|
|
|
can_regenerate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".ai-summary-box .generated-summary p")
|
|
|
|
.hasText(finalSummary, "Updates the summary with a final result");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".ai-summary-box .summarized-on")
|
|
|
|
.exists("summary metadata exists");
|
|
|
|
});
|
2024-08-20 09:57:23 -04:00
|
|
|
|
2024-08-29 18:07:07 -04:00
|
|
|
skip("clicking summary links", async function (assert) {
|
2024-08-20 09:57:23 -04:00
|
|
|
await visit("/t/-/1");
|
|
|
|
|
|
|
|
const partialSummary = "In this post,";
|
|
|
|
await publishToMessageBus("/discourse-ai/summaries/topic/1", {
|
|
|
|
done: false,
|
|
|
|
ai_topic_summary: { summarized_text: partialSummary },
|
|
|
|
});
|
|
|
|
|
|
|
|
await click(".ai-topic-summarization");
|
|
|
|
const finalSummaryCooked =
|
|
|
|
"In this post, <a href='/t/-/1/1'>bianca</a> said some stuff.";
|
|
|
|
const finalSummaryResult = "In this post, bianca said some stuff.";
|
|
|
|
await publishToMessageBus("/discourse-ai/summaries/topic/1", {
|
|
|
|
done: true,
|
|
|
|
ai_topic_summary: {
|
|
|
|
summarized_text: finalSummaryCooked,
|
|
|
|
summarized_on: "2023-01-01T04:00:00.000Z",
|
|
|
|
algorithm: "OpenAI GPT-4",
|
|
|
|
outdated: false,
|
|
|
|
new_posts_since_summary: false,
|
|
|
|
can_regenerate: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await click(".generated-summary a");
|
|
|
|
assert
|
|
|
|
.dom(".ai-summary-box .generated-summary p")
|
|
|
|
.hasText(finalSummaryResult, "Retains final summary after clicking link");
|
|
|
|
});
|
2024-07-02 11:51:59 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
acceptance("Topic - Summary - Anon", function (needs) {
|
|
|
|
const finalSummary = "This is a completed summary";
|
|
|
|
|
|
|
|
needs.pretender((server, helper) => {
|
|
|
|
server.get("/t/1.json", () => {
|
|
|
|
const json = cloneJSON(topicFixtures["/t/280/1.json"]);
|
|
|
|
json.id = 1;
|
|
|
|
json.summarizable = true;
|
|
|
|
|
|
|
|
return helper.response(json);
|
|
|
|
});
|
|
|
|
|
|
|
|
server.get("/discourse-ai/summarization/t/1", () => {
|
|
|
|
return helper.response({
|
|
|
|
ai_topic_summary: {
|
|
|
|
summarized_text: finalSummary,
|
|
|
|
summarized_on: "2023-01-01T04:00:00.000Z",
|
|
|
|
algorithm: "OpenAI GPT-4",
|
|
|
|
outdated: false,
|
|
|
|
new_posts_since_summary: false,
|
|
|
|
can_regenerate: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-09-18 13:36:42 -04:00
|
|
|
test("displays cached summary immediately", async function (assert) {
|
2024-07-02 11:51:59 -04:00
|
|
|
await visit("/t/-/1");
|
|
|
|
|
|
|
|
await click(".ai-topic-summarization");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".ai-summary-box .generated-summary p")
|
|
|
|
.hasText(finalSummary, "Updates the summary with the result");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".ai-summary-box .summarized-on")
|
|
|
|
.exists("summary metadata exists");
|
|
|
|
});
|
2024-09-18 13:36:42 -04:00
|
|
|
|
|
|
|
test("clicking outside of summary should not close the summary box", async function (assert) {
|
|
|
|
await visit("/t/-/1");
|
|
|
|
await click(".ai-topic-summarization");
|
|
|
|
await click("#main-outlet-wrapper");
|
|
|
|
assert.dom(".ai-summary-box").exists();
|
|
|
|
});
|
2024-07-02 11:51:59 -04:00
|
|
|
});
|