Skip to content

Commit

Permalink
Merge pull request #106 from SDP-Rock-Paper-Scissors/fix/quick-fix-is…
Browse files Browse the repository at this point in the history
…sues-firebase

fix
  • Loading branch information
bhvrgav authored May 18, 2022
2 parents b893fc7 + de85fa9 commit ab57db2
Show file tree
Hide file tree
Showing 21 changed files with 502 additions and 263 deletions.
13 changes: 3 additions & 10 deletions app/src/androidTest/java/ch/epfl/sweng/rps/GameButtonsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.epfl.sweng.rps.TestUtils.initializeForTest
import ch.epfl.sweng.rps.db.Env
import ch.epfl.sweng.rps.db.LocalRepository
import ch.epfl.sweng.rps.services.ServiceLocator
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
Expand All @@ -24,16 +20,13 @@ import org.junit.runner.RunWith
@ExperimentalCoroutinesApi
@RunWith(AndroidJUnit4::class)
class GameButtonsTest {
@ExperimentalCoroutinesApi

@get:Rule
val testRule = ActivityScenarioRule(MainActivity::class.java)
val testRule = ActivityScenarioRuleWithSetup.default(MainActivity::class.java)

@Before
fun setUp() {
ServiceLocator.setCurrentEnv(Env.Test)
Firebase.initializeForTest()
val repo = ServiceLocator.getInstance().repository as LocalRepository
repo.setCurrentUid("test")
ServiceLocator.localRepository.setCurrentUid("test")
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import ch.epfl.sweng.rps.db.Env
import ch.epfl.sweng.rps.db.LocalRepository
import ch.epfl.sweng.rps.models.*
import ch.epfl.sweng.rps.models.TotalScore
import ch.epfl.sweng.rps.models.User
import ch.epfl.sweng.rps.services.ServiceLocator
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test

import kotlin.test.assertEquals


class LeaderBoardFragmentTest {
@get:Rule
val testRule = ActivityScenarioRule<MainActivity>(createIntent())
val testRule = ActivityScenarioRuleWithSetup.default<MainActivity>(
createIntent()
)

private fun createIntent(): Intent {
val i = Intent(
Expand Down Expand Up @@ -67,9 +69,10 @@ class LeaderBoardFragmentTest {
)

repo.leaderBoardScore = mutableListOf(
TotalScore("player1",100),
TotalScore("player2",200),
TotalScore("player3",300))
TotalScore("player1", 100),
TotalScore("player2", 200),
TotalScore("player3", 300)
)


}
Expand All @@ -82,7 +85,7 @@ class LeaderBoardFragmentTest {

@Test
fun testEnv() {
assert(ServiceLocator.getCurrentEnv() == Env.Test)
assertEquals(Env.Test, ServiceLocator.getCurrentEnv())
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
package ch.epfl.sweng.rps

import android.content.Intent
import android.os.Bundle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Rule
import org.junit.Test

class LoadingActivityTest {

private fun createIntent(): Intent {
val bundle = Bundle()
bundle.putBoolean("isTest", true)
val intent = Intent(
InstrumentationRegistry.getInstrumentation().targetContext,
LoadingActivity::class.java
)
intent.putExtras(bundle)
intent.putExtra(LoadingActivity.IS_TEST_EXTRA, true)
return intent
}

@get:Rule
val rule =
ActivityScenarioRule<LoadingActivity>(createIntent())
val rule = ActivityScenarioRuleWithSetup.default<LoginActivity>(createIntent())

@Test
fun start() {
Expand Down
15 changes: 7 additions & 8 deletions app/src/androidTest/java/ch/epfl/sweng/rps/LoginPageTest.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package ch.epfl.sweng.rps

import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso.*
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.times
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import ch.epfl.sweng.rps.TestUtils.initializeForTest
import ch.epfl.sweng.rps.persistence.Cache
import ch.epfl.sweng.rps.persistence.PrivateStorage
import ch.epfl.sweng.rps.persistence.Storage
import com.google.firebase.FirebaseApp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.ktx.Firebase
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -36,7 +34,8 @@ class LoginPageTest {
Storage.FILES.USERINFO
)
Intents.init()
Cache.createInstance(InstrumentationRegistry.getInstrumentation().targetContext).updateUserDetails(null)
Cache.createInstance(InstrumentationRegistry.getInstrumentation().targetContext)
.updateUserDetails(null)
scenario = ActivityScenario.launch(LoginActivity::class.java)
}

Expand Down
16 changes: 5 additions & 11 deletions app/src/androidTest/java/ch/epfl/sweng/rps/MainActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,29 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.epfl.sweng.rps.TestUtils.initializeForTest
import com.google.firebase.ktx.Firebase
import org.junit.Before
import ch.epfl.sweng.rps.db.Env
import ch.epfl.sweng.rps.services.ServiceLocator
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals


@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get:Rule
val testRule = ActivityScenarioRule(MainActivity::class.java)

@Before
fun setUp() {
Firebase.initializeForTest()
}
val testRule = ActivityScenarioRuleWithSetup.default(MainActivity::class.java)

@Test
fun checkFirstFragment() {
onView(withId(R.id.fragment_home)).check(matches(isDisplayed()))
}



@Test
fun checkStatistics() {
assertEquals(Env.Test, ServiceLocator.getCurrentEnv())
onView(withId(R.id.nav_statistics)).perform(click())
onView(withId(R.id.fragment_statistics)).check(matches(isDisplayed()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import ch.epfl.sweng.rps.TestUtils.initializeForTest
import ch.epfl.sweng.rps.models.User
import com.google.firebase.ktx.Firebase
import org.junit.Before
import org.junit.Rule
import org.junit.Test

Expand Down Expand Up @@ -45,7 +42,7 @@ class ProfileFragmentTest {
}

@get:Rule
val testRule = ActivityScenarioRule<MainActivity>(createIntent())
val testRule = ActivityScenarioRuleWithSetup.default<MainActivity>(createIntent())
@Test
fun testFields() {
onView(withId(R.id.nav_profile)).perform(click())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import ch.epfl.sweng.rps.TestUtils.getActivityInstance
Expand All @@ -36,7 +35,7 @@ import java.util.concurrent.FutureTask
@RunWith(AndroidJUnit4::class)
class SettingsPageTest {
@get:Rule
val scenarioRule = ActivityScenarioRule(SettingsActivity::class.java)
val scenarioRule = ActivityScenarioRuleWithSetup.default(SettingsActivity::class.java)

private fun computeThemeMap(): List<Map.Entry<String, String>> {
val targetContext = getInstrumentation().targetContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.util.HumanReadables
import androidx.test.espresso.util.TreeIterables
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import ch.epfl.sweng.rps.TestUtils.initializeForTest
import ch.epfl.sweng.rps.db.Env
Expand All @@ -32,7 +31,7 @@ import java.util.concurrent.TimeoutException

class StatisticsFragmentTest {
@get:Rule
val testRule = ActivityScenarioRule<MainActivity>(createIntent())
val testRule = ActivityScenarioRuleWithSetup.default<MainActivity>(createIntent())

private fun createIntent(): Intent {
val i = Intent(
Expand Down
Loading

0 comments on commit ab57db2

Please sign in to comment.