Conversation
anilist/src/main/java/com/huchihaitachi/anilist/presentation/AnilistPresenter.kt
Outdated
Show resolved
Hide resolved
| val expectedInitial = AnilistViewState(pageState = PageState(null, 0, true)) | ||
| val expectedLoading = AnilistViewState( | ||
| loading = PAGE, | ||
| pageState = PageState(null, 0, true), | ||
| ) | ||
| val expectedResult = AnilistViewState(pageState = PageState(anime, 1, true)) | ||
| loadPageIntentMock.onNext(Unit) |
There was a problem hiding this comment.
Ideally you should copy previous state and set what's changed
There was a problem hiding this comment.
General case is testing only order of calls, not exact sequence, so states may not contain the previous state at all because some intermediate state was omitted. The question is: should I copy the previous state if possible or use a unified way of creating states (through the constructor). The second thing is the copy() function may work incorrectly which cause test fails (not in this case, but in general)
There was a problem hiding this comment.
Yea, you should copy the previous state if possible
| val expectedDetails = animeDetails.copy() | ||
| every { loadAnime(any()) } returns Single.just(animeDetails) |
There was a problem hiding this comment.
Ahah, your expected state equals your tested state always
Something wrong here
There was a problem hiding this comment.
No, I test not details, but a state itself (which contains details). copying details prevents expected details change after test instance change in the tested class, so it is ok
| val expectedThirdState = AnilistViewState( | ||
| pageState = PageState(anime, 1, true), | ||
| error = "No connection", | ||
| loadingEnabled = false, | ||
| backoff = 1 |
There was a problem hiding this comment.
Update please copying previous state
Overview
Write tests for AnilistPresenter to check sequence of invocation of different states for some flows.Checklist
Type of change