From 1e86ed6f62c1397fd9b63461842db4faa8663c03 Mon Sep 17 00:00:00 2001 From: "maxime.zammit" Date: Sat, 19 Mar 2022 00:09:22 +0100 Subject: [PATCH 01/15] deleting greeting activity --- .../java/ch/sdp/vibester/EndToEndTest.kt | 49 ------------------- .../ch/sdp/vibester/GameEndingScreenTest.kt | 22 ++++++--- .../ch/sdp/vibester/GreetingActivityTest.kt | 29 ----------- .../sdp/vibester/IncorrectSongsScreenTest.kt | 2 +- .../ch/sdp/vibester/LyricTemporaryTest.kt | 2 +- .../ch/sdp/vibester/MusicTemporaryTest.kt | 2 +- app/src/main/AndroidManifest.xml | 3 -- .../java/ch/sdp/vibester/GreetingActivity.kt | 23 --------- .../main/java/ch/sdp/vibester/MainActivity.kt | 9 ---- app/src/main/res/layout/activity_greeting.xml | 40 --------------- 10 files changed, 18 insertions(+), 163 deletions(-) delete mode 100644 app/src/androidTest/java/ch/sdp/vibester/EndToEndTest.kt delete mode 100644 app/src/androidTest/java/ch/sdp/vibester/GreetingActivityTest.kt delete mode 100644 app/src/main/java/ch/sdp/vibester/GreetingActivity.kt delete mode 100644 app/src/main/res/layout/activity_greeting.xml diff --git a/app/src/androidTest/java/ch/sdp/vibester/EndToEndTest.kt b/app/src/androidTest/java/ch/sdp/vibester/EndToEndTest.kt deleted file mode 100644 index 39b7218c2..000000000 --- a/app/src/androidTest/java/ch/sdp/vibester/EndToEndTest.kt +++ /dev/null @@ -1,49 +0,0 @@ -package ch.sdp.vibester - -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.closeSoftKeyboard -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.ext.junit.rules.ActivityScenarioRule -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class EndToEndTest { - - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("ch.sdp.vibester", appContext.packageName) - } - - @get:Rule - val testRule = ActivityScenarioRule( - MainActivity::class.java - ) - - - @Test - fun endToEndTest() { - // Context of the app under test. - val name = "SDPUser" - onView(withId(R.id.mainNameInput)).perform(ViewActions.typeText(name), closeSoftKeyboard()) - onView(withId(R.id.mainButton)).perform(click()) - onView(withId(R.id.greetName)).check(matches(withText("Hello $name!"))) - } - -} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/GameEndingScreenTest.kt b/app/src/androidTest/java/ch/sdp/vibester/GameEndingScreenTest.kt index 9c5aa100b..d96ba21cd 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/GameEndingScreenTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/GameEndingScreenTest.kt @@ -1,6 +1,8 @@ package ch.sdp.vibester import android.content.Intent +import android.content.Intent.FLAG_ACTIVITY_NEW_TASK +import androidx.core.content.ContextCompat import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso.onView @@ -56,6 +58,10 @@ class GameEndingScreenTest { @Test fun checkIntentOnCalled() { val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingScreen::class.java) + + //Start an activity from outside an activity + intent.setFlags(FLAG_ACTIVITY_NEW_TASK) + intent.putExtra("playerName", name) intent.putExtra("nbIncorrectSong", nbInc) //intent.putExtra("incorrect_songs", inc) @@ -67,7 +73,9 @@ class GameEndingScreenTest { intent.putExtra("stat_1", "Hello there") intent.putExtra("stat_res_1", "General Kenobi") - val scn: ActivityScenario = ActivityScenario.launch(intent) + + //keep this val to help kotlin inferring value type + val uselessVal: ActivityScenario = ActivityScenario.launch(intent) onView(withId(R.id.end_stat1)).check(matches(withText(stats[0]))) onView(withId(R.id.end_stat1_res)).check(matches(withText(statsRes[0]))) @@ -77,25 +85,25 @@ class GameEndingScreenTest { @Test fun checkIntentOnIncorrectSongs() { val intent = Intent(ApplicationProvider.getApplicationContext(), GameEndingScreen::class.java) + intent.putExtra("playerName", name) intent.putExtra("nbIncorrectSong", nbInc) - //intent.putExtra("incorrect_songs", inc) - //intent.putExtra("Stat_names", stats) - //intent.putExtra("Stat_values", statsRes) intent.putExtra("incorrect_song_1", "One") intent.putExtra("incorrect_song_2", "Two") intent.putExtra("incorrect_song_3", "Three") intent.putExtra("stat_1", "Hello There") intent.putExtra("stat_res_1", "General Kenobi") - val scn: ActivityScenario = ActivityScenario.launch(intent) + + //keep this val to help kotlin inferring value type + val uselessVal: ActivityScenario = ActivityScenario.launch(intent) onView(withId(R.id.end_go_to_inc)).perform(click()) + + intended(hasComponent(IncorrectSongsScreen::class.java.name)) intended(hasExtra("nb_false", nbInc)) - //intended(hasExtra("incorrect_songs", inc)) intended(hasExtra("incorrect_song_1", inc[0])) intended(hasExtra("incorrect_song_2", inc[1])) intended(hasExtra("incorrect_song_3", inc[2])) - intended(hasComponent(IncorrectSongsScreen::class.java.name)) } } \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/GreetingActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/GreetingActivityTest.kt deleted file mode 100644 index 9f114d0c7..000000000 --- a/app/src/androidTest/java/ch/sdp/vibester/GreetingActivityTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package ch.sdp.vibester - -import android.content.Intent -import androidx.test.core.app.ActivityScenario -import androidx.test.core.app.ApplicationProvider -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.ext.junit.rules.ActivityScenarioRule -import androidx.test.ext.junit.runners.AndroidJUnit4 -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class GreetingActivityTest { - - @Test - fun mainTest(){ - val inputName = "SDPUser" - val intent = Intent(ApplicationProvider.getApplicationContext(), GreetingActivity::class.java) - intent.putExtra("name", inputName) - val scn: ActivityScenario = ActivityScenario.launch(intent) - onView(withId(R.id.greetName)).check(matches(withText("Hello $inputName!"))) - } - - -} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/IncorrectSongsScreenTest.kt b/app/src/androidTest/java/ch/sdp/vibester/IncorrectSongsScreenTest.kt index d6d0bc223..0e8bbf833 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/IncorrectSongsScreenTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/IncorrectSongsScreenTest.kt @@ -43,7 +43,7 @@ class IncorrectSongsScreenTest { intent.putExtra("nbIncorrectSong", nbInc) intent.putExtra("incorrect_songs", inc) - val scn: ActivityScenario = ActivityScenario.launch(intent) + val scn: ActivityScenario = ActivityScenario.launch(intent) if(nbInc != 0) { for(x in 0 until nbInc) { diff --git a/app/src/androidTest/java/ch/sdp/vibester/LyricTemporaryTest.kt b/app/src/androidTest/java/ch/sdp/vibester/LyricTemporaryTest.kt index d7153e5d6..1e3a3de65 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/LyricTemporaryTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/LyricTemporaryTest.kt @@ -60,7 +60,7 @@ class LyricTemporaryTest { val intent = Intent( ApplicationProvider.getApplicationContext(), LyricTemporary::class.java ) - val scn: ActivityScenario = ActivityScenario.launch(intent) + val scn: ActivityScenario = ActivityScenario.launch(intent) onView(withId(R.id.artistForLyric)).perform(typeText(inputArtistName), closeSoftKeyboard()) onView(withId(R.id.trackForLyric)).perform(typeText(inputTrackName), closeSoftKeyboard()) onView(withId(R.id.validateForLyric)).perform(click()) diff --git a/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt b/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt index ef861edfd..e761fbe10 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt @@ -21,7 +21,7 @@ class MusicTemporaryTest{ val inputName = "Imagine Dragons Believer" val intent = Intent(ApplicationProvider.getApplicationContext(), MusicTemporary::class.java) - val scn: ActivityScenario = ActivityScenario.launch(intent) + val scn: ActivityScenario = ActivityScenario.launch(intent) onView(withId(R.id.musicName)) .perform(typeText(inputName), closeSoftKeyboard()) onView(withId(R.id.validateForMusic)).perform(click()) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 44d2adb97..717622b1e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -47,9 +47,6 @@ - diff --git a/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt b/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt deleted file mode 100644 index 3b87fec7e..000000000 --- a/app/src/main/java/ch/sdp/vibester/GreetingActivity.kt +++ /dev/null @@ -1,23 +0,0 @@ -package ch.sdp.vibester - -import android.os.Bundle -import android.util.Log -import android.widget.TextView -import androidx.appcompat.app.AppCompatActivity - -class GreetingActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_greeting) - - val textViewActivity = findViewById(R.id.greetName) - - val getIntent = intent.extras - val name: String = getIntent?.get("name") as String - - Log.d("NameGet: ", name) - - textViewActivity.text = "Hello $name!" - - } -} \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/MainActivity.kt b/app/src/main/java/ch/sdp/vibester/MainActivity.kt index d992a5a69..249ebbe6c 100644 --- a/app/src/main/java/ch/sdp/vibester/MainActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/MainActivity.kt @@ -15,15 +15,6 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - val txtInput = findViewById(R.id.mainNameInput) - - val btnGreeting = findViewById