Skip to content

Commit

Permalink
unit testting fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonelZalegas committed Jul 27, 2024
1 parent b08618a commit 50e303d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
6 changes: 0 additions & 6 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class CompanyInfoViewModelTest {
testDispatcher.scheduler.advanceUntilIdle()

// Assert
assertEquals(companyInfo, viewModel.state.company)
assertEquals(intradayInfo, viewModel.state.stockIntradayInfos)
assertFalse(viewModel.state.isLoading)
assertNull(viewModel.state.error)
val state = viewModel.state.value
assertEquals(companyInfo, state.company)
assertEquals(intradayInfo, state.stockIntradayInfos)
assertFalse(state.isLoading)
assertNull(state.error)

coVerify { repository.getCompanyInfo("AAPL") }
coVerify { repository.getIntradayInfo("AAPL") }
Expand All @@ -73,10 +74,11 @@ class CompanyInfoViewModelTest {
testDispatcher.scheduler.advanceUntilIdle()

// Assert
assertNull(viewModel.state.company)
assertTrue(viewModel.state.stockIntradayInfos.isEmpty())
assertFalse(viewModel.state.isLoading)
assertEquals("Couldn't load company info", viewModel.state.error)
val state = viewModel.state.value
assertNull(state.company)
assertTrue(state.stockIntradayInfos.isEmpty())
assertFalse(state.isLoading)
assertEquals("Couldn't load company info", state.error)

coVerify { repository.getCompanyInfo("AAPL") }
coVerify { repository.getIntradayInfo("AAPL") }
Expand All @@ -95,9 +97,10 @@ class CompanyInfoViewModelTest {
testDispatcher.scheduler.advanceUntilIdle()

// Assert
assertEquals(companyInfo, viewModel.state.company)
assertTrue(viewModel.state.stockIntradayInfos.isEmpty())
assertFalse(viewModel.state.isLoading)
assertEquals("Error fetching intraday info", viewModel.state.error)
val state = viewModel.state.value
assertEquals(companyInfo, state.company)
assertTrue(state.stockIntradayInfos.isEmpty())
assertFalse(state.isLoading)
assertEquals("Error fetching intraday info", state.error)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class CompanyListingsViewModelTest {
testDispatcher.scheduler.advanceUntilIdle()

// Assert
assertEquals(companyListings, viewModel.state.companies)
assertFalse(viewModel.state.isLoading)
assertEquals(companyListings, viewModel.state.value.companies)
assertFalse(viewModel.state.value.isLoading)

coVerify { repository.getCompanyListings(false, "") }
}
Expand All @@ -65,8 +65,8 @@ class CompanyListingsViewModelTest {
testDispatcher.scheduler.advanceUntilIdle()

// Assert
assertEquals(companyListings, viewModel.state.companies)
assertFalse(viewModel.state.isLoading)
assertEquals(companyListings, viewModel.state.value.companies)
assertFalse(viewModel.state.value.isLoading)

coVerify { repository.getCompanyListings(true, "") }
}
Expand All @@ -84,8 +84,8 @@ class CompanyListingsViewModelTest {
testDispatcher.scheduler.advanceTimeBy(510) // Wait for debounce

// Assert
assertEquals("Apple", viewModel.state.searchQuery)
assertEquals(companyListings, viewModel.state.companies)
assertEquals("Apple", viewModel.state.value.searchQuery)
assertEquals(companyListings, viewModel.state.value.companies)

coVerify { repository.getCompanyListings(false, "apple") }
}
Expand All @@ -106,8 +106,8 @@ class CompanyListingsViewModelTest {
testDispatcher.scheduler.advanceUntilIdle()

// Assert
assertFalse(viewModel.state.isLoading)
assertTrue(viewModel.state.companies.isEmpty())
assertFalse(viewModel.state.value.isLoading)
assertTrue(viewModel.state.value.companies.isEmpty())

coVerify { repository.getCompanyListings(false, "") }
}
Expand Down

0 comments on commit 50e303d

Please sign in to comment.