Skip to content

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

2.2 KB
Raw Blame
# frozen_string_literal: true

module PageObjects
  module Pages
    class AdminStaffActionLogs < PageObjects::Pages::Base
      def visit
        page.visit "admin/logs/staff_action_logs"
        self
      end

      def log_row_selector(user_history)
        ".staff-logs tr[data-user-history-id='#{user_history.id}']"
      end

      def log_row(user_history)
        find(log_row_selector(user_history))
      end

      def has_log_row?(user_history)
        has_css?(log_row_selector(user_history))
      end

      def has_no_log_row?(user_history)
        has_no_css?(log_row_selector(user_history))
      end

      def has_no_injected_detail_element?(user_history)
        has_no_css?("#{log_row_selector(user_history)} .details img[onerror]")
      end

      def has_details_text?(user_history, text)
        has_css?("#{log_row_selector(user_history)} .details", text: text)
      end

      def show_details(user_history)
        log_row(user_history).find(
          ".details a",
          text: I18n.t("admin_js.admin.logs.staff_actions.show"),
        ).click
      end

      def filter_by_action(action)
        filter = PageObjects::Components::SelectKit.new("#staff-action-logs-action-filter")
        filter.search(I18n.t("admin_js.admin.logs.staff_actions.actions.#{action}"))
        filter.select_row_by_value(action.to_s)
      end

      def clear_filter
        find(".clear-filters").click
      end

      def filter_by_staff_user(user)
        find(".staff-logs .staff-user button", text: user.username, match: :first).click
      end

      def has_staff_user_filter?(user)
        has_button?(staff_user_filter_label(user))
      end

      def clear_staff_user_filter(user)
        click_button(staff_user_filter_label(user))
      end

      def click_export_button
        find(".export-staff-action-logs").click
      end

      def fill_date_filter_from(date)
        find(".d-date-time-input.from .d-date-input input").set(date)
      end

      def fill_date_filter_to(date)
        find(".d-date-time-input.to .d-date-input input").set(date)
      end

      private

      def staff_user_filter_label(user)
        "#{I18n.t("admin_js.admin.logs.staff_actions.staff_user")}: #{user.username}"
      end
    end
  end
end