Rename hasDismissedOnboarding to shouldHideOnboarding

Change-Id: I8a6b35f7216f9944652d8da346e7458614311e08
pull/406/head
Don Turner 3 years ago
parent 6654403498
commit 5b8c284c74

@ -51,6 +51,6 @@ class OfflineFirstUserDataRepository @Inject constructor(
override suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig) = override suspend fun setDarkThemeConfig(darkThemeConfig: DarkThemeConfig) =
niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig) niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig)
override suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) = override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) =
niaPreferencesDataSource.setHasDismissedOnboarding(hasDismissedOnboarding) niaPreferencesDataSource.setShouldHideOnboarding(shouldHideOnboarding)
} }

@ -66,5 +66,5 @@ interface UserDataRepository {
/** /**
* Sets whether the user has completed the onboarding process. * Sets whether the user has completed the onboarding process.
*/ */
suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean)
} }

@ -64,7 +64,7 @@ class FakeUserDataRepository @Inject constructor(
niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig) niaPreferencesDataSource.setDarkThemeConfig(darkThemeConfig)
} }
override suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) { override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) {
niaPreferencesDataSource.setHasDismissedOnboarding(hasDismissedOnboarding) niaPreferencesDataSource.setShouldHideOnboarding(shouldHideOnboarding)
} }
} }

@ -59,7 +59,7 @@ class OfflineFirstUserDataRepositoryTest {
followedAuthors = emptySet(), followedAuthors = emptySet(),
themeBrand = ThemeBrand.DEFAULT, themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM, darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
hasDismissedOnboarding = false shouldHideOnboarding = false
), ),
subject.userDataStream.first() subject.userDataStream.first()
) )
@ -190,13 +190,13 @@ class OfflineFirstUserDataRepositoryTest {
} }
@Test @Test
fun whenUserCompletesOnboarding_thenRemovesAllInterests_hasDismissedOnboardingIsFalse() = fun whenUserCompletesOnboarding_thenRemovesAllInterests_shouldHideOnboardingIsFalse() =
runTest { runTest {
subject.setFollowedTopicIds(setOf("1")) subject.setFollowedTopicIds(setOf("1"))
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
subject.setFollowedTopicIds(emptySet()) subject.setFollowedTopicIds(emptySet())
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
} }
} }

@ -53,7 +53,7 @@ class NiaPreferencesDataSource @Inject constructor(
DarkThemeConfig.LIGHT DarkThemeConfig.LIGHT
DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK DarkThemeConfigProto.DARK_THEME_CONFIG_DARK -> DarkThemeConfig.DARK
}, },
hasDismissedOnboarding = it.hasDismissedOnboarding shouldHideOnboarding = it.shouldHideOnboarding
) )
} }
@ -63,7 +63,7 @@ class NiaPreferencesDataSource @Inject constructor(
it.copy { it.copy {
followedTopicIds.clear() followedTopicIds.clear()
followedTopicIds.putAll(topicIds.associateWith { true }) followedTopicIds.putAll(topicIds.associateWith { true })
updateHasDismissedOnboardingIfNecessary() updateShouldHideOnboardingIfNecessary()
} }
} }
} catch (ioException: IOException) { } catch (ioException: IOException) {
@ -80,7 +80,7 @@ class NiaPreferencesDataSource @Inject constructor(
} else { } else {
followedTopicIds.remove(topicId) followedTopicIds.remove(topicId)
} }
updateHasDismissedOnboardingIfNecessary() updateShouldHideOnboardingIfNecessary()
} }
} }
} catch (ioException: IOException) { } catch (ioException: IOException) {
@ -94,7 +94,7 @@ class NiaPreferencesDataSource @Inject constructor(
it.copy { it.copy {
followedAuthorIds.clear() followedAuthorIds.clear()
followedAuthorIds.putAll(authorIds.associateWith { true }) followedAuthorIds.putAll(authorIds.associateWith { true })
updateHasDismissedOnboardingIfNecessary() updateShouldHideOnboardingIfNecessary()
} }
} }
} catch (ioException: IOException) { } catch (ioException: IOException) {
@ -111,7 +111,7 @@ class NiaPreferencesDataSource @Inject constructor(
} else { } else {
followedAuthorIds.remove(authorId) followedAuthorIds.remove(authorId)
} }
updateHasDismissedOnboardingIfNecessary() updateShouldHideOnboardingIfNecessary()
} }
} }
} catch (ioException: IOException) { } catch (ioException: IOException) {
@ -194,18 +194,18 @@ class NiaPreferencesDataSource @Inject constructor(
} }
} }
suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) { suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) {
userPreferences.updateData { userPreferences.updateData {
it.copy { it.copy {
this.hasDismissedOnboarding = hasDismissedOnboarding this.shouldHideOnboarding = shouldHideOnboarding
} }
} }
} }
} }
fun UserPreferencesKt.Dsl.updateHasDismissedOnboardingIfNecessary() { fun UserPreferencesKt.Dsl.updateShouldHideOnboardingIfNecessary() {
if (followedTopicIds.isEmpty() && followedAuthorIds.isEmpty()) { if (followedTopicIds.isEmpty() && followedAuthorIds.isEmpty()) {
hasDismissedOnboarding = false shouldHideOnboarding = false
} }
} }

@ -44,8 +44,5 @@ message UserPreferences {
ThemeBrandProto theme_brand = 16; ThemeBrandProto theme_brand = 16;
DarkThemeConfigProto dark_theme_config = 17; DarkThemeConfigProto dark_theme_config = 17;
// Note that proto3 only allows a default value of `false` for boolean types. This means that bool should_hide_onboarding = 18;
// whilst the name `should_show_onboarding` would be preferable here we are forced to choose a
// name which works with this default value constraint.
bool has_dismissed_onboarding = 18;
} }

@ -39,99 +39,99 @@ class NiaPreferencesDataSourceTest {
} }
@Test @Test
fun hasDismissedOnboardingIsFalseByDefault() = runTest { fun shouldHideOnboardingIsFalseByDefault() = runTest {
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboardingIsTrueWhenSet() = runTest { fun userShouldHideOnboardingIsTrueWhenSet() = runTest {
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboarding_unfollowsLastAuthor_hasDismissedOnboardingIsFalse() = runTest { fun userShouldHideOnboarding_unfollowsLastAuthor_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting a single author. // Given: user completes onboarding by selecting a single author.
subject.toggleFollowedAuthorId("1", true) subject.toggleFollowedAuthorId("1", true)
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow that author. // When: they unfollow that author.
subject.toggleFollowedAuthorId("1", false) subject.toggleFollowedAuthorId("1", false)
// Then: onboarding should be shown again // Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboarding_unfollowsLastTopic_hasDismissedOnboardingIsFalse() = runTest { fun userShouldHideOnboarding_unfollowsLastTopic_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting a single topic. // Given: user completes onboarding by selecting a single topic.
subject.toggleFollowedTopicId("1", true) subject.toggleFollowedTopicId("1", true)
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow that topic. // When: they unfollow that topic.
subject.toggleFollowedTopicId("1", false) subject.toggleFollowedTopicId("1", false)
// Then: onboarding should be shown again // Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboarding_unfollowsAllAuthors_hasDismissedOnboardingIsFalse() = runTest { fun userShouldHideOnboarding_unfollowsAllAuthors_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting several authors. // Given: user completes onboarding by selecting several authors.
subject.setFollowedAuthorIds(setOf("1", "2")) subject.setFollowedAuthorIds(setOf("1", "2"))
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow those authors. // When: they unfollow those authors.
subject.setFollowedAuthorIds(emptySet()) subject.setFollowedAuthorIds(emptySet())
// Then: onboarding should be shown again // Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboarding_unfollowsAllTopics_hasDismissedOnboardingIsFalse() = runTest { fun userShouldHideOnboarding_unfollowsAllTopics_shouldHideOnboardingIsFalse() = runTest {
// Given: user completes onboarding by selecting several topics. // Given: user completes onboarding by selecting several topics.
subject.setFollowedTopicIds(setOf("1", "2")) subject.setFollowedTopicIds(setOf("1", "2"))
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow those topics. // When: they unfollow those topics.
subject.setFollowedTopicIds(emptySet()) subject.setFollowedTopicIds(emptySet())
// Then: onboarding should be shown again // Then: onboarding should be shown again
assertEquals(false, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(false, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboarding_unfollowsAllTopicsButNotAuthors_hasDismissedOnboardingIsTrue() = fun userShouldHideOnboarding_unfollowsAllTopicsButNotAuthors_shouldHideOnboardingIsTrue() =
runTest { runTest {
// Given: user completes onboarding by selecting several topics and authors. // Given: user completes onboarding by selecting several topics and authors.
subject.setFollowedTopicIds(setOf("1", "2")) subject.setFollowedTopicIds(setOf("1", "2"))
subject.setFollowedAuthorIds(setOf("3", "4")) subject.setFollowedAuthorIds(setOf("3", "4"))
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow just the topics. // When: they unfollow just the topics.
subject.setFollowedTopicIds(emptySet()) subject.setFollowedTopicIds(emptySet())
// Then: onboarding should still be dismissed // Then: onboarding should still be dismissed
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
} }
@Test @Test
fun userHasDismissedOnboarding_unfollowsAllAuthorsButNotTopics_hasDismissedOnboardingIsTrue() = fun userShouldHideOnboarding_unfollowsAllAuthorsButNotTopics_shouldHideOnboardingIsTrue() =
runTest { runTest {
// Given: user completes onboarding by selecting several topics and authors. // Given: user completes onboarding by selecting several topics and authors.
subject.setFollowedTopicIds(setOf("1", "2")) subject.setFollowedTopicIds(setOf("1", "2"))
subject.setFollowedAuthorIds(setOf("3", "4")) subject.setFollowedAuthorIds(setOf("3", "4"))
subject.setHasDismissedOnboarding(true) subject.setShouldHideOnboarding(true)
// When: they unfollow just the authors. // When: they unfollow just the authors.
subject.setFollowedAuthorIds(emptySet()) subject.setFollowedAuthorIds(emptySet())
// Then: onboarding should still be dismissed // Then: onboarding should still be dismissed
assertEquals(true, subject.userDataStream.first().hasDismissedOnboarding) assertEquals(true, subject.userDataStream.first().shouldHideOnboarding)
} }
} }

@ -25,5 +25,5 @@ data class UserData(
val followedAuthors: Set<String>, val followedAuthors: Set<String>,
val themeBrand: ThemeBrand, val themeBrand: ThemeBrand,
val darkThemeConfig: DarkThemeConfig, val darkThemeConfig: DarkThemeConfig,
val hasDismissedOnboarding: Boolean val shouldHideOnboarding: Boolean
) )

@ -31,7 +31,7 @@ private val emptyUserData = UserData(
followedAuthors = emptySet(), followedAuthors = emptySet(),
themeBrand = ThemeBrand.DEFAULT, themeBrand = ThemeBrand.DEFAULT,
darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM, darkThemeConfig = DarkThemeConfig.FOLLOW_SYSTEM,
hasDismissedOnboarding = false shouldHideOnboarding = false
) )
class TestUserDataRepository : UserDataRepository { class TestUserDataRepository : UserDataRepository {
@ -91,9 +91,9 @@ class TestUserDataRepository : UserDataRepository {
} }
} }
override suspend fun setHasDismissedOnboarding(hasDismissedOnboarding: Boolean) { override suspend fun setShouldHideOnboarding(shouldHideOnboarding: Boolean) {
currentUserData.let { current -> currentUserData.let { current ->
_userData.tryEmit(current.copy(hasDismissedOnboarding = hasDismissedOnboarding)) _userData.tryEmit(current.copy(shouldHideOnboarding = shouldHideOnboarding))
} }
} }

@ -48,7 +48,7 @@ class ForYouViewModel @Inject constructor(
) : ViewModel() { ) : ViewModel() {
private val shouldShowOnboarding: Flow<Boolean> = private val shouldShowOnboarding: Flow<Boolean> =
userDataRepository.userDataStream.map { !it.hasDismissedOnboarding } userDataRepository.userDataStream.map { !it.shouldHideOnboarding }
val isSyncing = syncStatusMonitor.isSyncing val isSyncing = syncStatusMonitor.isSyncing
.stateIn( .stateIn(
@ -63,7 +63,7 @@ class ForYouViewModel @Inject constructor(
// If the user hasn't completed the onboarding and hasn't selected any interests // If the user hasn't completed the onboarding and hasn't selected any interests
// show an empty news list to clearly demonstrate that their selections affect the // show an empty news list to clearly demonstrate that their selections affect the
// news articles they will see. // news articles they will see.
if (!userData.hasDismissedOnboarding && if (!userData.shouldHideOnboarding &&
userData.followedAuthors.isEmpty() && userData.followedAuthors.isEmpty() &&
userData.followedTopics.isEmpty() userData.followedTopics.isEmpty()
) { ) {
@ -126,7 +126,7 @@ class ForYouViewModel @Inject constructor(
fun dismissOnboarding() { fun dismissOnboarding() {
viewModelScope.launch { viewModelScope.launch {
userDataRepository.setHasDismissedOnboarding(true) userDataRepository.setShouldHideOnboarding(true)
} }
} }
} }

@ -1011,7 +1011,7 @@ class ForYouViewModelTest {
userDataRepository.setFollowedTopicIds(setOf("1")) userDataRepository.setFollowedTopicIds(setOf("1"))
authorsRepository.sendAuthors(sampleAuthors) authorsRepository.sendAuthors(sampleAuthors)
userDataRepository.setFollowedAuthorIds(setOf("1")) userDataRepository.setFollowedAuthorIds(setOf("1"))
userDataRepository.setHasDismissedOnboarding(true) userDataRepository.setShouldHideOnboarding(true)
newsRepository.sendNewsResources(sampleNewsResources) newsRepository.sendNewsResources(sampleNewsResources)
viewModel.updateNewsResourceSaved("2", true) viewModel.updateNewsResourceSaved("2", true)

Loading…
Cancel
Save