Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into jwen/end-game-download
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsathogguaa authored May 26, 2022
2 parents 25329df + 6f3114c commit 2cb3206
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 64 deletions.
10 changes: 0 additions & 10 deletions app/src/androidTest/java/ch/sdp/vibester/PartyRoomTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -43,13 +46,20 @@ class ChoosePartyRoomActivityTest {
val mockUsersRepo = mockk<DataGetter>()

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<Boolean>(any(), any(), any()) } answers {}
every { mockUsersRepo.updateRoomField<MutableList<Pair<String, String>>>(any(), any(), any()) } answers {}

every { mockUsersRepo.getRoomData(any(), any(), any()) } answers {}

}

@After
Expand All @@ -59,6 +69,8 @@ class ChoosePartyRoomActivityTest {

@Test
fun correctJoinPartyIntent() {
val ctx: Context = ApplicationProvider.getApplicationContext()

val roomName = "testRoomName"
var mockUserEmailList = mutableListOf<String>("email1, email2")
var mockPartyRoom = PartyRoom()
Expand All @@ -67,19 +79,25 @@ 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()
)
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<String>("email1, email2")
var mockPartyRoom = PartyRoom()
Expand All @@ -88,14 +106,18 @@ 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()
)
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))
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,64 +45,143 @@ class PartyRoomActivityTest {
@JvmField
val mockUsersRepo = mockk<DataGetter>()

private fun createMockInvocation(partyRoom: PartyRoom) {
every {mockUsersRepo.createRoom(any(), any())} answers {
lastArg<(PartyRoom) -> Unit>().invoke(partyRoom)
private fun createMockInvocation(partyRoom: PartyRoom, songList: MutableList<Pair<String, String>>, 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<Pair<String, String>>) -> 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<Boolean>(any(), any(), any()) } answers {}
every { mockUsersRepo.updateRoomField<MutableList<Pair<String, String>>>(any(), any(), any()) } answers {}


}

@After
fun clean() {
Intents.release()
}
/*

@Test
fun correctCreation() {
val ctx: Context = ApplicationProvider.getApplicationContext()

var mockRoomName = "mockName"
var mockUserEmailList = mutableListOf<String>("email1, email2")
var mockUserEmailList = mutableListOf<String>("Email1", "Email2")
var mockSongList = mutableListOf<Pair<String, String>>(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<CreateProfileActivity> = ActivityScenario.launch(intent)
val scn: ActivityScenario<PartyRoomActivity> = 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<String>("email1, email2")
var mockSongList = mutableListOf<Pair<String, String>>(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<CreateProfileActivity> = ActivityScenario.launch(intent)
val scn: ActivityScenario<PartyRoomActivity> = 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<String>("email1, email2")
var mockSongList = mutableListOf<Pair<String, String>>(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<PartyRoomActivity> = 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<String>("email1, email2")
var mockSongList = mutableListOf<Pair<String, String>>(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<PartyRoomActivity> = ActivityScenario.launch(intent)

Espresso.onView(ViewMatchers.withId(R.id.roomId))
.check(ViewAssertions.matches(ViewMatchers.withText(mockRoomID)))


}

}

*/
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 2cb3206

Please sign in to comment.