Skip to content

Commit

Permalink
Merge pull request #12812 from woocommerce/issue/10553-fix-crash-on-s…
Browse files Browse the repository at this point in the history
…ite-picker

Fix crash on site picker for accounts without woo sites
  • Loading branch information
hichamboushaba authored Oct 24, 2024
2 parents 6d0b57c + a96e66a commit c8b90c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ class SitePickerViewModel @Inject constructor(
loadAndDisplaySites()
}
)
sitePickerViewState = sitePickerViewState.copy(isSkeletonViewVisible = false, isPrimaryBtnVisible = true)
sitePickerViewState = sitePickerViewState.copy(
isSkeletonViewVisible = false,
isPrimaryBtnVisible = sites.value!!.any { it is WooSiteUiModel }
)
}

private fun loadWooNotFoundView(site: SiteModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ class SitePickerViewModelTest : BaseUnitTest() {
assertThat(viewModel.event.value).isEqualTo(NavigateToAccountMismatchScreen(CONNECT_JETPACK, url))
}

@Test
fun `given the site address does not match the user account and there is no woo site, continue button is hidden`() =
testBlocking {
givenThatUserLoggedInFromEnteringSiteAddress(null)
whenever(repository.fetchSiteInfo(any())).thenReturn(
Result.success(
ConnectSiteInfoPayload(
url = SitePickerTestUtils.loginSiteAddress,
isWordPress = true,
isWPCom = false
)
)
)
val nonWooSite = SiteModel().apply {
id = 1
siteId = 1
hasWooCommerce = false
}
val siteList = listOf(nonWooSite)
whenSitesAreFetched(sitesFromApi = siteList, sitesFromDb = siteList)
whenViewModelIsCreated()

assertThat(viewModel.sitePickerViewState.isPrimaryBtnVisible).isEqualTo(false)
}

@Test
fun `given that the site address entered during login does not have Woo, no woo error screen is displayed`() =
testBlocking {
Expand Down

0 comments on commit c8b90c3

Please sign in to comment.