1+ package com.nmc.android
2+
3+ import android.content.Intent
4+ import android.os.Looper
5+ import androidx.test.espresso.Espresso.onView
6+ import androidx.test.espresso.assertion.ViewAssertions.matches
7+ import androidx.test.espresso.intent.rule.IntentsTestRule
8+ import androidx.test.espresso.matcher.ViewMatchers.isClickable
9+ import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
10+ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
11+ import androidx.test.espresso.matcher.ViewMatchers.withId
12+ import androidx.test.platform.app.InstrumentationRegistry
13+ import com.google.android.material.bottomsheet.BottomSheetBehavior
14+ import com.google.android.material.bottomsheet.BottomSheetDialog
15+ import com.nextcloud.client.device.DeviceInfo
16+ import com.owncloud.android.AbstractIT
17+ import com.owncloud.android.R
18+ import com.owncloud.android.datamodel.OCFile
19+ import com.owncloud.android.ui.activity.FileDisplayActivity
20+ import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions
21+ import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialogFragment
22+ import org.hamcrest.CoreMatchers.not
23+ import org.junit.Before
24+ import org.junit.Rule
25+ import org.junit.Test
26+ import org.mockito.Mock
27+ import org.mockito.MockitoAnnotations
28+
29+ class ScanbotIT : AbstractIT () {
30+
31+ @Mock
32+ private lateinit var actions: OCFileListBottomSheetActions
33+
34+ @get:Rule
35+ var activityRule = IntentsTestRule (FileDisplayActivity ::class .java, true , false )
36+
37+ @Before
38+ fun setUp () {
39+ MockitoAnnotations .initMocks(this )
40+ }
41+
42+ @Test
43+ fun validateScanButton () {
44+ // Looper to avoid android.util.AndroidRuntimeException: Animators may only be run on Looper threads
45+ // during running test
46+ if (Looper .myLooper() == null ) {
47+ Looper .prepare()
48+ }
49+
50+ val intent = Intent (targetContext, FileDisplayActivity ::class .java)
51+ val fda = activityRule.launchActivity(intent)
52+ val info = DeviceInfo ()
53+ val ocFile = OCFile (" /test.md" )
54+
55+ val sut = OCFileListBottomSheetDialogFragment (
56+ fda,
57+ actions,
58+ info,
59+ user,
60+ ocFile
61+ )
62+
63+ sut.show(fda.supportFragmentManager, " " )
64+
65+ InstrumentationRegistry .getInstrumentation().waitForIdleSync()
66+ shortSleep()
67+
68+ (sut.requireDialog() as BottomSheetDialog ).behavior.state = BottomSheetBehavior .STATE_EXPANDED
69+
70+ // validate nmc scan button visibility & clickable
71+ onView(withId(R .id.menu_scan_document)).check(matches(isCompletelyDisplayed()))
72+ onView(withId(R .id.menu_scan_document)).check(matches(isClickable()))
73+
74+ // validate nc scan button hidden
75+ onView(withId(R .id.menu_scan_doc_upload)).check(matches(not (isDisplayed())))
76+
77+ InstrumentationRegistry .getInstrumentation().waitForIdleSync()
78+ shortSleep()
79+ }
80+ }
0 commit comments