changed newUiState to newsUiState in AuthorViewModel.kt and AuthorViewModelTest.kt

pull/293/head
kashif mehmood 2 years ago
parent 5f82a32185
commit e2db3c1a28

@ -69,7 +69,7 @@ fun AuthorRoute(
viewModel: AuthorViewModel = hiltViewModel(), viewModel: AuthorViewModel = hiltViewModel(),
) { ) {
val authorUiState: AuthorUiState by viewModel.authorUiState.collectAsStateWithLifecycle() val authorUiState: AuthorUiState by viewModel.authorUiState.collectAsStateWithLifecycle()
val newsUiState: NewsUiState by viewModel.newUiState.collectAsStateWithLifecycle() val newsUiState: NewsUiState by viewModel.newsUiState.collectAsStateWithLifecycle()
AuthorScreen( AuthorScreen(
authorUiState = authorUiState, authorUiState = authorUiState,

@ -62,7 +62,7 @@ class AuthorViewModel @Inject constructor(
initialValue = AuthorUiState.Loading initialValue = AuthorUiState.Loading
) )
val newUiState: StateFlow<NewsUiState> = newsUiStateStream( val newsUiState: StateFlow<NewsUiState> = newsUiStateStream(
authorId = authorId, authorId = authorId,
userDataRepository = userDataRepository, userDataRepository = userDataRepository,
newsRepository = newsRepository newsRepository = newsRepository

@ -91,7 +91,7 @@ class AuthorViewModelTest {
@Test @Test
fun uiStateNews_whenInitialized_thenShowLoading() = runTest { fun uiStateNews_whenInitialized_thenShowLoading() = runTest {
assertEquals(NewsUiState.Loading, viewModel.newUiState.value) assertEquals(NewsUiState.Loading, viewModel.newsUiState.value)
} }
@Test @Test
@ -115,7 +115,7 @@ class AuthorViewModelTest {
val collectJob = launch(UnconfinedTestDispatcher()) { val collectJob = launch(UnconfinedTestDispatcher()) {
combine( combine(
viewModel.authorUiState, viewModel.authorUiState,
viewModel.newUiState, viewModel.newsUiState,
::Pair ::Pair
).collect() ).collect()
} }
@ -123,7 +123,7 @@ class AuthorViewModelTest {
authorsRepository.sendAuthors(testInputAuthors.map { it.author }) authorsRepository.sendAuthors(testInputAuthors.map { it.author })
userDataRepository.setFollowedAuthorIds(setOf(testInputAuthors[1].author.id)) userDataRepository.setFollowedAuthorIds(setOf(testInputAuthors[1].author.id))
val authorState = viewModel.authorUiState.value val authorState = viewModel.authorUiState.value
val newsUiState = viewModel.newUiState.value val newsUiState = viewModel.newsUiState.value
assertTrue(authorState is AuthorUiState.Success) assertTrue(authorState is AuthorUiState.Success)
assertTrue(newsUiState is NewsUiState.Loading) assertTrue(newsUiState is NewsUiState.Loading)
@ -137,7 +137,7 @@ class AuthorViewModelTest {
val collectJob = launch(UnconfinedTestDispatcher()) { val collectJob = launch(UnconfinedTestDispatcher()) {
combine( combine(
viewModel.authorUiState, viewModel.authorUiState,
viewModel.newUiState, viewModel.newsUiState,
::Pair ::Pair
).collect() ).collect()
} }
@ -146,7 +146,7 @@ class AuthorViewModelTest {
userDataRepository.setFollowedAuthorIds(setOf(testInputAuthors[1].author.id)) userDataRepository.setFollowedAuthorIds(setOf(testInputAuthors[1].author.id))
newsRepository.sendNewsResources(sampleNewsResources) newsRepository.sendNewsResources(sampleNewsResources)
val authorState = viewModel.authorUiState.value val authorState = viewModel.authorUiState.value
val newsUiState = viewModel.newUiState.value val newsUiState = viewModel.newsUiState.value
assertTrue(authorState is AuthorUiState.Success) assertTrue(authorState is AuthorUiState.Success)
assertTrue(newsUiState is NewsUiState.Success) assertTrue(newsUiState is NewsUiState.Success)
@ -174,7 +174,7 @@ class AuthorViewModelTest {
@Test @Test
fun uiStateAuthor_whenNewsBookmarked_thenShowBookmarkedNews() = runTest { fun uiStateAuthor_whenNewsBookmarked_thenShowBookmarkedNews() = runTest {
val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.newUiState.collect() } val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.newsUiState.collect() }
authorsRepository.sendAuthors(testInputAuthors.map { it.author }) authorsRepository.sendAuthors(testInputAuthors.map { it.author })
newsRepository.sendNewsResources(sampleNewsResources) newsRepository.sendNewsResources(sampleNewsResources)
@ -191,7 +191,7 @@ class AuthorViewModelTest {
) )
assertTrue( assertTrue(
(viewModel.newUiState.value as NewsUiState.Success) (viewModel.newsUiState.value as NewsUiState.Success)
.news .news
.first { it.newsResource.id == sampleNewsResources.first().id } .first { it.newsResource.id == sampleNewsResources.first().id }
.isSaved .isSaved

Loading…
Cancel
Save