This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d93cccf
commit a741482
Showing
32 changed files
with
505 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
-dontnote | ||
|
||
-keepattributes *Annotation*, EnclosingMethod, InnerClasses, Signature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
-dontobfuscate | ||
|
||
-include proguard-rules-common.pro | ||
|
||
-keepattributes SourceFile, LineNumberTable | ||
|
||
-keep class androidx.fragment.app.testing.** { *; } | ||
|
||
-keep class androidx.test.core.app.ActivityScenario { *; } | ||
-keep class androidx.test.internal.platform.** { *; } | ||
-keep class androidx.test.internal.runner.** { *; } | ||
-keep class androidx.test.platform.** { *; } | ||
-keep class androidx.test.runner.** { *; } | ||
|
||
-keep class androidx.navigation.NavHostController { | ||
createDeepLink(); | ||
setNavigatorProvider(...); | ||
} | ||
|
||
-keep class androidx.navigation.NavDeepLinkBuilder { | ||
createTaskStackBuilder(...); | ||
setArguments(...); | ||
setDestination(...); | ||
} | ||
|
||
-keep class kotlin.jvm.internal.Intrinsics { | ||
checkParameterIsNotNull(...); | ||
checkExpressionValueIsNotNull(...); | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/androidTest/java/com/isupatches/android/viewglu/sample/FragmentBoundTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021 Patches Klinefelter | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.isupatches.android.viewglu.sample | ||
|
||
import androidx.fragment.app.testing.FragmentScenario | ||
import androidx.fragment.app.testing.launchFragmentInContainer | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.isupatches.android.viewglu.sample.testobjects.BaseRobot | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class FragmentBoundTest { | ||
|
||
@Test | ||
fun displays() { | ||
val scenario = launchFragmentInContainer<FragmentBound>(themeResId = R.style.AppTheme) | ||
scenario | ||
.boundScreen { | ||
checkTextIsDisplayed(R.string.bound_fragment_text) | ||
} | ||
} | ||
} | ||
|
||
private fun FragmentScenario<FragmentBound>.boundScreen( | ||
block: BoundFragmentRobot.() -> Unit | ||
) = BoundFragmentRobot().apply { block() } | ||
|
||
private class BoundFragmentRobot : BaseRobot() |
42 changes: 42 additions & 0 deletions
42
app/src/androidTest/java/com/isupatches/android/viewglu/sample/FragmentInflatedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021 Patches Klinefelter | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.isupatches.android.viewglu.sample | ||
|
||
import androidx.fragment.app.testing.FragmentScenario | ||
import androidx.fragment.app.testing.launchFragmentInContainer | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.isupatches.android.viewglu.sample.testobjects.BaseRobot | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
internal class FragmentInflatedTest { | ||
|
||
@Test | ||
fun displays() { | ||
val scenario = launchFragmentInContainer<FragmentInflated>(themeResId = R.style.AppTheme) | ||
scenario | ||
.inflatedScreen { | ||
checkTextIsDisplayed(R.string.inflated_fragment_text) | ||
} | ||
} | ||
} | ||
|
||
private fun FragmentScenario<FragmentInflated>.inflatedScreen( | ||
block: InflatedFragmentRobot.() -> Unit | ||
) = InflatedFragmentRobot().apply { block() } | ||
|
||
private class InflatedFragmentRobot : BaseRobot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...droidTest/java/com/isupatches/android/viewglu/sample/testobjects/ViewPagerInteractions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2021 Patches Klinefelter | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.isupatches.android.viewglu.sample.testobjects | ||
|
||
import android.view.View | ||
import androidx.core.view.ViewCompat | ||
import androidx.test.espresso.UiController | ||
import androidx.test.espresso.ViewAction | ||
import androidx.test.espresso.action.ViewActions.swipeDown | ||
import androidx.test.espresso.action.ViewActions.swipeLeft | ||
import androidx.test.espresso.action.ViewActions.swipeRight | ||
import androidx.test.espresso.action.ViewActions.swipeUp | ||
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom | ||
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA | ||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.isupatches.android.viewglu.sample.testobjects.SwipeAction.Direction.BACKWARD | ||
import com.isupatches.android.viewglu.sample.testobjects.SwipeAction.Direction.FORWARD | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.Matchers.allOf | ||
import org.hamcrest.Matchers.anyOf | ||
|
||
/** | ||
* ViewAction that issues a swipe gesture on a [ViewPager2] to move that ViewPager2 to the next | ||
* page, taking orientation and layout direction into account. | ||
*/ | ||
fun swipeNext(): ViewAction { | ||
return SwipeAction(FORWARD) | ||
} | ||
|
||
/** | ||
* ViewAction that issues a swipe gesture on a [ViewPager2] to move that ViewPager2 to the previous | ||
* page, taking orientation and layout direction into account. | ||
*/ | ||
fun swipePrevious(): ViewAction { | ||
return SwipeAction(BACKWARD) | ||
} | ||
|
||
private class SwipeAction(val direction: Direction) : ViewAction { | ||
enum class Direction { | ||
FORWARD, | ||
BACKWARD | ||
} | ||
|
||
override fun getDescription(): String = "Swiping $direction" | ||
|
||
override fun getConstraints(): Matcher<View> = | ||
allOf( | ||
anyOf( | ||
isAssignableFrom(ViewPager2::class.java), | ||
isDescendantOfA(isAssignableFrom(ViewPager2::class.java)) | ||
), | ||
isDisplayingAtLeast(90) | ||
) | ||
|
||
override fun perform(uiController: UiController, view: View) { | ||
val vp = if (view is ViewPager2) { | ||
view | ||
} else { | ||
var parent = view.parent | ||
while (parent !is ViewPager2 && parent != null) { | ||
parent = parent.parent | ||
} | ||
parent as ViewPager2 | ||
} | ||
val isForward = direction == FORWARD | ||
val swipeAction: ViewAction = if (vp.orientation == ViewPager2.ORIENTATION_HORIZONTAL) { | ||
if (isForward == vp.isRtl()) swipeRight() else swipeLeft() | ||
} else { | ||
if (isForward) swipeUp() else swipeDown() | ||
} | ||
swipeAction.perform(uiController, view) | ||
} | ||
|
||
private fun ViewPager2.isRtl(): Boolean { | ||
return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.