DEV: Add system test for user security keys (#23372)

This commit is contained in:
Penar Musaraj
2023-09-03 22:07:20 -04:00
committed by GitHub
parent d108762c94
commit 0a3f1852c6
8 changed files with 88 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
# frozen_string_literal: true
describe "User preferences for Interface", type: :system do
fab!(:user) { Fabricate(:user) }
let(:user_preferences_page) { PageObjects::Pages::UserPreferences.new }
let(:user_preferences_interface_page) { PageObjects::Pages::UserPreferencesInterface.new }
before { sign_in(user) }
describe "Bookmarks" do
it "changes the bookmark after notification preference" do
user_preferences_page.visit(user)
click_link(I18n.t("js.user.preferences_nav.interface"))
dropdown = PageObjects::Components::SelectKit.new("#bookmark-after-notification-mode")
# preselects the default user_option.bookmark_auto_delete_preference value of 3 (clear_reminder)
expect(dropdown).to have_selected_value(Bookmark.auto_delete_preferences[:clear_reminder])
dropdown.select_row_by_value(Bookmark.auto_delete_preferences[:when_reminder_sent])
click_button(I18n.t("js.save"))
# the preference page reloads after saving, so we need to poll the db
try_until_success(timeout: 20) do
expect(
UserOption.exists?(
user_id: user.id,
bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:when_reminder_sent],
),
).to be_truthy
end
end
end
end

View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
describe "User page navigation menu", type: :system do
fab!(:user) { Fabricate(:user) }
let(:everyone_group) { Group[:everyone] }
let(:user_preferences_page) { PageObjects::Pages::UserPreferences.new }
describe "when visiting the user's preferences page" do
it "should allow the user to scroll the horizontal navigation menu when window width is narrow" do
resize_window(width: 400) do
sign_in(user)
user_preferences_page.visit(user)
expect(user_preferences_page).to have_interface_link_not_visible
expect(user_preferences_page).to have_account_link_visible
user_preferences_page.click_secondary_navigation_menu_scroll_right
expect(user_preferences_page).to have_interface_link_visible
expect(user_preferences_page).to have_account_link_not_visible
user_preferences_page.click_secondary_navigation_menu_scroll_left
expect(user_preferences_page).to have_interface_link_not_visible
expect(user_preferences_page).to have_account_link_visible
end
end
end
end

View File

@@ -0,0 +1,45 @@
# frozen_string_literal: true
describe "User preferences for Security", type: :system do
fab!(:password) { "kungfukenny" }
fab!(:email) { "email@user.com" }
fab!(:user) { Fabricate(:user, email: email, password: password) }
let(:user_preferences_security_page) { PageObjects::Pages::UserPreferencesSecurity.new }
let(:user_menu) { PageObjects::Components::UserMenu.new }
before do
user.activate
sign_in(user)
end
describe "Security keys" do
it "adds a 2F security key and logs in with it" do
# simulate browser credential authorization
options = ::Selenium::WebDriver::VirtualAuthenticatorOptions.new
page.driver.browser.add_virtual_authenticator(options)
user_preferences_security_page.visit(user)
user_preferences_security_page.visit_second_factor(password)
find(".security-key .new-security-key").click
expect(user_preferences_security_page).to have_css("input#security-key-name")
find(".modal-body input#security-key-name").fill_in(with: "First Key")
find(".add-security-key").click
expect(user_preferences_security_page).to have_css(".security-key .second-factor-item")
user_menu.sign_out
# login flow
find(".d-header .login-button").click
find("input#login-account-name").fill_in(with: user.username)
find("input#login-account-password").fill_in(with: password)
find(".modal-footer .btn-primary").click
find("#security-key .btn-primary").click
expect(page).to have_css(".header-dropdown-toggle.current-user")
end
end
end