Skip to content

Commit

Permalink
fix progress screen for tracks without projects
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkash committed Oct 31, 2023
1 parent d47c552 commit ecbfc47
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ data class Profile(
val isStaff: Boolean,
@SerialName("track_id")
val trackId: Long?,
@SerialName("project")
val projectId: Long?,
@SerialName("track_title")
val trackTitle: String?,
@SerialName("is_beta")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ internal class ProgressScreenViewStateMapper(
): ProgressScreenViewState.TrackProgressViewState.Content {
val track = trackProgressContent.trackWithProgress.track
val trackProgress = trackProgressContent.trackWithProgress.trackProgress
val isFreemiumUser = trackProgressContent.subscription.isFreemium
val projectsNotAvailable = trackProgressContent.subscription.isFreemium ||
trackProgressContent.profile.projectId == null

return ProgressScreenViewState.TrackProgressViewState.Content(
title = track.title,
imageSource = track.cover?.takeIf { it.isNotBlank() },
completedTopicsCountLabel = "${trackProgress.completedTopics} / ${track.topicsCount}",
completedTopicsPercentageLabel = "${trackProgressContent.trackWithProgress.completedTopicsProgress}%",
completedTopicsPercentageProgress = trackProgressContent.trackWithProgress.completedTopicsProgress / 100f,
appliedTopicsState = if (isFreemiumUser) {
appliedTopicsState = if (projectsNotAvailable) {
AppliedTopicsState.Empty
} else {
AppliedTopicsState.Content(
Expand All @@ -70,7 +71,7 @@ internal class ProgressScreenViewStateMapper(
)
},
timeToCompleteLabel = formatTrackTimeToComplete(trackProgressContent),
completedGraduateProjectsCount = if (isFreemiumUser) {
completedGraduateProjectsCount = if (projectsNotAvailable) {
null
} else {
trackProgress.completedCapstoneProjects.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fun Profile.Companion.stub(
id: Long = 0,
isBeta: Boolean = false,
isGuest: Boolean = false,
trackId: Long? = null
trackId: Long? = 1L,
projectId: Long? = 1L
): Profile =
Profile(
id = id,
Expand All @@ -31,6 +32,7 @@ fun Profile.Companion.stub(
isGuest = isGuest,
isStaff = false,
trackId = trackId,
projectId = projectId,
trackTitle = null,
isBeta = isBeta,
featuresMap = emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,30 @@ class ProgressScreenTest {

assertNull(trackProgressContentState.completedGraduateProjectsCount)
}

@Test
fun `User on track without project doesn't see applied topics and graduated projects`() {
val state = ProgressScreenFeature.State(
trackProgressState = ProgressScreenFeature.TrackProgressState.Content(
trackWithProgress = TrackWithProgress.stub(trackId = 1L),
studyPlan = StudyPlan.stub(),
profile = Profile.stub(projectId = null),
subscription = Subscription.stub()
),
projectProgressState = ProgressScreenFeature.ProjectProgressState.Empty,
isTrackProgressRefreshing = false,
isProjectProgressRefreshing = false
)

val viewState = viewStateMapper.map(state)

val trackProgressContentState = viewState.trackProgressViewState as TrackProgressViewState.Content

assertEquals(
TrackProgressViewState.Content.AppliedTopicsState.Empty,
trackProgressContentState.appliedTopicsState
)

assertNull(trackProgressContentState.completedGraduateProjectsCount)
}
}

0 comments on commit ecbfc47

Please sign in to comment.