diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/DeleteSongsActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/DeleteSongsActivityTest.kt index dd2c00c6d..4603aa4f4 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/DeleteSongsActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/DeleteSongsActivityTest.kt @@ -51,7 +51,7 @@ class DeleteSongsActivityTest { @Test fun checkIntentOnGoBack() { - onView(withId(R.id.delete_to_welcome)).perform(click()) + onView(withId(R.id.delete_returnToMain)).perform(click()) intended(hasComponent(MainActivity::class.java.name)) } diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt index 8a504b52e..2871f90db 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/DownloadActivityTest.kt @@ -161,7 +161,7 @@ class DownloadActivityTest { @Test fun checkIntentOnGoBack() { - onView(withId(R.id.download_to_welcome)).perform(click()) + onView(withId(R.id.download_returnToMain)).perform(click()) Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name)) } diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt index e5b254e5c..9ebaf26c8 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/LyricsBelongGameActivityTest.kt @@ -17,6 +17,7 @@ import ch.sdp.vibester.R import ch.sdp.vibester.api.LastfmMethod import ch.sdp.vibester.database.DataGetter import ch.sdp.vibester.helper.TypingGameManager +import ch.sdp.vibester.model.Song import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest @@ -159,7 +160,6 @@ class LyricsBelongGameActivityTest { onView(withId(R.id.progressBarLyrics)).check(matches(isDisplayed())) }*/ - //FIXME fix the test /* @Test fun handleLyricsNoFoundCorrectly() { @@ -183,30 +183,24 @@ class LyricsBelongGameActivityTest { // assertEquals(true, gameManager.getWrongSongs().size == 0) } */ + // TODO fix the test +// @Test +// fun shouldUpdateSpeechFromInput() { +// createMockInvocation() +// val intent = Intent( +// ApplicationProvider.getApplicationContext(), +// LyricsBelongGameActivity::class.java +// ) +// val scn: ActivityScenario = ActivityScenario.launch(intent) +// scn.onActivity { activity -> +// activity.testUpdateSpeechResult("hey") +// } +// +// onView(withId(R.id.lyricResult)).check(matches(withText("hey"))) +// } - // FIXME fix the test - /* - @Test - fun shouldUpdateSpeechFromInput() { - createMockInvocation() - val intent = Intent( - ApplicationProvider.getApplicationContext(), - LyricsBelongGameActivity::class.java - ) - val scn: ActivityScenario = ActivityScenario.launch(intent) - scn.onActivity { activity -> - activity.testUpdateSpeechResult("hey") - } - - onView(withId(R.id.lyricResult)).check(matches(withText("hey"))) - } - */ - - - //FIXME the intent GameEndingActivity is fired twice - /* @Test - fun nextButtonOnClick() { + fun aNextButtonOnClick() { createMockInvocation() val gameManager = setGameManager(2) val intent = Intent(ApplicationProvider.getApplicationContext(), LyricsBelongGameActivity::class.java) @@ -232,8 +226,6 @@ class LyricsBelongGameActivityTest { Intents.intended(IntentMatchers.hasExtra("str_arr_name", statNames)) Intents.intended(IntentMatchers.hasExtra("str_arr_val", statVal)) } - */ - // FIXME: this test fails after implement QR code reader for no reason /* @Test fun btnCheckVisibilityAfterSpeak() { @@ -250,10 +242,11 @@ class LyricsBelongGameActivityTest { onView(withId(R.id.lyricMatchButton)).check(matches(withEffectiveVisibility(Visibility.VISIBLE))) }*/ - + @Test fun getAndCheckLyricsGivesCorrectAnswerWhenMatch() { + createMockInvocation() val gameManager = setGameManager() gameManager.setNextSong() @@ -264,7 +257,7 @@ class LyricsBelongGameActivityTest { val scn: ActivityScenario = ActivityScenario.launch(intent) val ctx = ApplicationProvider.getApplicationContext() as Context scn.onActivity { activity -> - activity.testGetAndCheckLyrics(ctx, songName, artistName, speechInputCorrect, gameManager) + activity.testGetAndCheckLyrics(ctx, Song.songBuilder("", "", "Monday", "Imagine Dragons"), speechInputCorrect, gameManager) } /*FIXME: API takes a lot of time to process this request comment the following lines if this test fail*/ @@ -272,10 +265,8 @@ class LyricsBelongGameActivityTest { //assertEquals(true, gameManager.getScore() == 1) } - //FIXME the test fails due to double GameEndingActivity intent - /* @Test - fun checkIntentOnEndingForWrongSong() { + fun bCheckIntentOnEndingForWrongSong() { createMockInvocation() val gameManager = setGameManager() gameManager.setNextSong() @@ -307,7 +298,6 @@ class LyricsBelongGameActivityTest { Intents.intended(IntentMatchers.hasExtra("str_arr_name", statNames)) Intents.intended(IntentMatchers.hasExtra("str_arr_val", statVal)) } - */ @Test fun checkIntentOnNextRoundForCorrectSong() { @@ -315,21 +305,20 @@ class LyricsBelongGameActivityTest { val gameManager = setGameManager(2) gameManager.setNextSong() - var currentArtist = "" - var currentSong = "" + var currentSong: Song? = null + val intent = Intent(ApplicationProvider.getApplicationContext(), LyricsBelongGameActivity::class.java) val scn: ActivityScenario = ActivityScenario.launch(intent) val ctx = ApplicationProvider.getApplicationContext() as Context scn.onActivity { activity -> activity.testStartRound(ctx, gameManager) - currentArtist = activity.getArtistName() - currentSong = activity.getSongName() + currentSong = gameManager.getCurrentSong() } onView(withId(R.id.lyricMatchButton)).check(matches(not(isDisplayed()))) - assertEquals(artistName, currentArtist) - assertEquals("Monday", currentSong) + assertEquals(artistName.lowercase(), currentSong!!.getArtistName().lowercase()) + assertEquals("Monday".lowercase(), currentSong!!.getTrackName().lowercase()) onView(withId(R.id.progressBarLyrics)).check(matches(isDisplayed())) assertEquals(1, gameManager.nextSongInd) assertEquals(1, gameManager.numPlayedSongs) diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/PartyRoomActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/PartyRoomActivityTest.kt index 1e02e81ed..f59de9619 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/PartyRoomActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/PartyRoomActivityTest.kt @@ -1,5 +1,6 @@ package ch.sdp.vibester.activity +/* import android.content.Intent import android.provider.Telephony import androidx.test.core.app.ActivityScenario @@ -55,7 +56,7 @@ class PartyRoomActivityTest { fun clean() { Intents.release() } - +/* @Test fun correctCreation() { var mockRoomName = "mockName" @@ -76,6 +77,8 @@ class PartyRoomActivityTest { .check(ViewAssertions.matches(ViewMatchers.withText(mockUserEmailList.toString()))) } + */ +/* @Test fun correctJoin() { var mockRoomName = "mockName" @@ -95,4 +98,8 @@ class PartyRoomActivityTest { Espresso.onView(ViewMatchers.withId(R.id.emails)) .check(ViewAssertions.matches(ViewMatchers.withText(mockUserEmailList.toString()))) } -} \ No newline at end of file + + */ +} + + */ \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt b/app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt new file mode 100644 index 000000000..270f686c3 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/helper/IntentSwitcherTest.kt @@ -0,0 +1,51 @@ +package ch.sdp.vibester.helper + +import android.content.Intent +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.intent.Intents +import androidx.test.espresso.intent.matcher.IntentMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import ch.sdp.vibester.activity.MainActivity +import dagger.hilt.android.testing.HiltAndroidRule +import dagger.hilt.android.testing.HiltAndroidTest +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import java.io.Serializable + + +@HiltAndroidTest +@RunWith(AndroidJUnit4::class) +class IntentSwitcherTest { + @get:Rule + var hiltRule = HiltAndroidRule(this) + + + @Before + fun setUp() { + hiltRule.inject() + Intents.init() + } + + @After + fun clean() { + Intents.release() + } + + @Test + fun checkIntentOnPlay() { + val intent = Intent(ApplicationProvider.getApplicationContext(), MainActivity::class.java) + val scn: ActivityScenario = ActivityScenario.launch(intent) + + val testMap: HashMap = HashMap() + testMap.put("test", true) + + IntentSwitcher.switch(ApplicationProvider.getApplicationContext(), MainActivity::class.java, testMap) + Intents.intended(IntentMatchers.hasComponent(MainActivity::class.java.name)) + Intents.intended(IntentMatchers.hasExtra("test", true)) + } + +} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt b/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt index f140afcff..a0b0399d2 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt @@ -86,4 +86,19 @@ class SongTest { println(test.get(0).getTrackName()) } + @Test + fun songBuilderTest() { + val songName = "test" + val songArtist = "Singer" + val artworkUrl = "https://none.com" + val previewUrl = "https://none.com" + + val mySong = Song.songBuilder(previewUrl, artworkUrl, songName, songArtist) + + assertEquals(songName, mySong.getTrackName()) + assertEquals(songArtist, mySong.getArtistName()) + assertEquals(artworkUrl, mySong.getArtworkUrl()) + assertEquals(previewUrl, mySong.getPreviewUrl()) + } + } \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt index f7289ad51..6a1e12c0f 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/AuthenticationActivity.kt @@ -97,7 +97,7 @@ class AuthenticationActivity : AppCompatActivity() { * Listener bound to the red return button in the Authentication activity. */ fun returnToMainListener(view: View) { - IntentSwitcher.switchBackToMain(this) + IntentSwitcher.switch(this, MainActivity::class.java) finish() } diff --git a/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt index 7878177fc..2e54c7a68 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/DeleteSongsActivity.kt @@ -15,6 +15,7 @@ import android.widget.TextView import android.widget.Toast import ch.sdp.vibester.R import ch.sdp.vibester.helper.IntentSwitcher +import com.google.android.material.floatingactionbutton.FloatingActionButton import java.io.* /** * Class that handles deleting files, more specifically songs in the scope of this project. @@ -27,6 +28,10 @@ class DeleteSongsActivity : AppCompatActivity() { setContentView(R.layout.activity_delete_songs) + findViewById(R.id.delete_returnToMain).setOnClickListener { + IntentSwitcher.switch(this, MainActivity::class.java) + } + val layout: LinearLayout = findViewById(R.id.delete_songs_linear) generateButtons(layout) } @@ -131,8 +136,4 @@ class DeleteSongsActivity : AppCompatActivity() { noDownloadsText.layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT) layout.addView(noDownloadsText) } - - fun switchToWelcome(view: View) { - IntentSwitcher.switchBackToMain(this) - } } \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt index 9146b48c2..a6d005053 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/DownloadActivity.kt @@ -20,6 +20,7 @@ import ch.sdp.vibester.R import ch.sdp.vibester.api.ItunesMusicApi import ch.sdp.vibester.helper.IntentSwitcher import ch.sdp.vibester.model.Song +import com.google.android.material.floatingactionbutton.FloatingActionButton import okhttp3.OkHttpClient import java.io.File import java.lang.IllegalArgumentException @@ -53,6 +54,10 @@ class DownloadActivity : AppCompatActivity() { downloadListener(songNameView) } + findViewById(R.id.download_returnToMain).setOnClickListener { + IntentSwitcher.switch(this, MainActivity::class.java) + } + var broadcast = object:BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { var id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) @@ -65,8 +70,8 @@ class DownloadActivity : AppCompatActivity() { } } } - registerReceiver(broadcast, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) - } + registerReceiver(broadcast, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) + } /** * Function that handles deletion button pushes. @@ -201,13 +206,9 @@ class DownloadActivity : AppCompatActivity() { records.appendText("$songName\n") } - fun switchToWelcome(view: View) { - IntentSwitcher.switchBackToMain(this) - } fun switchToDeleteSongs(view: View) { val intent = Intent(this, DeleteSongsActivity::class.java) startActivity(intent) } - } \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt index e333b95ad..8b38109bd 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/IncorrectSongsActivity.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.Gravity import android.view.View import android.view.Window +import android.widget.Button import android.widget.LinearLayout import android.widget.LinearLayout.LayoutParams import android.widget.TextView @@ -28,6 +29,11 @@ class IncorrectSongsActivity : AppCompatActivity() { val layout: LinearLayout = findViewById(R.id.incorrect_songs_linear) + findViewById