package com.peachpasswords.autofill import com.peachpasswords.vault.VaultEntry import org.junit.Assert.assertEquals import org.junit.Test class AutofillMatchTest { private fun entry(title: String, url: String?) = VaultEntry(id = title, title = title, url = url, createdAt = 0, modifiedAt = 0) @Test fun domain_match_ranks_first() { val gh = entry("GitHub", "https://github.com/login") val mail = entry("Fastmail", "https://fastmail.com") val ranked = AutofillResponseBuilder.matchEntries(listOf(mail, gh), "login.github.com") assertEquals("GitHub", ranked.first().title) } @Test fun subdomain_origin_matches_core_label() { val gh = entry("GitHub", "https://github.com") val ranked = AutofillResponseBuilder.matchEntries(listOf(gh), "https://gist.github.com/") assertEquals("GitHub", ranked.first().title) } @Test fun no_origin_returns_all_unchanged() { val a = entry("A", null) val b = entry("B", null) assertEquals(listOf(a, b), AutofillResponseBuilder.matchEntries(listOf(a, b), null)) } }