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
// Nested conditions (BAD IDEA) | |
fun logTeamMembers(teamMembers: List<String>) { | |
if (teamMembers.isEmpty()) { | |
Log.d("TAG", "It's empty") | |
} else if (teamMembers.size == 1) { | |
if (teamMembers.first() == "foo") { | |
Log.d("TAG", "The only member is foo") | |
} else { | |
Log.d("TAG", "The only member is not foo") | |
} |
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
@Composable | |
private fun FilterIcon(modifier: Modifier, onClick: () -> Unit) { | |
Box(modifier) { | |
IconButton( | |
onClick = onClick | |
) { | |
Image( | |
painter = painterResource(R.drawable.ic_filter), | |
contentDescription = "Filter Button" | |
) |
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
private val dialogFilterButton by lazy { | |
composeTestRule.onNodeWithContentDescription("Filter Button") | |
} | |
@Test | |
fun elementsVisibilityAfterOpeningTheMainScreen() { | |
setMainContent() | |
dialogFilterButton.assertIsDisplayed() | |
} | |
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
android { | |
defaultConfig { | |
applicationId = "prieto.fernando.sample" | |
testInstrumentationRunner = "prieto.fernando.sample.webmock.MockTestRunner" | |
} | |
buildFeatures { | |
compose = true | |
viewBinding = true | |
} | |
// rest of configuration |
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
class MockTestRunner : AndroidJUnitRunner() { | |
override fun onCreate(arguments: Bundle?) { | |
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build()) | |
super.onCreate(arguments) | |
} | |
override fun newApplication( | |
cl: ClassLoader?, | |
className: String?, | |
context: Context? |
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
@Module | |
@TestInstallIn( | |
components = [SingletonComponent::class], | |
replaces = [NetworkModule::class] | |
) | |
class FakeNetworkModule : NetworkModule() { | |
override fun getBaseUrl() = "http://127.0.0.1:${BuildConfig.PORT}" | |
} |
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
@InstallIn(SingletonComponent::class) | |
@Module | |
open class NetworkModule { | |
open fun getBaseUrl () ="https://api.spacexdata.com/v3/" | |
@Provides | |
@BaseUrl | |
fun provideBaseUrl() = getBaseUrl () |
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
val mockWebServer by lazy { MockWebServer() } | |
@Before | |
fun setUp() { | |
mockWebServer.start(BuildConfig.PORT) | |
} | |
@After | |
fun teardown() { | |
mockWebServer.shutdown() |
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
@ExperimentalMaterialApi | |
@RunWith(AndroidJUnit4::class) | |
@HiltAndroidTest | |
class LaunchesScreenKtTest : BaseScreenTest() { | |
@Test | |
@InternalCoroutinesApi | |
fun visibleItemsCountAfterOpeningTheScreen() { | |
mockWebServer.dispatcher = SuccessDispatcher() | |
setMainContent() |
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
@Test | |
@InternalCoroutinesApi | |
fun elementsVisibilityAfterTwoItemsRetrieved() { | |
composeTestRule.apply { | |
setContent { | |
SpaceXTheme { | |
LaunchesScreen( | |
state = LaunchesContract.State( | |
listOf( | |
LaunchUiModel( |