Skip to content

A platform for community discussion. Free, open, simple.

3.7 KB
Raw Blame
# 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_anonymous_card?
        page.has_css?(".ai-bot-anonymous-card")
      end

      def click_anonymous_card
        page.find(".ai-bot-anonymous-card").click
      end

      def has_input_value?(value)
        page.has_field?("ai-bot-conversations-input", with: value)
      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 click_fist_sidebar_conversation
        page.find(".sidebar-section-content a.sidebar-section-link").click
      end

      def agent_selector
        PageObjects::Components::SelectKit.new(".agent-llm-selector__agent-dropdown")
      end

      def llm_selector
        PageObjects::Components::SelectKit.new(".agent-llm-selector__llm-dropdown")
      end

      def has_sidebar_back_link?
        page.has_css?(".sidebar-sections__back-to-forum")
      end

      def starred_section
        page.find("#sidebar-section-content-starred-conversations")
      end

      def today_section
        page.find("#sidebar-section-content-today")
      end

      def conversation_link(topic)
        page.find("li[data-list-item-name='ai-conversation-#{topic.id}']")
      end

      def has_starred_conversations_section?
        page.has_css?("#sidebar-section-content-starred-conversations")
      end

      def has_no_starred_conversations_section?
        page.has_no_css?("#sidebar-section-content-starred-conversations")
      end

      def open_conversation_menu(topic)
        conversation_link(topic).hover
        conversation_link(topic).find(".sidebar-section-hover-button").click
      end

      def toggle_star_for_conversation(topic)
        open_conversation_menu(topic)
        page.find(".ai-conversation-sidebar-link-menu__star-conversation").click
      end

      def share_conversation(topic)
        open_conversation_menu(topic)
        page.find(".ai-conversation-sidebar-link-menu__share-conversation").click
      end

      def has_share_conversation_menu_item?
        page.has_css?(".ai-conversation-sidebar-link-menu__share-conversation")
      end

      def has_no_star_conversation_menu_item?
        page.has_no_css?(".ai-conversation-sidebar-link-menu__star-conversation")
      end

      def has_star_conversation_menu_item?
        page.has_css?(".ai-conversation-sidebar-link-menu__star-conversation")
      end

      def has_no_sidebar_back_link?
        page.has_no_css?(".sidebar-sections__back-to-forum")
      end
    end
  end
end