diff --git a/app/src/androidTest/java/ch/sdp/vibester/PartyRoomTest.kt b/app/src/androidTest/java/ch/sdp/vibester/PartyRoomTest.kt index c54f8802e..ad2489de2 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/PartyRoomTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/PartyRoomTest.kt @@ -6,16 +6,6 @@ import junit.framework.Assert.assertTrue import org.junit.Test class PartyRoomTest { - @Test - fun correctSetRoom() { - val roomName = "testRoom" - val testPartyRoom = PartyRoom() - - testPartyRoom.setRoomName(roomName) - - assertEquals(testPartyRoom.getRoomName(), roomName) - } - @Test fun correctSetEmailList() { val emailList = mutableListOf("email1, email2") diff --git a/app/src/androidTest/java/ch/sdp/vibester/activity/ChoosePartyRoomActivityTest.kt b/app/src/androidTest/java/ch/sdp/vibester/activity/ChoosePartyRoomActivityTest.kt index cafae8e9b..c95d6337b 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/ChoosePartyRoomActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/ChoosePartyRoomActivityTest.kt @@ -1,5 +1,7 @@ package ch.sdp.vibester.activity +import android.content.Context +import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions @@ -9,6 +11,7 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.sdp.vibester.R +import ch.sdp.vibester.database.AppPreferences import ch.sdp.vibester.database.DataGetter import ch.sdp.vibester.helper.PartyRoom import ch.sdp.vibester.user.User @@ -43,13 +46,20 @@ class ChoosePartyRoomActivityTest { val mockUsersRepo = mockk() private fun createMockInvocation(partyRoom: PartyRoom) { - every {mockUsersRepo.createRoom(any(), any())} answers { - lastArg<(PartyRoom) -> Unit>().invoke(partyRoom) + every { mockUsersRepo.createRoom(any()) } answers { + firstArg<(PartyRoom, String) -> Unit>().invoke(partyRoom, "") } - every {mockUsersRepo.getRoomData(any(), any())} answers { - lastArg<(PartyRoom) -> Unit>().invoke(partyRoom) + + every { mockUsersRepo.readStartGame(any(), any()) } answers { + false } + + every { mockUsersRepo.updateRoomField(any(), any(), any()) } answers {} + every { mockUsersRepo.updateRoomField>>(any(), any(), any()) } answers {} + + every { mockUsersRepo.getRoomData(any(), any(), any()) } answers {} + } @After @@ -59,6 +69,8 @@ class ChoosePartyRoomActivityTest { @Test fun correctJoinPartyIntent() { + val ctx: Context = ApplicationProvider.getApplicationContext() + val roomName = "testRoomName" var mockUserEmailList = mutableListOf("email1, email2") var mockPartyRoom = PartyRoom() @@ -67,6 +79,10 @@ class ChoosePartyRoomActivityTest { createMockInvocation(mockPartyRoom) + AppPreferences.init(ctx) + AppPreferences.setStr(ctx.getString(R.string.preferences_game_mode), "local_typing") + AppPreferences.setStr(ctx.getString(R.string.preferences_game_genre), "imagine dragons") + onView(ViewMatchers.withId(R.id.roomNameInput)).perform( ViewActions.typeText("testRoomName"), ViewActions.closeSoftKeyboard() @@ -74,12 +90,14 @@ class ChoosePartyRoomActivityTest { onView(ViewMatchers.withId(R.id.joinParty)).perform(ViewActions.click()) Intents.intended(IntentMatchers.hasComponent(PartyRoomActivity ::class.java.name)) - Intents.intended(IntentMatchers.hasExtra("roomName", roomName)) + Intents.intended(IntentMatchers.hasExtra("roomID", roomName)) Intents.intended(IntentMatchers.hasExtra("createRoom", false)) } @Test fun correctCreatePartyIntent() { + val ctx: Context = ApplicationProvider.getApplicationContext() + val roomName = "testRoomName" var mockUserEmailList = mutableListOf("email1, email2") var mockPartyRoom = PartyRoom() @@ -88,6 +106,10 @@ class ChoosePartyRoomActivityTest { createMockInvocation(mockPartyRoom) + AppPreferences.init(ctx) + AppPreferences.setStr(ctx.getString(R.string.preferences_game_mode), "local_typing") + AppPreferences.setStr(ctx.getString(R.string.preferences_game_genre), "imagine dragons") + onView(ViewMatchers.withId(R.id.roomNameInput)).perform( ViewActions.typeText("testRoomName"), ViewActions.closeSoftKeyboard() @@ -95,7 +117,7 @@ class ChoosePartyRoomActivityTest { onView(ViewMatchers.withId(R.id.createParty)).perform(ViewActions.click()) Intents.intended(IntentMatchers.hasComponent(PartyRoomActivity ::class.java.name)) - Intents.intended(IntentMatchers.hasExtra("roomName", roomName)) + Intents.intended(IntentMatchers.hasExtra("roomID", roomName)) Intents.intended(IntentMatchers.hasExtra("createRoom", true)) } } \ No newline at end of file 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 f59de9619..4aa8c7cfc 100644 --- a/app/src/androidTest/java/ch/sdp/vibester/activity/PartyRoomActivityTest.kt +++ b/app/src/androidTest/java/ch/sdp/vibester/activity/PartyRoomActivityTest.kt @@ -1,19 +1,22 @@ package ch.sdp.vibester.activity -/* + +import android.content.Context import android.content.Intent -import android.provider.Telephony import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.intent.Intents +import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.runners.AndroidJUnit4 import ch.sdp.vibester.R +import ch.sdp.vibester.database.AppPreferences import ch.sdp.vibester.database.DataGetter +import ch.sdp.vibester.helper.GameManager import ch.sdp.vibester.helper.PartyRoom -import ch.sdp.vibester.user.User import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest @@ -42,64 +45,143 @@ class PartyRoomActivityTest { @JvmField val mockUsersRepo = mockk() - private fun createMockInvocation(partyRoom: PartyRoom) { - every {mockUsersRepo.createRoom(any(), any())} answers { - lastArg<(PartyRoom) -> Unit>().invoke(partyRoom) + private fun createMockInvocation(partyRoom: PartyRoom, songList: MutableList>, startGame: Boolean, roomID: String) { + every {mockUsersRepo.createRoom(any())} answers { + firstArg<(PartyRoom, String) -> Unit>().invoke(partyRoom, roomID) + } + + every { mockUsersRepo.getRoomData(any(), any(), any()) } answers { + secondArg<(PartyRoom, String) -> Unit>().invoke(partyRoom, roomID) + lastArg<(MutableList>) -> Unit>().invoke(songList) } - every {mockUsersRepo.getRoomData(any(), any())} answers { - lastArg<(PartyRoom) -> Unit>().invoke(partyRoom) + every { mockUsersRepo.readStartGame(any(), any()) } answers { + secondArg<(Boolean) -> Unit>().invoke(startGame) } + + every { mockUsersRepo.updateRoomField(any(), any(), any()) } answers {} + every { mockUsersRepo.updateRoomField>>(any(), any(), any()) } answers {} + + } @After fun clean() { Intents.release() } -/* + @Test fun correctCreation() { + val ctx: Context = ApplicationProvider.getApplicationContext() + var mockRoomName = "mockName" - var mockUserEmailList = mutableListOf("email1, email2") + var mockUserEmailList = mutableListOf("Email1", "Email2") + var mockSongList = mutableListOf>(Pair("mockSong1", "mockSong2")) var mockPartyRoom = PartyRoom() mockPartyRoom.setEmailList(mockUserEmailList) - createMockInvocation(mockPartyRoom) + createMockInvocation(mockPartyRoom, mockSongList, false, mockRoomName) - val intent = Intent(ApplicationProvider.getApplicationContext(), PartyRoomActivity::class.java) + AppPreferences.init(ctx) + AppPreferences.setStr(ctx.getString(R.string.preferences_game_mode), "local_typing") + AppPreferences.setStr(ctx.getString(R.string.preferences_game_genre), "imagine dragons") + + + val intent = Intent(ctx, PartyRoomActivity::class.java) intent.putExtra("roomName", mockRoomName) intent.putExtra("createRoom", true) - val scn: ActivityScenario = ActivityScenario.launch(intent) + val scn: ActivityScenario = ActivityScenario.launch(intent) Espresso.onView(ViewMatchers.withId(R.id.emails)) .check(ViewAssertions.matches(ViewMatchers.withText(mockUserEmailList.toString()))) } - */ -/* @Test fun correctJoin() { + val ctx: Context = ApplicationProvider.getApplicationContext() + var mockRoomName = "mockName" var mockUserEmailList = mutableListOf("email1, email2") + var mockSongList = mutableListOf>(Pair("mockSong1", "mockSong2")) var mockPartyRoom = PartyRoom() mockPartyRoom.setEmailList(mockUserEmailList) - createMockInvocation(mockPartyRoom) + createMockInvocation(mockPartyRoom, mockSongList, false, mockRoomName) - val intent = Intent(ApplicationProvider.getApplicationContext(), PartyRoomActivity::class.java) + AppPreferences.init(ctx) + AppPreferences.setStr(ctx.getString(R.string.preferences_game_mode), "local_typing") + AppPreferences.setStr(ctx.getString(R.string.preferences_game_genre), "imagine dragons") + + val intent = Intent(ctx, PartyRoomActivity::class.java) intent.putExtra("roomName", mockRoomName) intent.putExtra("createRoom", false) - val scn: ActivityScenario = ActivityScenario.launch(intent) + val scn: ActivityScenario = ActivityScenario.launch(intent) Espresso.onView(ViewMatchers.withId(R.id.emails)) .check(ViewAssertions.matches(ViewMatchers.withText(mockUserEmailList.toString()))) } - */ + @Test + fun correctDifficulty() { + val ctx: Context = ApplicationProvider.getApplicationContext() + + var mockRoomName = "mockRoom" + var mockUserEmailList = mutableListOf("email1, email2") + var mockSongList = mutableListOf>(Pair("mockSong1", "mockSong2")) + var mockPartyRoom = PartyRoom() + + AppPreferences.init(ctx) + AppPreferences.setStr(ctx.getString(R.string.preferences_game_mode), "local_typing") + AppPreferences.setStr(ctx.getString(R.string.preferences_game_genre), "imagine dragons") + + + mockPartyRoom.setEmailList(mockUserEmailList) + + createMockInvocation(mockPartyRoom, mockSongList, true, mockRoomName) + + val intent = Intent(ctx, PartyRoomActivity::class.java) + intent.putExtra("roomName", mockRoomName) + intent.putExtra("createRoom", true) + + val scn: ActivityScenario = ActivityScenario.launch(intent) + + Intents.intended(IntentMatchers.hasComponent(TypingGameActivity ::class.java.name)) + Intents.intended(IntentMatchers.hasExtra("Difficulty", R.string.GameSetup_easy)) + } + + @Test + fun correctRoomID() { + val ctx: Context = ApplicationProvider.getApplicationContext() + + var mockRoomID = "mockRoom" + var mockUserEmailList = mutableListOf("email1, email2") + var mockSongList = mutableListOf>(Pair("mockSong1", "mockSong2")) + var mockPartyRoom = PartyRoom() + + AppPreferences.init(ctx) + AppPreferences.setStr(ctx.getString(R.string.preferences_game_mode), "local_typing") + AppPreferences.setStr(ctx.getString(R.string.preferences_game_genre), "imagine dragons") + + + mockPartyRoom.setEmailList(mockUserEmailList) + + createMockInvocation(mockPartyRoom, mockSongList, false, mockRoomID) + + val intent = Intent(ctx, PartyRoomActivity::class.java) + intent.putExtra("roomName", mockRoomID) + intent.putExtra("createRoom", false) + + val scn: ActivityScenario = ActivityScenario.launch(intent) + + Espresso.onView(ViewMatchers.withId(R.id.roomId)) + .check(ViewAssertions.matches(ViewMatchers.withText(mockRoomID))) + + + } + } - */ \ No newline at end of file diff --git a/app/src/main/java/ch/sdp/vibester/activity/ChoosePartyRoomActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/ChoosePartyRoomActivity.kt index 30be3d926..9622b8dd4 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/ChoosePartyRoomActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/ChoosePartyRoomActivity.kt @@ -30,7 +30,7 @@ class ChoosePartyRoomActivity : AppCompatActivity() { private fun switchToRoom(roomName: String, createRoom: Boolean) { val newIntent = Intent(this, PartyRoomActivity::class.java) - newIntent.putExtra("roomName", roomName) + newIntent.putExtra("roomID", roomName) newIntent.putExtra("createRoom", createRoom) startActivity(newIntent) diff --git a/app/src/main/java/ch/sdp/vibester/activity/PartyRoomActivity.kt b/app/src/main/java/ch/sdp/vibester/activity/PartyRoomActivity.kt index d5e6792fe..c4253bf4e 100644 --- a/app/src/main/java/ch/sdp/vibester/activity/PartyRoomActivity.kt +++ b/app/src/main/java/ch/sdp/vibester/activity/PartyRoomActivity.kt @@ -1,49 +1,142 @@ package ch.sdp.vibester.activity import android.content.ContentValues +import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log +import android.widget.Button import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout import ch.sdp.vibester.R +import ch.sdp.vibester.api.LastfmApiInterface +import ch.sdp.vibester.api.LastfmMethod +import ch.sdp.vibester.api.LastfmUri +import ch.sdp.vibester.database.AppPreferences import ch.sdp.vibester.database.DataGetter import ch.sdp.vibester.database.Database +import ch.sdp.vibester.helper.GameManager import ch.sdp.vibester.helper.PartyRoom import ch.sdp.vibester.user.User import com.google.firebase.database.DataSnapshot import com.google.firebase.database.DatabaseError import com.google.firebase.database.ValueEventListener +import com.google.gson.Gson import dagger.hilt.android.AndroidEntryPoint +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response import javax.inject.Inject +import kotlin.properties.Delegates @AndroidEntryPoint class PartyRoomActivity : AppCompatActivity() { @Inject lateinit var dataGetter: DataGetter + lateinit var gameManager: GameManager + + lateinit var roomID: String + + + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_party_room) - val roomName = intent.getStringExtra("roomName").toString() val createPartyRoom = intent.getBooleanExtra("createRoom", false) if(createPartyRoom) { - createRoom(roomName) + createRoom() + setGameManager() + dataGetter.updateRoomField(roomID, "gameStarted", false) } else { - fetchData(roomName) + this.roomID = intent.getStringExtra("roomID").toString() + fetchData(roomID) } + + val startGame = findViewById