Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/summarization/fold_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def summarize(user, &on_partial_blk)

# @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)
Expand Down
26 changes: 26 additions & 0 deletions spec/system/page_objects/components/ai_summary_box.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 28 additions & 2 deletions spec/system/summarization/topic_summarization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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)
Expand All @@ -38,10 +39,35 @@

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.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

)
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