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:
parent
fbc74c7467
commit
644141ff08
|
@ -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);
|
return this._requestSummary(fetchURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ module DiscourseAi
|
||||||
|
|
||||||
# @returns { AiSummary } - Resulting summary.
|
# @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
|
def existing_summary
|
||||||
if !defined?(@existing_summary)
|
if !defined?(@existing_summary)
|
||||||
summary = AiSummary.find_by(target: strategy.target, summary_type: strategy.type)
|
summary = AiSummary.find_by(target: strategy.target, summary_type: strategy.type)
|
||||||
|
|
|
@ -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
|
|
@ -14,6 +14,7 @@ RSpec.describe "Summarize a topic ", type: :system do
|
||||||
end
|
end
|
||||||
let(:summarization_result) { "This is a summary" }
|
let(:summarization_result) { "This is a summary" }
|
||||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||||
|
let(:summary_box) { PageObjects::Components::AiSummaryBox.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
group.add(current_user)
|
group.add(current_user)
|
||||||
|
@ -38,10 +39,35 @@ RSpec.describe "Summarize a topic ", type: :system do
|
||||||
|
|
||||||
it "displays it" do
|
it "displays it" do
|
||||||
topic_page.visit_topic(topic)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue