Sam 3800728d52
FIX: clear uploads after successfully posting new PM (#1307)
This PR addresses a bug where uploads weren't being cleared after successfully posting a new private message in the AI bot conversations interface. Here's what the changes do:

## Main Fix:
- Makes the `prepareAndSubmitToBot()` method async and adds proper error handling
- Adds `this.uploads.clear()` after successful submission to clear all uploads
- Adds a test to verify that the "New Question" button properly resets the UI with no uploads

## Additional Improvements:
1. **Dynamic Character Length Validation**:
   - Uses `siteSettings.min_personal_message_post_length` instead of hardcoded 10 characters
   - Updates the error message to show the dynamic character count
   - Adds proper pluralization in the localization file for the error message

2. **Bug Fixes**:
   - Adds null checks with optional chaining (`link?.topic?.id`) in the sidebar code to prevent potential errors

3. **Code Organization**:
   - Moves error handling from the service to the controller for better separation of concerns
2025-05-02 13:46:22 +10:00

83 lines
2.1 KiB
Ruby

# frozen_string_literal: true
module PageObjects
module Components
class AiPmHomepage < PageObjects::Components::Base
HOMEPAGE_WRAPPER_CLASS = ".ai-bot-conversations__content-wrapper"
def visit
page.visit("/discourse-ai/ai-bot/conversations")
end
def input
page.find("#ai-bot-conversations-input")
end
def submit
page.find(".ai-conversation-submit").click
end
def has_too_short_dialog?
page.find(
".dialog-content",
text:
I18n.t(
"js.discourse_ai.ai_bot.conversations.min_input_length_message",
count: SiteSetting.min_personal_message_post_length,
),
)
end
def has_homepage?
page.has_css?(HOMEPAGE_WRAPPER_CLASS)
end
def has_no_homepage?
page.has_no_css?(HOMEPAGE_WRAPPER_CLASS)
end
def has_no_new_question_button?
page.has_no_css?(".ai-new-question-button")
end
def has_new_question_button?
sidebar = PageObjects::Components::NavigationMenu::Sidebar.new
sidebar.has_css?(
"button.ai-new-question-button",
text: I18n.t("js.discourse_ai.ai_bot.conversations.new"),
)
end
def click_new_question_button
page.find(".ai-new-question-button").click
end
def has_empty_state?
page.has_css?(".ai-bot-sidebar-empty-state")
end
def click_fist_sidebar_conversation
page.find(
".sidebar-section[data-section-name='ai-conversations-history'] a.sidebar-section-link:not(.date-heading)",
).click
end
def persona_selector
PageObjects::Components::SelectKit.new(".persona-llm-selector__persona-dropdown")
end
def llm_selector
PageObjects::Components::SelectKit.new(".persona-llm-selector__llm-dropdown")
end
def has_sidebar_back_link?
page.has_css?(".sidebar-sections__back-to-forum")
end
def has_no_sidebar_back_link?
page.has_no_css?(".sidebar-sections__back-to-forum")
end
end
end
end