A platform for community discussion. Free, open, simple.
# frozen_string_literal: true
module PageObjects
module Pages
class AdminDashboardReports < PageObjects::Pages::Base
SECTION_SELECTOR = ".db-main [data-section-id='reports']"
def has_section?
has_css?(SECTION_SELECTOR)
end
def card_identifiers
within(SECTION_SELECTOR) { all(".db-report__card").map { |el| el["data-identifier"] } }
end
def has_cards_in_order?(identifiers)
has_css?("#{SECTION_SELECTOR} .db-report__card", count: identifiers.size) &&
identifiers.each_with_index.all? do |identifier, index|
has_css?(
"#{SECTION_SELECTOR} .db-report__card:nth-child(#{index + 1})[data-identifier='#{identifier}']",
)
end
end
def has_card?(identifier)
has_css?("#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}']")
end
def has_card_size?(identifier, rows:, cols:)
selector = "#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}']"
selector += cols > 1 ? ".--wide" : ":not(.--wide)"
selector += rows > 1 ? ".--rows-#{rows}" : ":not([class*='--rows-'])"
has_css?(selector)
end
def has_default_report?
has_card?(default_report_identifier)
end
def has_no_card?(identifier)
has_no_css?("#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}']")
end
def has_add_tile?
has_css?("#{SECTION_SELECTOR} .db-report__add-report")
end
def has_no_add_tile?
has_no_css?("#{SECTION_SELECTOR} .db-report__add-report")
end
def has_cog?
has_css?("#{SECTION_SELECTOR} .db-section__header-action .btn")
end
def has_no_cog?
has_no_css?("#{SECTION_SELECTOR} .db-section__header-action .btn")
end
def has_no_remove_button?(identifier)
has_no_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__remove",
)
end
def open_default_report
within(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{default_report_identifier}']",
) { find(".db-report__name").click }
self
end
def open_manage_reports_via_tile
find("#{SECTION_SELECTOR} .db-report__add-report").click
self
end
def open_manage_reports_via_cog
within(SECTION_SELECTOR) { find(".db-section__header-action .btn").click }
self
end
def manage_reports_modal
PageObjects::Components::ManageableRowListModal.new(
".manage-reports",
"admin_js.admin.dashboard.reports_section.modal.counter",
)
end
def has_label_for?(identifier, label)
has_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__label",
text: label,
)
end
def has_no_label_for?(identifier)
has_no_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__label",
)
end
def has_empty_state_for?(identifier)
has_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__empty",
)
end
private
def default_report_identifier
"#{::AdminDashboard::Reports::CoreReportProvider::SOURCE_NAME}:#{SeedData::AdminDashboardReports::DEFAULT_BUILTIN_REPORTS.first}"
end
end
end
end