shared: Add top app bar composable to reflect different active services
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
parent
dfc3f4b9f3
commit
0f2bbf11ff
11 changed files with 453 additions and 2 deletions
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.composable
|
||||
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.v2.runComposeUiTest
|
||||
import com.russhwolf.settings.MapSettings
|
||||
import com.russhwolf.settings.Settings
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
import net.newpipe.app.extensions.withKoin
|
||||
import newpipe.shared.generated.resources.Res
|
||||
import newpipe.shared.generated.resources.app_name
|
||||
import newpipe.shared.generated.resources.navigate_back
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import org.koin.dsl.module
|
||||
|
||||
@OptIn(ExperimentalTestApi::class)
|
||||
class TopAppBarTest {
|
||||
|
||||
private val emptySettings = module {
|
||||
single<Settings> { MapSettings() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTopAppBarHasNoNavigationByDefault() = runComposeUiTest {
|
||||
withKoin(
|
||||
modules = listOf(emptySettings),
|
||||
content = {
|
||||
TopAppBar()
|
||||
},
|
||||
onContent = {
|
||||
onNodeWithContentDescription(getString(Res.string.navigate_back))
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTopAppBarCanHaveNavigation() = runComposeUiTest {
|
||||
var navigationBackClicked = false
|
||||
withKoin(
|
||||
modules = listOf(emptySettings),
|
||||
content = {
|
||||
TopAppBar(
|
||||
title = stringResource(Res.string.app_name),
|
||||
onNavigateUp = { navigationBackClicked = true }
|
||||
)
|
||||
},
|
||||
onContent = {
|
||||
onNodeWithText(getString(Res.string.app_name)).assertIsDisplayed()
|
||||
onNodeWithContentDescription(getString(Res.string.navigate_back)).apply {
|
||||
assertExists()
|
||||
performClick()
|
||||
assertTrue(navigationBackClicked)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.extensions
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.test.ComposeUiTest
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import org.koin.compose.KoinApplication
|
||||
import org.koin.core.context.stopKoin
|
||||
import org.koin.core.logger.Level
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.dsl.koinConfiguration
|
||||
|
||||
/**
|
||||
* Sets the content for the UI test wrapped inside Koin
|
||||
* @param modules Modules for Koin to init for the composables
|
||||
* @param content Composable content for testing
|
||||
* @param onContent Non-composable code for testing, maybe dependent upon composable code
|
||||
*/
|
||||
@OptIn(ExperimentalTestApi::class)
|
||||
inline fun ComposeUiTest.withKoin(
|
||||
modules: List<Module>,
|
||||
noinline content: @Composable () -> Unit = {},
|
||||
onContent: () -> Unit = {}
|
||||
) {
|
||||
try {
|
||||
setContent {
|
||||
KoinApplication(
|
||||
configuration = koinConfiguration {
|
||||
modules(modules)
|
||||
},
|
||||
logLevel = Level.DEBUG,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
onContent()
|
||||
} finally {
|
||||
stopKoin()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.theme
|
||||
|
||||
import androidx.compose.ui.test.ExperimentalTestApi
|
||||
import androidx.compose.ui.test.v2.runComposeUiTest
|
||||
import com.russhwolf.settings.MapSettings
|
||||
import com.russhwolf.settings.Settings
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
import net.newpipe.app.Constants.KEY_STREAMING_SERVICE
|
||||
import net.newpipe.app.extensions.withKoin
|
||||
import org.koin.dsl.module
|
||||
|
||||
@OptIn(ExperimentalTestApi::class)
|
||||
class ServiceThemeTest {
|
||||
|
||||
@Test
|
||||
fun testDefaultServiceIsYouTube() = runComposeUiTest {
|
||||
val emptySettings = module {
|
||||
single<Settings> { MapSettings() }
|
||||
}
|
||||
|
||||
withKoin(
|
||||
modules = listOf(emptySettings),
|
||||
content = {
|
||||
assertEquals(currentService(), Service.YOUTUBE)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testServiceSwitchingWorks() = runComposeUiTest {
|
||||
val settings = module {
|
||||
single<Settings> {
|
||||
MapSettings(KEY_STREAMING_SERVICE to "PeerTube")
|
||||
}
|
||||
}
|
||||
|
||||
withKoin(
|
||||
modules = listOf(settings),
|
||||
content = {
|
||||
assertNotEquals(currentService(), Service.YOUTUBE)
|
||||
assertEquals(currentService(), Service.PEERTUBE)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue