@ -92,6 +92,21 @@ class HistoryMetadataMiddlewareTest {
}
}
}
}
@Test
fun `GIVEN normal tab has search results parent without search terms WHEN history metadata is recorded THEN search terms and referrer url are provided` ( ) {
setupGoogleSearchEngine ( )
val parentTab = createTab ( " https://google.com?q=mozilla+website " )
val tab = createTab ( " https://mozilla.org " , parent = parentTab )
store . dispatch ( TabListAction . AddTabAction ( parentTab ) ) . joinBlocking ( )
store . dispatch ( TabListAction . AddTabAction ( tab ) ) . joinBlocking ( )
store . dispatch ( ContentAction . UpdateHistoryStateAction ( tab . id , emptyList ( ) , currentIndex = 0 ) ) . joinBlocking ( )
verify {
service . createMetadata ( any ( ) , eq ( " mozilla website " ) , eq ( " https://google.com?q=mozilla+website " ) )
}
}
@Test
@Test
fun `GIVEN normal tab has parent WHEN url is the same THEN nothing happens` ( ) {
fun `GIVEN normal tab has parent WHEN url is the same THEN nothing happens` ( ) {
val parentTab = createTab ( " https://mozilla.org " , searchTerms = " mozilla website " )
val parentTab = createTab ( " https://mozilla.org " , searchTerms = " mozilla website " )
@ -107,25 +122,7 @@ class HistoryMetadataMiddlewareTest {
fun `GIVEN normal tab has no parent WHEN history metadata is recorded THEN search terms and referrer url are provided` ( ) {
fun `GIVEN normal tab has no parent WHEN history metadata is recorded THEN search terms and referrer url are provided` ( ) {
val tab = createTab ( " https://mozilla.org " )
val tab = createTab ( " https://mozilla.org " )
store . dispatch ( TabListAction . AddTabAction ( tab ) ) . joinBlocking ( )
store . dispatch ( TabListAction . AddTabAction ( tab ) ) . joinBlocking ( )
store . dispatch ( SearchAction . SetSearchEnginesAction (
setupGoogleSearchEngine ( )
regionSearchEngines = listOf (
SearchEngine (
id = " google " ,
name = " Google " ,
icon = mock ( ) ,
type = SearchEngine . Type . BUNDLED ,
resultUrls = listOf ( " https://google.com?q={searchTerms} " )
)
) ,
userSelectedSearchEngineId = null ,
userSelectedSearchEngineName = null ,
regionDefaultSearchEngineId = " google " ,
customSearchEngines = emptyList ( ) ,
hiddenSearchEngines = emptyList ( ) ,
additionalAvailableSearchEngines = emptyList ( ) ,
additionalSearchEngines = emptyList ( ) ,
regionSearchEnginesOrder = listOf ( " google " )
) ) . joinBlocking ( )
val historyState = listOf (
val historyState = listOf (
HistoryItem ( " firefox " , " https://google.com?q=mozilla+website " ) ,
HistoryItem ( " firefox " , " https://google.com?q=mozilla+website " ) ,
@ -142,25 +139,7 @@ class HistoryMetadataMiddlewareTest {
fun `GIVEN normal tab has no parent WHEN history metadata is recorded without search terms THEN no referrer is provided` ( ) {
fun `GIVEN normal tab has no parent WHEN history metadata is recorded without search terms THEN no referrer is provided` ( ) {
val tab = createTab ( " https://mozilla.org " )
val tab = createTab ( " https://mozilla.org " )
store . dispatch ( TabListAction . AddTabAction ( tab ) ) . joinBlocking ( )
store . dispatch ( TabListAction . AddTabAction ( tab ) ) . joinBlocking ( )
store . dispatch ( SearchAction . SetSearchEnginesAction (
setupGoogleSearchEngine ( )
regionSearchEngines = listOf (
SearchEngine (
id = " google " ,
name = " Google " ,
icon = mock ( ) ,
type = SearchEngine . Type . BUNDLED ,
resultUrls = listOf ( " https://google.com?q={searchTerms} " )
)
) ,
userSelectedSearchEngineId = null ,
userSelectedSearchEngineName = null ,
regionDefaultSearchEngineId = " google " ,
customSearchEngines = emptyList ( ) ,
hiddenSearchEngines = emptyList ( ) ,
additionalAvailableSearchEngines = emptyList ( ) ,
additionalSearchEngines = emptyList ( ) ,
regionSearchEnginesOrder = listOf ( " google " )
) ) . joinBlocking ( )
val historyState = listOf (
val historyState = listOf (
HistoryItem ( " firefox " , " https://mozilla.org " ) ,
HistoryItem ( " firefox " , " https://mozilla.org " ) ,
@ -410,4 +389,26 @@ class HistoryMetadataMiddlewareTest {
store . dispatch ( TabListAction . RemoveTabsAction ( listOf ( otherTab . id , yetAnotherTab . id ) ) ) . joinBlocking ( )
store . dispatch ( TabListAction . RemoveTabsAction ( listOf ( otherTab . id , yetAnotherTab . id ) ) ) . joinBlocking ( )
verify { service wasNot Called }
verify { service wasNot Called }
}
}
private fun setupGoogleSearchEngine ( ) {
store . dispatch ( SearchAction . SetSearchEnginesAction (
regionSearchEngines = listOf (
SearchEngine (
id = " google " ,
name = " Google " ,
icon = mock ( ) ,
type = SearchEngine . Type . BUNDLED ,
resultUrls = listOf ( " https://google.com?q={searchTerms} " )
)
) ,
userSelectedSearchEngineId = null ,
userSelectedSearchEngineName = null ,
regionDefaultSearchEngineId = " google " ,
customSearchEngines = emptyList ( ) ,
hiddenSearchEngines = emptyList ( ) ,
additionalAvailableSearchEngines = emptyList ( ) ,
additionalSearchEngines = emptyList ( ) ,
regionSearchEnginesOrder = listOf ( " google " )
) ) . joinBlocking ( )
}
}
}