-
Notifications
You must be signed in to change notification settings - Fork 0
AnilistPresenter tests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally you should copy previous state and set what's changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahah, your expected state equals your tested state always
Something wrong here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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