Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/JMaio/Coinz
Browse files Browse the repository at this point in the history
  • Loading branch information
JMaio committed Dec 21, 2018
2 parents d082840 + f9d19ff commit 00cfb1b
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 95 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ The coin collection game around The University of Edinburgh
## Author:
Joao Maio\
s1621503

## Testing environment
The app was tested using API 26 (Oreo 8.0) on an emulated Pixel 2 XL device

multiDex was enabled since it solved some compilation errors that would otherwise prevent building

This file was deleted.

104 changes: 47 additions & 57 deletions app/src/androidTest/java/io/github/jmaio/coinz/LoginActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ package io.github.jmaio.coinz
import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import androidx.test.runner.AndroidJUnit4
import org.hamcrest.Description
import org.hamcrest.Matcher
Expand All @@ -26,63 +27,51 @@ class LoginActivityTest {
@JvmField
var mActivityTestRule = ActivityTestRule(LoginActivity::class.java)

@Rule
@JvmField
var mGrantPermissionRule =
GrantPermissionRule.grant(
"android.permission.ACCESS_FINE_LOCATION")

@Test
fun loginActivityTest() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(3000)

val appCompatAutoCompleteTextView = onView(
allOf(withId(R.id.email),
childAtPosition(
childAtPosition(
withId(R.id.email_input_field),
0),
0),
isDisplayed()))
appCompatAutoCompleteTextView.perform(click())
Thread.sleep(1000)

val appCompatAutoCompleteTextView2 = onView(
allOf(withId(R.id.email),
childAtPosition(
childAtPosition(
withId(R.id.email_input_field),
0),
0),
isDisplayed()))
appCompatAutoCompleteTextView2.perform(replaceText("user"), closeSoftKeyboard())

// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(1000)

val appCompatEditText = onView(
allOf(withId(R.id.login_password),
childAtPosition(
childAtPosition(
withId(R.id.password_input_field),
0),
0),
isDisplayed()))
Thread.sleep(1000)
appCompatEditText.perform(replaceText("hello"), closeSoftKeyboard())

// pressBack()
Thread.sleep(1000)

val materialButton = onView(
allOf(withId(R.id.email_sign_in_button), withText("Sign in"),
childAtPosition(
allOf(withId(R.id.login_form),
childAtPosition(
withId(android.R.id.content),
0)),
4),
isDisplayed()))
materialButton.perform(click())
if (mActivityTestRule.activity.user == null) {
Thread.sleep(4000)

val appCompatAutoCompleteTextView = onView(
allOf(withId(R.id.email_input),
childAtPosition(
childAtPosition(
withId(R.id.email_input_field),
0),
0)))
appCompatAutoCompleteTextView.perform(scrollTo(), replaceText("[email protected]"), closeSoftKeyboard())

Thread.sleep(500)

val appCompatEditText = onView(
allOf(withId(R.id.password_input),
childAtPosition(
childAtPosition(
withId(R.id.password_input_field),
0),
0)))
appCompatEditText.perform(scrollTo(), replaceText("123456"), closeSoftKeyboard())

Thread.sleep(500)

val materialButton = onView(
allOf(withId(R.id.sign_in_button), withText("Sign in"),
childAtPosition(
childAtPosition(
withId(R.id.login_form),
4),
1)))
materialButton.perform(scrollTo(), click())

Thread.sleep(500)
}

}

private fun childAtPosition(
Expand All @@ -101,4 +90,5 @@ class LoginActivityTest {
}
}
}

}
50 changes: 50 additions & 0 deletions app/src/androidTest/java/io/github/jmaio/coinz/LogoutTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.jmaio.coinz


import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import androidx.test.runner.AndroidJUnit4
import com.google.android.material.internal.NavigationMenu
import com.google.android.material.internal.NavigationMenuItemView
import com.google.android.material.navigation.NavigationView
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class LogoutTest {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)

@Rule
@JvmField
var mGrantPermissionRule =
GrantPermissionRule.grant(
"android.permission.ACCESS_FINE_LOCATION")

@Test
fun logoutTest() {
Thread.sleep(3000)
onView(withId(R.id.user_id_chip)).perform(click())

Thread.sleep(2000)
onView(withText("OK")).perform(click())

Thread.sleep(2000)
}

}
64 changes: 64 additions & 0 deletions app/src/androidTest/java/io/github/jmaio/coinz/MainActivityTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.github.jmaio.coinz


import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import androidx.test.runner.AndroidJUnit4
import com.google.android.material.internal.NavigationMenu
import com.google.android.material.internal.NavigationMenuItemView
import com.google.android.material.navigation.NavigationView
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {

@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)

@Rule
@JvmField
var mGrantPermissionRule =
GrantPermissionRule.grant(
"android.permission.ACCESS_FINE_LOCATION")

@Test
fun mainActivityTest() {
if (mActivityTestRule.activity.user != null) {

Thread.sleep(3000)
onView(withId(R.id.fab)).perform(click())

Thread.sleep(2000)
pressBack()

Thread.sleep(2000)
onView(withId(R.id.app_bar_leaderboard)).perform(click())

Thread.sleep(2000)
pressBack()

Thread.sleep(2000)
onView(withContentDescription("Navigate up")).perform(click())

Thread.sleep(2000)
pressBack()

Thread.sleep(2000)
}
}
}
30 changes: 16 additions & 14 deletions app/src/main/java/io/github/jmaio/coinz/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ class MainActivity : AppCompatActivity(), AnkoLogger, LocationEngineListener {
private var penySource: GeoJsonSource? = null
private var geoJsonSources = mutableMapOf<String, GeoJsonSource?>()

private lateinit var auth: FirebaseAuth
private lateinit var db: FirebaseFirestore
private lateinit var user: FirebaseUser
// Initialize Firebase Auth
private var auth = FirebaseAuth.getInstance()
private var db = FirebaseFirestore.getInstance().apply {
firestoreSettings = FirebaseFirestoreSettings.Builder()
.setTimestampsInSnapshotsEnabled(true)
.build()
}
val user = auth.currentUser

private var wallet = Wallet()
private var walletStore = WalletStore()
private var userDisplay = "defaultUser"
Expand All @@ -73,13 +79,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger, LocationEngineListener {
@SuppressLint("MissingPermission")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Initialize Firebase Auth
auth = FirebaseAuth.getInstance()
db = FirebaseFirestore.getInstance().apply {
firestoreSettings = FirebaseFirestoreSettings.Builder()
.setTimestampsInSnapshotsEnabled(true)
.build()
}

// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.mapbox_access_token))
Expand Down Expand Up @@ -175,12 +175,11 @@ class MainActivity : AppCompatActivity(), AnkoLogger, LocationEngineListener {
super.onStart()
// set currently signed-in user and display it
auth.currentUser.let { u ->
if (u != null)
user = u
u?.email.let { e ->
if (e != null)
if (e != null) {
userDisplay = e
user_id_chip.text = e
}
user_id_chip.text = userDisplay
}
}

Expand Down Expand Up @@ -264,6 +263,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger, LocationEngineListener {
}

// get this user's wallet as a basis for populating the map
if (user != null)
walletStore.getWallet(user) { w ->
wallet = w
if (!sameDate) {
Expand Down Expand Up @@ -347,6 +347,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger, LocationEngineListener {

private fun createOnClickListeners() {
fab.setOnClickListener {
if (user != null)
walletStore.getWallet(user) { w ->
wallet = w
startActivity(Intent(this, WalletActivity::class.java)
Expand All @@ -357,6 +358,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger, LocationEngineListener {
}

bottom_app_bar.setNavigationOnClickListener {
if (user != null)
walletStore.getWallet(user) { w ->
wallet = w
startActivity(Intent(this, BankActivity::class.java)
Expand Down

0 comments on commit 00cfb1b

Please sign in to comment.