FIX: Regenerate summary button still shows cached summary (#903)

This PR fixes an issue where clicking to regenerate a summary was still showing the cached summary. To resolve this we call resetSummary() to reset all the summarization related properties before creating a new request.
This commit is contained in:
Keegan George 2024-11-08 09:01:18 +09:00 committed by GitHub
parent fbc74c7467
commit 644141ff08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 3 deletions

View File

@ -123,6 +123,8 @@ export default class AiSummaryBox extends Component {
}
}
// ensure summary is reset before requesting a new one:
this.resetSummary();
return this._requestSummary(fetchURL);
}

View File

@ -48,7 +48,7 @@ module DiscourseAi
# @returns { AiSummary } - Resulting summary.
#
# Finds a summary matching the target and strategy. Marks it as outdates if the strategy found newer content
# Finds a summary matching the target and strategy. Marks it as outdated if the strategy found newer content
def existing_summary
if !defined?(@existing_summary)
summary = AiSummary.find_by(target: strategy.target, summary_type: strategy.type)

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
module PageObjects
module Components
class AiSummaryBox < PageObjects::Components::Base
SUMMARY_BUTTON_SELECTOR = ".ai-summarization-button button"
SUMMARY_CONTAINER_SELECTOR = ".ai-summary-container"
def click_summarize
find(SUMMARY_BUTTON_SELECTOR).click
end
def click_regenerate_summary
find("#{SUMMARY_CONTAINER_SELECTOR} .outdated-summary button").click
end
def has_summary?(summary)
find("#{SUMMARY_CONTAINER_SELECTOR} .generated-summary p").text == summary
end
def has_generating_summary_indicator?
find("#{SUMMARY_CONTAINER_SELECTOR} .ai-summary__generating-text").present?
end
end
end
end

View File

@ -14,6 +14,7 @@ RSpec.describe "Summarize a topic ", type: :system do
end
let(:summarization_result) { "This is a summary" }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:summary_box) { PageObjects::Components::AiSummaryBox.new }
before do
group.add(current_user)
@ -38,10 +39,35 @@ RSpec.describe "Summarize a topic ", type: :system do
it "displays it" do
topic_page.visit_topic(topic)
summary_box.click_summarize
expect(summary_box).to have_summary(summarization_result)
end
end
find(".ai-summarization-button button").click
context "when a summary is outdated" do
before do
AiSummary.create!(
target: topic,
summarized_text: summarization_result,
algorithm: "test",
original_content_sha: "test",
summary_type: AiSummary.summary_types[:complete],
)
end
fab!(:new_post) do
Fabricate(
:post,
topic: topic,
raw:
"Idk, I think pie is overrated. I prefer cake. Cake is the best dessert. I always eat cake. I never throw it at people.",
)
end
expect(find(".generated-summary p").text).to eq(summarization_result)
it "displays the new summary instead of a cached one" do
topic_page.visit_topic(topic)
summary_box.click_summarize
summary_box.click_regenerate_summary
expect(summary_box).to have_generating_summary_indicator
end
end
end