Skip to content
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

Add Sponsor ActionCreator test #751

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
package io.github.droidkaigi.confsched2019

import com.soywiz.klock.DateTime
import com.soywiz.klock.hours
import io.github.droidkaigi.confsched2019.model.SponsorCategory
import io.github.droidkaigi.confsched2019.model.Sponsor
import io.github.droidkaigi.confsched2019.model.SponsorCategory

private val startTime =
DateTime.createAdjusted(2019, 2, 7, 10, 0).toOffsetUnadjusted(9.hours).utc

fun dummySponsorsData(): List<SponsorCategory> {
fun dummySponsorCategoriesData(): List<SponsorCategory> {
return listOf(
SponsorCategory(
SponsorCategory.Category.PLATINUM,
1,
listOf(
category = SponsorCategory.Category.PLATINUM,
index = 1,
sponsors = listOf(
Sponsor(
name = "mercari",
url = "https://tech.mercari.com/",
image = "https://droidkaigi.jp/2019/images/sponsors/25_mercari.png"
)
)
),
SponsorCategory(
category = SponsorCategory.Category.GOLD,
index = 2,
sponsors = listOf(
Sponsor(
"name1",
"url1",
"image1"
name = "google developers",
url = "https://developers.google.com/",
image = "https://droidkaigi.jp/2019/images/sponsors/aa_google.png"
)
)
),
SponsorCategory(
SponsorCategory.Category.GOLD,
2,
listOf(
category = SponsorCategory.Category.SUPPORT,
index = 3,
sponsors = listOf(
Sponsor(
"name2",
"url2",
"image2"
name = "deploygate",
url = "https://deploygate.com/",
image = "https://droidkaigi.jp/2019/images/sponsors/42_deploygate.png"
)
)
),
SponsorCategory(
SponsorCategory.Category.SUPPORT,
3,
listOf(
category = SponsorCategory.Category.TECH,
index = 4,
sponsors = listOf(
Sponsor(
"name3",
"url3",
"image3"
name = "dwango",
url = "http://dwango.co.jp/",
image = "https://droidkaigi.jp/2019/images/sponsors/58_dwango.png"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.github.droidkaigi.confsched2019.sponsor.ui.actioncreator

import androidx.lifecycle.Lifecycle
import io.github.droidkaigi.confsched2019.action.Action
import io.github.droidkaigi.confsched2019.data.repository.SponsorRepository
import io.github.droidkaigi.confsched2019.dispatcher.Dispatcher
import io.github.droidkaigi.confsched2019.dummySponsorCategoriesData
import io.github.droidkaigi.confsched2019.ext.android.CoroutinePlugin
import io.github.droidkaigi.confsched2019.model.LoadingState
import io.github.droidkaigi.confsched2019.widget.component.TestLifecycleOwner
import io.mockk.MockKAnnotations
import io.mockk.Ordering
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.impl.annotations.RelaxedMockK
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Test

class SponsorActionCreatorTest {
@RelaxedMockK lateinit var dispatcher: Dispatcher
@RelaxedMockK lateinit var sponsorRepository: SponsorRepository

@Before
fun setUp() {
MockKAnnotations.init(this, relaxUnitFun = true)
CoroutinePlugin.mainDispatcherHandler = { Dispatchers.Default }
}

@Test
fun load() = runBlocking {
val lifecycleOwner = TestLifecycleOwner().handleEvent(Lifecycle.Event.ON_RESUME)
coEvery { sponsorRepository.sponsors() } returns dummySponsorCategoriesData()
val sponsorActionCreator = SponsorActionCreator(
dispatcher,
sponsorRepository,
lifecycleOwner.lifecycle
)

sponsorActionCreator.load()

coVerify(ordering = Ordering.ORDERED) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this coVerify. 😄

dispatcher.dispatch(Action.SponsorLoadingStateChanged(LoadingState.LOADING))
sponsorRepository.sponsors()
dispatcher.dispatch(Action.SponsorLoaded(dummySponsorCategoriesData()))
sponsorRepository.refresh()
sponsorRepository.sponsors()
dispatcher.dispatch(Action.SponsorLoaded(dummySponsorCategoriesData()))
dispatcher.dispatch(Action.SponsorLoadingStateChanged(LoadingState.LOADED))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.github.droidkaigi.confsched2019.sponsor.ui.store
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import io.github.droidkaigi.confsched2019.action.Action
import io.github.droidkaigi.confsched2019.dispatcher.Dispatcher
import io.github.droidkaigi.confsched2019.dummySponsorsData
import io.github.droidkaigi.confsched2019.dummySponsorCategoriesData
import io.github.droidkaigi.confsched2019.ext.android.CoroutinePlugin
import io.github.droidkaigi.confsched2019.ext.android.changedForever
import io.github.droidkaigi.confsched2019.model.SponsorCategory
Expand Down Expand Up @@ -45,7 +45,7 @@ class SponsorStoreTest {
sponsorStore.sponsors.changedForever(observer)
verify { observer(emptyList()) }

val dummySponsors = dummySponsorsData()
val dummySponsors = dummySponsorCategoriesData()
dispatcher.dispatch(
Action.SponsorLoaded(dummySponsors)
)
Expand Down

This file was deleted.