Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add detachment test
  • Loading branch information
EmmanuelMess committed Apr 16, 2025
commit bc431ff61b1ea462232c1c51e4113010d69a65d6
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ class TabFragmentTest {
}
}

/**
* This test causes a rotation to happen while the MainFragment detaches, to check if it
* fails. This could happen in reality, but should be very rare
*/
@Test
fun testFragmentStateSavingDuringDetachment() {
activityRule.activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

// Get the TabFragment
InstrumentationRegistry.getInstrumentation().runOnMainSync {
val activity = activityRule.activity
val tabFragment =
activity.supportFragmentManager
.findFragmentById(R.id.content_frame) as TabFragment

// Detach fragment through FragmentManager
activity.supportFragmentManager.beginTransaction().apply {
tabFragment.fragments.forEach { detach(it) }
commit()
}
}
}

/**
* Check if the fragment state is saved correctly during a configuration change
* by rotate the screen while swiping between the tabs.
Expand Down
Loading