-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from nimblehq/release/3.20.0
[Release] 3.20.0
- Loading branch information
Showing
25 changed files
with
381 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ jobs: | |
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Publish Github Wiki | ||
uses: nimblehq/[email protected] | ||
with: | ||
|
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
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
17 changes: 17 additions & 0 deletions
17
sample-compose/app/src/test/java/co/nimblehq/sample/compose/ui/screens/BaseScreenTest.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,17 @@ | ||
package co.nimblehq.sample.compose.ui.screens | ||
|
||
import co.nimblehq.sample.compose.test.CoroutineTestRule | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
|
||
abstract class BaseScreenTest { | ||
|
||
protected val coroutinesRule = CoroutineTestRule() | ||
|
||
protected fun setStandardTestDispatcher() { | ||
coroutinesRule.testDispatcher = StandardTestDispatcher() | ||
} | ||
|
||
protected fun advanceUntilIdle() { | ||
coroutinesRule.testDispatcher.scheduler.advanceUntilIdle() | ||
} | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
sample-xml/app/src/main/java/co/nimblehq/sample/xml/extension/NavArgsExt.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,10 @@ | ||
package co.nimblehq.sample.xml.extension | ||
|
||
import androidx.annotation.MainThread | ||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.NavArgs | ||
import androidx.navigation.fragment.navArgs | ||
|
||
@MainThread | ||
inline fun <reified Args : NavArgs> Fragment.provideNavArgs(): Lazy<Args> = | ||
OverridableLazy(navArgs()) |
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
14 changes: 14 additions & 0 deletions
14
sample-xml/app/src/test/java/co/nimblehq/sample/xml/test/NavArgsExt.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,14 @@ | ||
package co.nimblehq.sample.xml.test | ||
|
||
import androidx.navigation.NavArgs | ||
import co.nimblehq.sample.xml.extension.OverridableLazy | ||
import kotlin.reflect.KProperty1 | ||
import kotlin.reflect.jvm.isAccessible | ||
|
||
fun <Arg : NavArgs, T> T.replace( | ||
argumentDelegate: KProperty1<T, Arg>, | ||
argument: Arg | ||
) { | ||
argumentDelegate.isAccessible = true | ||
(argumentDelegate.getDelegate(this) as OverridableLazy<Arg>).implementation = lazy { argument } | ||
} |
108 changes: 108 additions & 0 deletions
108
sample-xml/app/src/test/java/co/nimblehq/sample/xml/ui/screens/home/HomeFragmentTest.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,108 @@ | ||
package co.nimblehq.sample.xml.ui.screens.home | ||
|
||
import androidx.core.view.isVisible | ||
import co.nimblehq.sample.xml.databinding.FragmentHomeBinding | ||
import co.nimblehq.sample.xml.model.UiModel | ||
import co.nimblehq.sample.xml.test.TestNavigatorModule.mockMainNavigator | ||
import co.nimblehq.sample.xml.test.getPrivateProperty | ||
import co.nimblehq.sample.xml.test.replace | ||
import co.nimblehq.sample.xml.ui.BaseFragmentTest | ||
import co.nimblehq.sample.xml.ui.base.NavigationEvent | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import io.kotest.matchers.booleans.shouldBeFalse | ||
import io.kotest.matchers.booleans.shouldBeTrue | ||
import io.kotest.matchers.nulls.shouldNotBeNull | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.* | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import org.junit.* | ||
import org.robolectric.shadows.ShadowToast | ||
import java.util.* | ||
|
||
@HiltAndroidTest | ||
class HomeFragmentTest : BaseFragmentTest<HomeFragment, FragmentHomeBinding>() { | ||
|
||
private val mockViewModel = mockk<HomeViewModel>(relaxed = true) | ||
|
||
@get:Rule | ||
var hiltRule = HiltAndroidRule(this) | ||
|
||
@Before | ||
fun setUp() { | ||
hiltRule.inject() | ||
} | ||
|
||
@Test | ||
fun `When launching fragment, it displays the recycler view`() { | ||
launchFragment() | ||
fragment.binding.rvHome.isVisible.shouldBeTrue() | ||
} | ||
|
||
@Test | ||
fun `When launching fragment and view model emits loading, it displays the progress bar`() { | ||
every { mockViewModel.isLoading } returns MutableStateFlow(true) | ||
|
||
launchFragment() | ||
fragment.binding.pbHome.isVisible.shouldBeTrue() | ||
} | ||
|
||
@Test | ||
fun `When launching fragment and view model does not emit loading, it does not display the progress bar`() { | ||
every { mockViewModel.isLoading } returns MutableStateFlow(false) | ||
|
||
launchFragment() | ||
fragment.binding.pbHome.isVisible.shouldBeFalse() | ||
} | ||
|
||
@Test | ||
fun `When launching fragment and view model emits list of item, it displays the recycler view with items`() { | ||
val items = arrayListOf( | ||
UiModel(UUID.randomUUID().toString()), | ||
UiModel(UUID.randomUUID().toString()), | ||
UiModel(UUID.randomUUID().toString()) | ||
) | ||
every { mockViewModel.uiModels } returns MutableStateFlow(items) | ||
|
||
launchFragment() | ||
fragment.binding.rvHome.adapter?.itemCount shouldBe items.size | ||
} | ||
|
||
@Test | ||
fun `When launching fragment and view model emits first time launch, it displays a toast message`() { | ||
every { mockViewModel.isFirstTimeLaunch } returns MutableStateFlow(true) | ||
|
||
launchFragment() | ||
ShadowToast.getTextOfLatestToast() shouldBe "This is the first time launch" | ||
} | ||
|
||
@Test | ||
fun `When launching fragment and view model does not emit first time launch, it does not display a toast message`() { | ||
every { mockViewModel.isFirstTimeLaunch } returns MutableStateFlow(false) | ||
|
||
launchFragment() | ||
ShadowToast.getTextOfLatestToast() shouldBe null | ||
} | ||
|
||
@Test | ||
fun `When view model emits navigation event to second fragment, it should navigate to second screen`() { | ||
val uiModel = UiModel(UUID.randomUUID().toString()) | ||
every { mockViewModel.navigator } returns MutableStateFlow(NavigationEvent.Second(uiModel)) | ||
every { mockMainNavigator.navigate(any()) } returns Unit | ||
|
||
launchFragment() | ||
verify { mockMainNavigator.navigate(NavigationEvent.Second(uiModel)) } | ||
} | ||
|
||
private fun launchFragment() { | ||
launchFragmentInHiltContainer<HomeFragment>( | ||
onInstantiate = { | ||
replace(getPrivateProperty("viewModel"), mockViewModel) | ||
navigator = mockMainNavigator | ||
} | ||
) { | ||
fragment = this | ||
fragment.navigator.shouldNotBeNull() | ||
} | ||
} | ||
} |
Oops, something went wrong.