Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JhonnySalles committed Jul 22, 2022
2 parents 90652ed + 14f0091 commit 5bf6b0a
Show file tree
Hide file tree
Showing 110 changed files with 4,248 additions and 1,527 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/captures
.externalNativeBuild
.cxx
local.properties
local.properties
8 changes: 5 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "br.com.fenix.bilingualmangareader"
minSdk 26
targetSdk 31
versionCode 11
versionName "2.11"
versionCode 13
versionName "2.13"
archivesBaseName = "BilingualManga_" + versionName

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -76,6 +76,23 @@ dependencies {
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
implementation 'com.github.tony19:logback-android:2.0.0'

// OCR
implementation 'cz.adaptech:tesseract4android:4.1.1'
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:18.0.0'

// MANGA INFO
implementation 'com.kttdevelopment:mal4j:2.8.1'

// TEST
testImplementation 'junit:junit:4.13.2'
androidTestImplementation "androidx.test:core:1.4.0"
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test:rules:1.2.0"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.ext:truth:1.4.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.4.0"
androidTestImplementation "androidx.test.espresso:espresso-intents:3.4.0"


}
6 changes: 3 additions & 3 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 11,
"versionName": "2.11",
"outputFile": "BilingualManga_2.11-release.apk"
"versionCode": 13,
"versionName": "2.13",
"outputFile": "BilingualManga_2.13-release.apk"
}
],
"elementType": "File"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
package br.com.fenix.bilingualmangareader

import android.content.res.Resources
import android.view.Gravity
import android.view.KeyEvent
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.DrawerActions
import androidx.test.espresso.contrib.DrawerMatchers.isClosed
import androidx.test.espresso.contrib.NavigationViewActions
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import br.com.fenix.bilingualmangareader.view.ui.about.AboutFragment
import br.com.fenix.bilingualmangareader.view.ui.configuration.ConfigFragment
import br.com.fenix.bilingualmangareader.view.ui.help.HelpFragment
import br.com.fenix.bilingualmangareader.view.ui.history.HistoryFragment
import br.com.fenix.bilingualmangareader.view.ui.library.LibraryFragment
import junit.framework.TestCase.assertTrue
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit


@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(AndroidJUnit4::class)
class MainActivityTest {

@get:Rule
var activityScenarioRule: ActivityScenario<MainActivity> = ActivityScenario.launch(MainActivity::class.java)

private val animationTimer = 600L

@Test
fun `1_open_screens_in_app`() {
val waiter = CountDownLatch(1)

// History
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.START)))
.perform(DrawerActions.open())

onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.menu_history))

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is HistoryFragment)
}

// Configuration
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.START)))
.perform(DrawerActions.open())

onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.menu_configuration))

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is ConfigFragment)
}

// Help
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.START)))
.perform(DrawerActions.open())

onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.menu_help))

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is HelpFragment)
}

// About
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.START)))
.perform(DrawerActions.open())

onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.menu_about))

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is AboutFragment)
}

// Library
onView(withId(R.id.drawer_layout))
.check(matches(isClosed(Gravity.START)))
.perform(DrawerActions.open())

onView(withId(R.id.nav_view))
.perform(NavigationViewActions.navigateTo(R.id.menu_library))

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is LibraryFragment)
}

pressBack()

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is AboutFragment)
}

pressBack()

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is HelpFragment)
}

pressBack()

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is ConfigFragment)
}

pressBack()

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is HistoryFragment)
}

pressBack()

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val fragment = it.supportFragmentManager.findFragmentById(R.id.main_content_root)
assertTrue(fragment is LibraryFragment)
}
}


@Test
fun `2_test_in_library`() {
val waiter = CountDownLatch(1)
activityScenarioRule.recreate() // Re load app

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

onView(withId(R.id.menu_library_grid_type)).perform(click())

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

onView(withId(R.id.menu_library_grid_type)).perform(click())

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

onView(withId(R.id.menu_library_grid_type)).perform(click())

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

onView(withId(R.id.menu_library_list_order)).perform(click())

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

onView(withId(R.id.menu_library_list_order)).perform(click())

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

onView(withId(R.id.menu_library_list_order)).perform(click())

waiter.await(animationTimer, TimeUnit.MILLISECONDS)

activityScenarioRule.onActivity {
val recyclerView = it.findViewById<RecyclerView>(R.id.library_recycler_view)
val itemCount = recyclerView.adapter?.itemCount ?: 0

recyclerView.smoothScrollToPosition(itemCount)

waiter.await(2, TimeUnit.SECONDS)

recyclerView.smoothScrollToPosition(0)

waiter.await(2, TimeUnit.SECONDS)
}

onView(withId(R.id.menu_library_search)).perform(click())

onView(
withId(
Resources.getSystem().getIdentifier(
"search_src_text",
"id", "android"
)
)
).perform(clearText(), typeText("Test"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER))

onView(
withId(
Resources.getSystem().getIdentifier(
"search_src_text",
"id", "android"
)
)
).perform(clearText())
.perform(pressKey(KeyEvent.KEYCODE_ENTER))

onView(
withId(
Resources.getSystem().getIdentifier(
"search_close_btn",
"id", "android"
)
)
).perform(click())

onView(
withId(
Resources.getSystem().getIdentifier(
"search_close_btn",
"id", "android"
)
)
).perform(closeSoftKeyboard())
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package br.com.fenix.bilingualmangareader.custom

import android.view.View
import androidx.annotation.DrawableRes
import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.test.espresso.matcher.BoundedMatcher
import com.google.android.material.button.MaterialButton
import org.hamcrest.Description
import org.hamcrest.Matcher


object CustomMatchers {
object Button {
fun withActionIconDrawable(@DrawableRes resourceId: Int, ignoreColor: Boolean = false): Matcher<View?> {
return object : BoundedMatcher<View?, MaterialButton>(MaterialButton::class.java) {
override fun describeTo(description: Description) {
description.appendText("has image drawable resource $resourceId")
}

override fun matchesSafely(buttonView: MaterialButton): Boolean {
return CustomUtils.sameBitmap(
buttonView.context,
buttonView.icon,
resourceId,
buttonView,
ignoreColor
)
}
}
}
}

object MenuItem {
fun withActionIconDrawable(@DrawableRes resourceId: Int, ignoreColor: Boolean = false): Matcher<View?> {
return object : BoundedMatcher<View?, ActionMenuItemView>(ActionMenuItemView::class.java) {
override fun describeTo(description: Description) {
description.appendText("has image drawable resource $resourceId")
}

override fun matchesSafely(actionMenuItemView: ActionMenuItemView): Boolean {
return CustomUtils.sameBitmap(
actionMenuItemView.context,
actionMenuItemView.itemData.icon,
resourceId,
actionMenuItemView,
ignoreColor
)
}
}
}
}
}
Loading

0 comments on commit 5bf6b0a

Please sign in to comment.