Skip to content
Snippets Groups Projects
Verified Commit 7f61fd5d authored by Eduardo Sanz García's avatar Eduardo Sanz García :zero:
Browse files

Remove oauth-login-[provider] ID used for testing

The documentation suggest finding the element by text or `data-testid`:
https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#finders
parent 23353959
No related branches found
No related tags found
2 merge requests!144312Change service start (cut-off) date for code suggestions to March 15th,!142801Remove oauth-login-[provider] ID used for testing
......@@ -9,8 +9,7 @@
= render 'devise/shared/omniauth_provider_button',
href: omniauth_authorize_path(:user, provider),
provider: provider,
data: { testid: test_id_for_provider(provider) },
id: "oauth-login-#{provider}"
data: { testid: test_id_for_provider(provider) }
- if render_remember_me
= render Pajamas::CheckboxTagComponent.new(name: 'js-remember-me-omniauth', value: nil) do |c|
- c.with_label do
......
- button_options = { class: local_assigns[:classes], data: data, id: local_assigns[:id] }
- button_options = { class: local_assigns[:classes], data: data }
= render Pajamas::ButtonComponent.new(href: href, method: :post, form: true, block: true, button_options: button_options) do
- if provider_has_icon?(provider)
......
......@@ -35,21 +35,22 @@ describe('preserve_url_fragment', () => {
describe('OAuth login forms', () => {
const findFormAction = (selector) =>
document.querySelector(`.js-oauth-login #oauth-login-${selector}`).parentElement.action;
document.querySelector(`.js-oauth-login [data-testid=${selector}-login-button]`).parentElement
.action;
describe('appendRedirectQuery', () => {
it('does not add an empty query parameter to the login form actions', () => {
appendRedirectQuery();
expect(findFormAction('auth0')).toBe('http://test.host/users/auth/auth0');
expect(findFormAction('github')).toBe('http://test.host/users/auth/github');
});
describe('adds "redirect_fragment" query parameter to the login form actions', () => {
it('when "remember_me" is not present', () => {
appendRedirectQuery('#L65');
expect(findFormAction('auth0')).toBe(
'http://test.host/users/auth/auth0?redirect_fragment=L65',
expect(findFormAction('github')).toBe(
'http://test.host/users/auth/github?redirect_fragment=L65',
);
});
......@@ -60,8 +61,8 @@ describe('preserve_url_fragment', () => {
appendRedirectQuery('#L65');
expect(findFormAction('auth0')).toBe(
'http://test.host/users/auth/auth0?remember_me=1&redirect_fragment=L65',
expect(findFormAction('github')).toBe(
'http://test.host/users/auth/github?remember_me=1&redirect_fragment=L65',
);
});
});
......@@ -73,15 +74,15 @@ describe('preserve_url_fragment', () => {
it('toggles "remember_me" query parameter', () => {
toggleRememberMeQuery();
expect(findFormAction('auth0')).toBe('http://test.host/users/auth/auth0');
expect(findFormAction('github')).toBe('http://test.host/users/auth/github');
rememberMe().click();
expect(findFormAction('auth0')).toBe('http://test.host/users/auth/auth0?remember_me=1');
expect(findFormAction('github')).toBe('http://test.host/users/auth/github?remember_me=1');
rememberMe().click();
expect(findFormAction('auth0')).toBe('http://test.host/users/auth/auth0');
expect(findFormAction('github')).toBe('http://test.host/users/auth/github');
});
});
});
......
......@@ -114,7 +114,7 @@ def login_via(provider, user, uid, remember_me: false, additional_info: {})
check 'js-remember-me-omniauth' if remember_me
click_button "oauth-login-#{provider}"
click_button Gitlab::Auth::OAuth::Provider.label_for(provider)
end
def sign_in_using_ldap!(user, ldap_tab, ldap_name)
......@@ -132,7 +132,7 @@ def register_via(provider, uid, email, additional_info: {})
visit new_user_registration_path
expect(page).to have_content('Create an account using').or(have_content('Register with'))
click_link_or_button Gitlab::Auth::OAuth::Provider.label_for(provider)
click_button Gitlab::Auth::OAuth::Provider.label_for(provider)
end
def fake_successful_webauthn_authentication
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment