Skip to content

Conversation

@NickHuk
Copy link
Owner

@NickHuk NickHuk commented Jun 15, 2021

Overview

Write tests for AnilistPresenter to check sequence of invocation of different states for some flows.

Checklist

  • Test initial data loading
  • Test refresh data
  • Test viewing details during the data refreshing
  • Test backoff after viewing details
  • Test loading after a backoff

Type of change

  • Test

@NickHuk NickHuk self-assigned this Jun 15, 2021
Comment on lines 72 to 78
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)
Copy link
Collaborator

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

Copy link
Owner Author

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)

Copy link
Collaborator

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

Comment on lines +143 to +144
val expectedDetails = animeDetails.copy()
every { loadAnime(any()) } returns Single.just(animeDetails)
Copy link
Collaborator

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

Copy link
Owner Author

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

Comment on lines 216 to 220
val expectedThirdState = AnilistViewState(
pageState = PageState(anime, 1, true),
error = "No connection",
loadingEnabled = false,
backoff = 1
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants