Skip to content

Commit

Permalink
Merge pull request #158 from DroidKaigi/yamada-ika/add-staff-screen
Browse files Browse the repository at this point in the history
Add Staff Screen
  • Loading branch information
takahirom authored Jul 28, 2024
2 parents 41ef278 + cffc4e8 commit 04261a2
Show file tree
Hide file tree
Showing 18 changed files with 519 additions and 10 deletions.
1 change: 1 addition & 0 deletions app-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ dependencies {
implementation(projects.feature.eventmap)
implementation(projects.feature.profilecard)
implementation(projects.feature.about)
implementation(projects.feature.staff)
implementation(projects.core.model)
implementation(projects.core.data)
implementation(projects.core.designsystem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import io.github.droidkaigi.confsched.sessions.nestedSessionScreens
import io.github.droidkaigi.confsched.sessions.sessionScreens
import io.github.droidkaigi.confsched.sessions.timetableScreenRoute
import io.github.droidkaigi.confsched.share.ShareNavigator
import io.github.droidkaigi.confsched.staff.staffScreenRoute
import io.github.droidkaigi.confsched.staff.staffScreens
import io.github.droidkaigi.confsched.ui.NavHostWithSharedAxisX
import io.github.droidkaigi.confshed.profilecard.navigateProfileCardScreen
import io.github.droidkaigi.confshed.profilecard.profileCardScreen
Expand Down Expand Up @@ -103,6 +105,11 @@ private fun KaigiNavHost(
onNavigationIconClick = navController::popBackStack,
onContributorItemClick = externalNavController::navigate,
)

staffScreens(
onNavigationIconClick = navController::popBackStack,
onStaffItemClick = externalNavController::navigate,
)
}
}

Expand Down Expand Up @@ -153,7 +160,7 @@ private fun NavGraphBuilder.mainScreen(
)
}

AboutItem.Staff -> TODO()
AboutItem.Staff -> navController.navigate(staffScreenRoute)
AboutItem.X -> externalNavController.navigate(
url = "https://twitter.com/DroidKaigi",
)
Expand Down
1 change: 1 addition & 0 deletions app-ios-shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ kotlin {
api(projects.feature.contributors)
api(projects.feature.profilecard)
api(projects.feature.about)
api(projects.feature.staff)
implementation(libs.kotlinxCoroutinesCore)
implementation(libs.skieAnnotation)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package io.github.droidkaigi.confsched.data.staff

import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap
import io.github.droidkaigi.confsched.data.di.RepositoryQualifier
import io.github.droidkaigi.confsched.model.StaffRepository
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
public class StaffRepositoryModule {
public abstract class StaffRepositoryModule {
@Binds
@RepositoryQualifier
@IntoMap
@ClassKey(StaffRepository::class)
public abstract fun bind(repository: StaffRepository): Any

@Provides
@Singleton
public fun provideStaffRepository(
staffApi: StaffApiClient,
): StaffRepository {
return DefaultStaffRepository(
staffApi = staffApi,
)
public companion object {
@Provides
@Singleton
public fun provideStaffRepository(
staffApi: StaffApiClient,
): StaffRepository {
return DefaultStaffRepository(
staffApi = staffApi,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.github.droidkaigi.confsched.data.staff

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import io.github.droidkaigi.confsched.compose.SafeLaunchedEffect
import io.github.droidkaigi.confsched.compose.safeCollectAsRetainedState
import io.github.droidkaigi.confsched.model.Staff
import io.github.droidkaigi.confsched.model.StaffRepository
import kotlinx.collections.immutable.PersistentList
Expand Down Expand Up @@ -28,4 +32,15 @@ public class DefaultStaffRepository(
.getStaff()
.toPersistentList()
}

@Composable
override fun staff(): PersistentList<Staff> {
val staff by staffsStateFlow.safeCollectAsRetainedState()
SafeLaunchedEffect(Unit) {
if (staff.isEmpty()) {
refresh()
}
}
return staff
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.droidkaigi.confsched.model

import androidx.compose.runtime.Composable
import io.github.droidkaigi.confsched.model.compositionlocal.LocalRepositories
import kotlinx.collections.immutable.PersistentList
import kotlinx.coroutines.flow.Flow
import kotlin.coroutines.cancellation.CancellationException
Expand All @@ -10,4 +12,12 @@ interface StaffRepository {

@Throws(CancellationException::class)
public suspend fun refresh()

@Composable
fun staff(): PersistentList<Staff>
}

@Composable
fun localStaffRepository(): StaffRepository {
return LocalRepositories.current[StaffRepository::class] as StaffRepository
}
1 change: 1 addition & 0 deletions core/testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
implementation(projects.feature.sessions)
implementation(projects.feature.profilecard)
implementation(projects.feature.about)
implementation(projects.feature.staff)
implementation(libs.daggerHiltAndroidTesting)
implementation(libs.roborazzi)
implementation(libs.kermit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import io.github.droidkaigi.confsched.data.eventmap.EventMapApiClient
import io.github.droidkaigi.confsched.data.eventmap.FakeEventMapApiClient
import io.github.droidkaigi.confsched.data.sessions.FakeSessionsApiClient
import io.github.droidkaigi.confsched.data.sessions.SessionsApiClient
import io.github.droidkaigi.confsched.data.staff.FakeStaffApiClient
import io.github.droidkaigi.confsched.data.staff.StaffApiClient
import io.github.droidkaigi.confsched.testing.coroutines.runTestWithLogging
import kotlinx.coroutines.test.TestDispatcher
import org.robolectric.RuntimeEnvironment
Expand Down Expand Up @@ -195,3 +197,25 @@ class DefaultEventMapServerRobot @Inject constructor(contributorsApiClient: Even
)
}
}

interface StaffServerRobot {
enum class ServerStatus {
Operational,
Error,
}

fun setupStaffServer(serverStatus: ServerStatus)
}

class DefaultStaffServerRobot @Inject constructor(staffApiClient: StaffApiClient) :
StaffServerRobot {
private val fakeStaffApiClient = staffApiClient as FakeStaffApiClient
override fun setupStaffServer(serverStatus: StaffServerRobot.ServerStatus) {
fakeStaffApiClient.setup(
when (serverStatus) {
StaffServerRobot.ServerStatus.Operational -> FakeStaffApiClient.Status.Operational
StaffServerRobot.ServerStatus.Error -> FakeStaffApiClient.Status.Error
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.droidkaigi.confsched.testing.robot

import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.staff.StaffScreen
import io.github.droidkaigi.confsched.testing.DefaultScreenRobot
import io.github.droidkaigi.confsched.testing.DefaultStaffServerRobot
import io.github.droidkaigi.confsched.testing.ScreenRobot
import io.github.droidkaigi.confsched.testing.StaffServerRobot
import javax.inject.Inject

class StaffScreenRobot @Inject constructor(
private val screenRobot: DefaultScreenRobot,
private val staffServerRobot: DefaultStaffServerRobot,
) : ScreenRobot by screenRobot,
StaffServerRobot by staffServerRobot {
suspend fun setupScreenContent() {
robotTestRule.setContent {
KaigiTheme {
StaffScreen(
onNavigationIconClick = { },
onStaffItemClick = { },
)
}
}
waitUntilIdle()
}
}
1 change: 1 addition & 0 deletions feature/staff/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
24 changes: 24 additions & 0 deletions feature/staff/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id("droidkaigi.convention.kmpfeature")
}

android.namespace = "io.github.droidkaigi.confsched.feature.staff"
roborazzi.generateComposePreviewRobolectricTests.packages = listOf("io.github.droidkaigi.confsched.staff")
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(projects.core.model)
implementation(projects.core.ui)
implementation(libs.kotlinxCoroutinesCore)
implementation(projects.core.designsystem)
implementation(libs.moleculeRuntime)
}
}
androidUnitTest {
dependencies {
implementation(projects.core.testing)
}
}
}
}
21 changes: 21 additions & 0 deletions feature/staff/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.github.droidkaigi.confsched.staff

import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.droidkaigi.confsched.testing.DescribedBehavior
import io.github.droidkaigi.confsched.testing.RobotTestRule
import io.github.droidkaigi.confsched.testing.StaffServerRobot.ServerStatus.Error
import io.github.droidkaigi.confsched.testing.StaffServerRobot.ServerStatus.Operational
import io.github.droidkaigi.confsched.testing.describeBehaviors
import io.github.droidkaigi.confsched.testing.execute
import io.github.droidkaigi.confsched.testing.robot.StaffScreenRobot
import io.github.droidkaigi.confsched.testing.runRobot
import io.github.droidkaigi.confsched.testing.todoChecks
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import javax.inject.Inject

@RunWith(ParameterizedRobolectricTestRunner::class)
@HiltAndroidTest
class StaffScreenTest(
private val testCase: DescribedBehavior<StaffScreenRobot>,
) {
@get:Rule
@BindValue val robotTestRule: RobotTestRule = RobotTestRule(testInstance = this)

@Inject
lateinit var staffScreenRobot: StaffScreenRobot

@Test
fun runTest() {
runRobot(staffScreenRobot) {
testCase.execute(staffScreenRobot)
}
}

companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters(name = "{0}")
fun behaviors(): List<DescribedBehavior<StaffScreenRobot>> {
return describeBehaviors<StaffScreenRobot>(name = "StaffScreen") {
describe("when server is operational") {
run {
setupStaffServer(Operational)
}
describe("when launch") {
run {
setupScreenContent()
}
itShould("show staff screen") {
captureScreenWithChecks(
checks = todoChecks("This screen is still empty now. Please add some checks."),
)
}
}
}

describe("when server is down") {
run {
setupStaffServer(Error)
}
describe("when launch") {
run {
setupScreenContent()
}
itShould("show snackbar") {
captureScreenWithChecks(
checks = todoChecks("This screen is still empty now. Please add some checks."),
)
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sdk=34
# RobolectricDeviceQualifiers.NexusOne
qualifiers=w320dp-h533dp-normal-long-notround-any-hdpi-keyshidden-trackball

application=dagger.hilt.android.testing.HiltTestApplication
# https://github.com/robolectric/robolectric/issues/6593
instrumentedPackages=androidx.loader.content
Loading

0 comments on commit 04261a2

Please sign in to comment.