Skip to content

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

DEV: Avoid ancestor lookup in admin plugin toggle spec (#44119)

Gabriel Grubba1ed6cd599f6b
diff --git a/plugins/automation/spec/system/admin_plugins_list_spec.rb b/plugins/automation/spec/system/admin_plugins_list_spec.rb
index c71f3666776..eda945e8bf9 100644
--- a/plugins/automation/spec/system/admin_plugins_list_spec.rb
+++ b/plugins/automation/spec/system/admin_plugins_list_spec.rb
@@ -34,16 +34,13 @@ describe "Admin Plugins List" do
it "can toggle whether a plugin is enabled" do
admin_plugins_list_page.visit
- toggle_switch =
- PageObjects::Components::DToggleSwitch.new(
- admin_plugins_list_page.plugin_row_selector("automation") +
- " .admin-plugins-list__enabled .d-toggle-switch__checkbox",
- )
- toggle_switch.toggle
- expect(toggle_switch).to be_unchecked
+
+ admin_plugins_list_page.toggle_plugin("automation")
+ expect(admin_plugins_list_page).to have_plugin_disabled("automation")
expect(SiteSetting.discourse_automation_enabled).to eq(false)
- toggle_switch.toggle
- expect(toggle_switch).to be_checked
+
+ admin_plugins_list_page.toggle_plugin("automation")
+ expect(admin_plugins_list_page).to have_plugin_enabled("automation")
expect(SiteSetting.discourse_automation_enabled).to eq(true)
end
diff --git a/spec/system/page_objects/pages/admin_plugins_list.rb b/spec/system/page_objects/pages/admin_plugins_list.rb
index 50eb09b580f..78844188eb8 100644
--- a/spec/system/page_objects/pages/admin_plugins_list.rb
+++ b/spec/system/page_objects/pages/admin_plugins_list.rb
@@ -19,6 +19,24 @@ module PageObjects
def click_plugin_name(plugin)
find_plugin(plugin).find(".admin-plugins-list__name").click
end
+
+ def toggle_plugin(plugin)
+ find(
+ "#{plugin_row_selector(plugin)} .admin-plugins-list__enabled label.d-toggle-switch__label",
+ ).click
+ end
+
+ def has_plugin_enabled?(plugin)
+ has_css?(
+ "#{plugin_row_selector(plugin)} .admin-plugins-list__enabled button[aria-checked='true']",
+ )
+ end
+
+ def has_plugin_disabled?(plugin)
+ has_css?(
+ "#{plugin_row_selector(plugin)} .admin-plugins-list__enabled button[aria-checked='false']",
+ )
+ end
end
end
end