-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added FakeBooksRepository and FakeBookUiState
- Loading branch information
1 parent
d5ba918
commit 3b50829
Showing
6 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/test/java/com/don/preface/fake/data/FakeBookUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.don.preface.fake.data | ||
|
||
import com.don.preface.domain.states.BookUiState | ||
import com.don.preface.domain.states.ResultState | ||
import com.don.preface.domain.utils.color_utils.model.ColorPallet | ||
import com.don.preface.fake.data.FakeBookDetailsDataSource.fakeBookDetailsResponse | ||
|
||
object FakeBookUiState { | ||
|
||
val fakeBookUiStateSuccess: BookUiState = | ||
BookUiState( | ||
bookDetails = fakeBookDetailsResponse, | ||
resultState = ResultState.Success, | ||
highestImageUrl = "https://example.com/highest_image.jpg", | ||
colorPallet = ColorPallet() | ||
) | ||
val fakeBookUiStateError: BookUiState = | ||
BookUiState( | ||
resultState = ResultState.Error("Error message") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/test/java/com/don/preface/fake/repository/FakeBooksRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.don.preface.fake.repository | ||
|
||
import com.don.preface.data.model.BookListItemResponse | ||
import com.don.preface.domain.repositories.BooksRepository | ||
import com.don.preface.domain.states.BookUiState | ||
import com.don.preface.fake.data.FakeBookUiState.fakeBookUiStateError | ||
import com.don.preface.fake.data.FakeBookUiState.fakeBookUiStateSuccess | ||
import com.don.preface.fake.data.FakeBooksDataSource | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.update | ||
import retrofit2.Response | ||
|
||
class FakeBooksRepository: BooksRepository { | ||
private val _bookState = MutableStateFlow(BookUiState()) | ||
override val bookUiState: StateFlow<BookUiState> = _bookState | ||
|
||
override suspend fun searchBooks(query: String): Response<BookListItemResponse> { | ||
return FakeBooksDataSource.fakeBookList | ||
} | ||
|
||
override suspend fun getBookDetails(bookId: String) { | ||
if (bookId == "5cu7sER89nwC") { | ||
_bookState.value = fakeBookUiStateSuccess | ||
}else if(bookId == "exampleErrorId"){ | ||
_bookState.value = fakeBookUiStateError | ||
|
||
} | ||
} | ||
|
||
override fun updateBookState(newState: BookUiState) { | ||
_bookState.update { | ||
newState | ||
} | ||
} | ||
|
||
|
||
} |
4 changes: 4 additions & 0 deletions
4
app/src/test/java/com/don/preface/tests/repositories/BooksRepositoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.don.preface.tests.repositories | ||
|
||
class BooksRepositoryTest { | ||
} |