Add autofill filter test for names with punctuation (#1142)

This commit is contained in:
Leendert de Borst
2025-08-25 17:50:00 +02:00
committed by Leendert de Borst
parent 0f8e1f7e15
commit 64a879f72d
3 changed files with 38 additions and 0 deletions

View File

@@ -279,6 +279,19 @@ describe('Filter - Credential URL Matching', () => {
expect(matches).toHaveLength(0);
});
// [#19] - Ensure separators and punctuation are stripped for matching
it('should match service names when separated by commas and other punctuation', () => {
const matches = filterCredentials(
testCredentials,
'https://nomatch.com',
'Reddit, social media platform'
);
// Should match "Reddit" even though it's followed by a comma and description
expect(matches).toHaveLength(1);
expect(matches[0].ServiceName).toBe('Reddit');
});
/**
* Creates the shared test credential dataset used across all platforms.
* Note: when making changes to this list, make sure to update the corresponding list for iOS and Android tests as well.
@@ -297,6 +310,7 @@ describe('Filter - Credential URL Matching', () => {
createTestCredential('Title Only newyorktimes', '', ''),
createTestCredential('Bank Account', 'https://secure-bank.com', 'user@bank.com'),
createTestCredential('AliExpress', 'https://aliexpress.com', 'user@aliexpress.com'),
createTestCredential('Reddit', '', 'user@reddit.com'),
];
}

View File

@@ -282,6 +282,19 @@ class AutofillTest {
assertTrue(matches.isEmpty())
}
// [#19] - Ensure separators and punctuation are stripped for matching
@Test
fun testSeparatorsAndPunctuationStripped() {
val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"Reddit, social media platform",
)
// Should match "Reddit" even though it's followed by a comma and description
assertEquals(1, matches.size)
assertEquals("Reddit", matches[0].service.name)
}
/**
* Creates the shared test credential dataset used across all platforms.
* This ensures consistent testing across Browser Extension, iOS, and Android.
@@ -300,6 +313,7 @@ class AutofillTest {
createTestCredential("Title Only newyorktimes", "", ""),
createTestCredential("Bank Account", "https://secure-bank.com", "user@bank.com"),
createTestCredential("AliExpress", "https://aliexpress.com", "user@aliexpress.com"),
createTestCredential("Reddit", "", "user@reddit.com"),
)
}

View File

@@ -180,6 +180,15 @@ final class CredentialFilterTests: XCTestCase {
XCTAssertTrue(matches.isEmpty)
}
// [#19] - Ensure separators and punctuation are stripped for matching
func testSeparatorsAndPunctuationStripped() {
let matches = CredentialFilter.filterCredentials(testCredentials, searchText: "Reddit, social media platform")
// Should match "Coolblue" even though it's followed by a comma and description
XCTAssertEqual(matches.count, 1)
XCTAssertEqual(matches.first?.service.name, "Reddit")
}
// MARK: - Shared Test Data
/**
@@ -200,6 +209,7 @@ final class CredentialFilterTests: XCTestCase {
createTestCredential(serviceName: "Title Only newyorktimes", serviceUrl: "", username: ""),
createTestCredential(serviceName: "Bank Account", serviceUrl: "https://secure-bank.com", username: "user@bank.com"),
createTestCredential(serviceName: "AliExpress", serviceUrl: "https://aliexpress.com", username: "user@aliexpress.com"),
createTestCredential(serviceName: "Reddit", serviceUrl: "", username: "user@reddit.com"),
]
}