Skip to content

Commit

Permalink
test: move to unit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Oct 25, 2024
1 parent 1d6a2f9 commit 4a55d98
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 77 deletions.
6 changes: 2 additions & 4 deletions integration-test/helpers/pages/unknownUsernameLoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import {expect} from '@playwright/test'
export function unknownUsernameLoginPage (page) {
class UnknownUsernameLoginPage {
/**
* @param {boolean} isPhone
* @return {Promise<void>}
*/
async navigate (isPhone = false) {
const path = `${constants.pages['unknownUsernameLogin']}/?fieldType=${isPhone ? 'phone' : 'unknown'}`
await page.goto(path)
async navigate (to = 'unknownUsernameLogin') {
await page.goto(constants.pages[to])
}

/**
Expand Down
17 changes: 1 addition & 16 deletions integration-test/pages/unknown-username-login.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,10 @@
Based on the presence of a password field, the unknown field should be classified
as a username field.
</p>
<script>
function updateLabelFromURL() {
const urlParams = new URLSearchParams(window.location.search);
const fieldType = urlParams.get('fieldType');
const label = document.getElementById('unknown-label');
const input = document.getElementById('unknown');
if (fieldType === 'phone') {
label.textContent = 'Phone number:';
label.id = 'phone'
} else {
label.textContent = 'Random input field:';
}
}
window.onload = updateLabelFromURL;
</script>
</head>
<body>
<form name="logon" style="display: flex; flex-direction: column; gap: 10px; align-items: flex-start;">
<label for="unknown" id="unknown-label">Random input field:</label>
<label for="unknown">Random input field:</label>
<input type="text" id="unknown" name="dummy">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
Expand Down
93 changes: 37 additions & 56 deletions integration-test/tests/login-form.macos.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,67 +109,48 @@ test.describe('Auto-fill a login form on macOS', () => {
})

test.describe('when there is a single ambiguous field, and one password field', () => {
test.describe('and the input type is unknown', async () => {
test('the ambiguous field is a username', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate()
await page.waitForTimeout(10)
await login.assertUnknownFieldIsUsername()
test('the ambiguous field is a username', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate()
await page.waitForTimeout(10)
await login.assertUnknownFieldIsUsername()
})

test('unknown field is autofilled when clicking into password', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate()
await login.autofillWithPasswordField(personalAddress)
await login.assertCredentialsFilled(personalAddress, password)
})
test('password field is autofilled when clicking into unknown field', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate()
await login.autofillWithPasswordField(personalAddress)
await login.assertCredentialsFilled(personalAddress, password)
test('unknown field is autofilled when clicking into password', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate()
await login.autofillWithPasswordField(personalAddress)
await login.assertCredentialsFilled(personalAddress, password)
})

test.describe('and the input type is phone number', () => {
test('phone field is a username', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate(true)
await login.autofillWithPasswordField(personalAddress)
await login.assertCredentialsFilled(personalAddress, password)
test('password field is autofilled when clicking into unknown field', async ({page}) => {
await forwardConsoleMessages(page)
await mocks(page, {
unknown_username_categorization: true
})
await createAutofillScript()
.replaceAll(macosContentScopeReplacements({}))
.platform('macos')
.applyTo(page)
const login = unknownUsernameLoginPage(page)
await login.navigate()
await login.autofillWithPasswordField(personalAddress)
await login.assertCredentialsFilled(personalAddress, password)
})
})

Expand Down
31 changes: 31 additions & 0 deletions test-forms/accounts_oneplus_login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

<form class="controlledfeild_form___jx_im htmlform_form__3r6nub" data-bitwarden-watching="1">
<div class="phonecodeinput_container__1li5pg">
<div class="input_wrapper__1x23fj">
<span class="phonecodeinput_selector__3tip3u">
+36
<div class="dropdownarrow_arrow__2ipvqn phonecodeinput_arrow__2bervq">
<svg width="8" height="5" viewBox="0 0 8 5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.53214 0L7.46788 0C7.76176 0 8 0.224178 8 0.500715C8 0.614524 7.9588 0.724938 7.88318 0.813762L4.51914 4.76539C4.28947 5.03518 3.87086 5.07869 3.58416 4.86257C3.54605 4.83384 3.51141 4.80125 3.48088 4.76539L0.116839 0.813762C-0.0668963 0.597935 -0.0299065 0.282816 0.199458 0.109925C0.293853 0.0387712 0.411192 0 0.53214 0Z" fill="black" fill-opacity="0.2"></path>
</svg>
</div>
</span>
<i style="display: inline-block; background-color: rgba(0, 0, 0, 0.08); width: 1px; height: 12px;"></i>
<div class="input_inner__9pf0en false">
<input autocomplete="off" class="input_input__102by1 input_has_before__bvm5rf" type="tel" placeholder="Phone" value="" data-ddg-inputtype="identities.phone">
<div data-lastpass-icon-root="" style="position: relative !important; height: 0px !important; width: 0px !important; float: left !important;"></div>
</div>
</div>
</div>
<i style="display: inline-block; background-color: transparent; width: 1px; height: 16px;"></i>
<div class="input_wrapper__1x23fj undefined">
<div class="input_inner__9pf0en false">
<input autocomplete="new-password" class="input_input__102by1" type="password" placeholder="Password" data-ddg-inputtype="credentials.password.current">
<div data-lastpass-icon-root="" style="position: relative !important; height: 0px !important; width: 0px !important; float: left !important;"></div>
</div>
<div class="passwordinput_after__1vrn_m"><span class="passwordinput_icon__dhpjay passwordinput_off__2vccul"></span></div>
</div>
<div class="controlledfeild_links__3et6gy"><span></span><a href="#" class="anchorlink_anchor__1gttsn" style="color: rgb(0, 123, 255);">Forgot password?</a></div>
<div class="controlledfeild_blank__2tj9ff"></div>
<div class="controlledfeild_buttons__16fcwv"><i style="opacity: 0;"></i><button class="button_button__2g6tsu button_middle__5fjgss bypwdandphone_button__2aqt9_" data-manual-submit="submit"><span>Sign in with password</span></button></div>
</form>
3 changes: 2 additions & 1 deletion test-forms/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,6 @@
{ "html": "fullcolor_login.html" },
{ "html": "malta-taxes-payment-form.html", "expectedFailures": ["expirationMonth", "expirationYear", "cardSecurityCode"] },
{ "html": "single-select-form.html" },
{ "html": "camelcamelcamel_login.html" }
{ "html": "camelcamelcamel_login.html" },
{ "html": "accounts_oneplus_login.html"}
]

0 comments on commit 4a55d98

Please sign in to comment.