Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3930 Greeting text on home screen should be a single TextView #5131

Merged
merged 16 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ class WelcomeViewModel(
dateTimeUtil: DateTimeUtil
) : HomeItemViewModel() {

/** Text [String] to greet the learner and display on-screen when launching the home activity. */
/** Text [String] to greet the learner. */
val greeting: String = dateTimeUtil.getGreetingMessage()

/**
* Returns the user-readable portion of the welcome screen greeting that contains the user's name.
* Returns the string which contains greeting message with user's name and
* display on-screen when launching the home activity.
*/
fun computeProfileNameText(): String {
return resourceHandler.getStringInLocaleWithWrapping(R.string.welcome_profile_name, profileName)
}
fun computeWelcomeText(): String = resourceHandler.getStringInLocaleWithWrapping(
R.string.welcome_profile_name,
greeting,
profileName
)

// Overriding equals is needed so that DataProvider combine functions used in the HomeViewModel
// will only rebind when the actual data in the data list changes, rather than when the ViewModel
Expand Down
11 changes: 1 addition & 10 deletions app/src/main/res/layout/welcome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/home_welcome_text_view_margin_end"
android:fontFamily="sans-serif"
android:text="@{viewModel.greeting}"
android:textColor="@color/component_color_shared_primary_text_color"
android:textSize="24sp" />

<TextView
android:id="@+id/profile_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="@{viewModel.computeProfileNameText()}"
android:text="@{viewModel.computeWelcomeText}"
android:textColor="@color/component_color_shared_primary_text_color"
android:textSize="24sp" />
</com.google.android.flexbox.FlexboxLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<string name="size_gb">%s GB</string>
<string name="correct">Correct!</string>
<string name="topic_prefix">Topic: %s</string>
<string name="welcome_profile_name">%s!</string>
<string name="welcome_profile_name">%s %s!</string>
<plurals name="chapter_count">
<item quantity="one">1 Chapter</item>
<item quantity="other">%s Chapters</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,6 @@ class HomeActivityTest {
assertThat(screenName).isEqualTo(ScreenName.HOME_ACTIVITY)
}

@Test
fun testHomeActivity_withAdminProfile_profileNameIsDisplayed() {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.profile_name_text_view,
stringToMatch = "Admin!"
)
}
}

@Test
fun testHomeActivity_hasCorrectActivityLabel() {
launch(HomeActivity::class.java).use { scenario ->
Expand All @@ -271,59 +258,61 @@ class HomeActivityTest {

@Test
fun testHomeActivity_withAdminProfile_configChange_profileNameIsDisplayed() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(EVENING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.profile_name_text_view,
stringToMatch = "Admin!"
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good evening, Admin!"
ShubhadeepKarmakar marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

@Test
fun testHomeActivity_morningTimestamp_goodMorningMessageIsDisplayed() {
fun testHomeActivity_morningTimestamp_goodMorningMessageIsDisplayed_withAdminProfileName() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(MORNING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId1)).use {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good morning,"
stringToMatch = "Good morning, Admin!"
)
}
}

@Test
fun testHomeActivity_afternoonTimestamp_goodAfternoonMessageIsDisplayed() {
fun testHomeActivity_afternoonTimestamp_goodAfternoonMessageIsDisplayed_withAdminProfileName() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(AFTERNOON_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId1)).use {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good afternoon,"
stringToMatch = "Good afternoon, Admin!"
)
}
}

@Test
fun testHomeActivity_eveningTimestamp_goodEveningMessageIsDisplayed() {
fun testHomeActivity_eveningTimestamp_goodEveningMessageIsDisplayed_withAdminProfileName() {
fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME)
fakeOppiaClock.setCurrentTimeToSameDateTime(EVENING_TIMESTAMP)
launch<HomeActivity>(createHomeActivityIntent(internalProfileId1)).use {
launch<HomeActivity>(createHomeActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
scrollToPosition(position = 0)
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good evening,"
stringToMatch = "Good evening, Admin!"
)
}
}
Expand Down Expand Up @@ -1094,7 +1083,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand All @@ -1113,7 +1102,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand All @@ -1131,7 +1120,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand All @@ -1150,7 +1139,7 @@ class HomeActivityTest {
atPositionOnView(
R.id.home_recycler_view,
0,
R.id.profile_name_text_view
R.id.welcome_text_view
)
).check(matches(not(isEllipsized())))
}
Expand Down Expand Up @@ -1574,7 +1563,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Good morning,"
stringToMatch = "Good morning, Admin!"
)
}
}
Expand Down Expand Up @@ -1634,7 +1623,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Bom dia,"
stringToMatch = "Bom dia, Admin!"
)
assertThat(testActivityRecreator.getRecreateCount()).isEqualTo(1)
// Verify that the display locale is set up correctly (for string formatting).
Expand Down Expand Up @@ -1664,7 +1653,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "صباح الخير"
stringToMatch = "صباح الخير \u200F\u202AAdmin\u202C\u200F!"
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down Expand Up @@ -1734,7 +1723,7 @@ class HomeActivityTest {
verifyExactTextOnHomeListItemAtPosition(
itemPosition = 0,
targetViewId = R.id.welcome_text_view,
stringToMatch = "Bom dia,"
stringToMatch = "Bom dia, Admin!"
)
}
}
Expand Down
Loading