diff --git a/assets/javascripts/discourse/connectors/topic-map-expanded-after/ai-summary-box.gjs b/assets/javascripts/discourse/connectors/topic-map-expanded-after/ai-summary-box.gjs index 7a27cf4b..9052c4b2 100644 --- a/assets/javascripts/discourse/connectors/topic-map-expanded-after/ai-summary-box.gjs +++ b/assets/javascripts/discourse/connectors/topic-map-expanded-after/ai-summary-box.gjs @@ -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); } diff --git a/lib/summarization/fold_content.rb b/lib/summarization/fold_content.rb index 7b68ee88..6f334447 100644 --- a/lib/summarization/fold_content.rb +++ b/lib/summarization/fold_content.rb @@ -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) diff --git a/spec/system/page_objects/components/ai_summary_box.rb b/spec/system/page_objects/components/ai_summary_box.rb new file mode 100644 index 00000000..c31e1742 --- /dev/null +++ b/spec/system/page_objects/components/ai_summary_box.rb @@ -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 diff --git a/spec/system/summarization/topic_summarization_spec.rb b/spec/system/summarization/topic_summarization_spec.rb index fabe2dfa..f9ef67b4 100644 --- a/spec/system/summarization/topic_summarization_spec.rb +++ b/spec/system/summarization/topic_summarization_spec.rb @@ -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