discourse/spec/system/page_objects/pages/admin_api_keys.rb
Régis Hanol 8830c1bb32
FIX: API key scopes display and navigation issues (#36844)
Two issues were occurring with the admin API keys page:

1. Clicking "Edit" on an API key in the list failed to navigate properly
because the full apiKey object was passed to the route instead of just
the ID.

2. Viewing an API key with scopes would error when a scope's
allowed_parameters was null/undefined, as the template tried to call
`get` on a nullish value.

**BEFORE**

https://github.com/user-attachments/assets/a1c3a54f-7d26-4498-95e3-fd734b2e9a61

**AFTER**

https://github.com/user-attachments/assets/d560a189-566f-4f85-a76a-266b9ac95bed
2025-12-23 17:56:12 +01:00

107 lines
2.8 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Pages
class AdminApiKeys < PageObjects::Pages::Base
def visit_page
page.visit "/admin/api/keys"
self
end
def has_api_key_listed?(name)
page.has_css?(table_selector, text: name)
end
def has_revoked_api_key_listed?(name)
row = page.find(table_selector, text: name)
row.has_css?(badge_selector, text: I18n.t("admin_js.admin.api_keys.revoked"))
end
def has_unrevoked_api_key_listed?(name)
row = page.find(table_selector, text: name)
row.has_no_css?(badge_selector, text: I18n.t("admin_js.admin.api_keys.revoked"))
end
def has_no_api_key_listed?(name)
page.has_no_css?(table_selector, text: name)
end
def has_generated_api_key?
page.has_css?(".generated-api-key")
end
def add_api_key(description:)
page.find(header_actions_selector, text: I18n.t("admin_js.admin.api_keys.add")).click
form = page.find(".form-kit")
form.find(description_field_selector).fill_in(with: description)
form.find(".save").click
end
def click_continue
page.find("button", text: I18n.t("admin_js.admin.api_keys.continue")).click
end
def click_edit(description)
row = page.find(row_selector, text: description)
row.find("button", text: I18n.t("admin_js.admin.api_keys.edit")).click
end
def click_revoke
page.find("button", text: I18n.t("admin_js.admin.api_keys.revoke")).click
end
def click_unrevoke
page.find("button", text: I18n.t("admin_js.admin.api_keys.undo_revoke")).click
end
def click_delete
page.find("button", text: I18n.t("admin_js.admin.api_keys.delete")).click
end
def edit_description(new_description)
page.find("button", text: I18n.t("admin_js.admin.api_keys.edit")).click
page.find(description_field_selector).fill_in(with: new_description)
page.find("button", text: I18n.t("admin_js.admin.api_keys.save")).click
end
def click_back
page.find("a.back-button").click
end
def has_scopes_displayed?
page.has_css?(scopes_table_selector)
end
def has_scope?(resource:, action:)
page.has_css?("#{scopes_table_selector} tr", text: /#{resource}.*#{action}/i)
end
private
def table_selector
".admin-api_keys__items"
end
def row_selector
".d-table__row"
end
def badge_selector
".status-label"
end
def header_actions_selector
".d-page-header__actions"
end
def description_field_selector
"input[name='description']"
end
def scopes_table_selector
".scopes-table"
end
end
end
end