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

Refactor BuzzerSetupActivityTest & AuthenticationActivityTest #266

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,11 @@ class AuthenticationActivityTest {
}

@Test
fun stringValidationEmptyUsername() {
fun stringValidationEmptyFields() {
onView(withId(R.id.createAcc)).perform(click())
onView(withId(R.id.authentication_status)).check(matches(withText("Empty email or password")))
}

@Test
fun stringValidationEmptyUPassword() {
onView(withId(R.id.createAcc)).perform(click())
onView(withId(R.id.authentication_status)).check(matches(withText("Empty email or password")))
}

@Test
fun returnToMain() {
Expand All @@ -143,8 +138,8 @@ class AuthenticationActivityTest {

@Test
fun stringValidationWrongEmail() {
val username = "john"
val password = "password"
val username = "j"
val password = "passwo"

onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
Expand All @@ -155,8 +150,8 @@ class AuthenticationActivityTest {

@Test
fun stringValidationShorPassword() {
val username = "[email protected]"
val password = "12345"
val username = "[email protected]"
val password = "1"

onView(withId(R.id.username)).perform(ViewActions.typeText(username), closeSoftKeyboard())
onView(withId(R.id.password)).perform(ViewActions.typeText(password), closeSoftKeyboard())
Expand All @@ -168,8 +163,8 @@ class AuthenticationActivityTest {

@Test
fun logInCorrect() {
val username = "[email protected]"
val password = "password"
val username = "[email protected]"
val password = "passwo"

val mockTask = createMockTask(true)
val mockUser = createMockUser(username)
Expand All @@ -186,8 +181,8 @@ class AuthenticationActivityTest {

@Test
fun createAccountCorrect() {
val username = "[email protected]"
val password = "password"
val username = "[email protected]"
val password = "passwo"

TestMode.setTest()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class BuzzerSetupActivityTest {
@get:Rule(order = 1)
val activityRule = ActivityScenarioRule(BuzzerSetupActivity::class.java)

val mockArray = arrayOf("Player1", "Player2", "Player3", "Player4")
val mockArray = arrayOf("1", "2", "3", "4")
val editTextIdArray = arrayOf(R.id.namePlayer1, R.id.namePlayer2, R.id.namePlayer3, R.id.namePlayer4)

/** helper function used in tests
/**
* helper function used in tests
* @param n: number of names to enter
*/
private fun enterNames(n: Int) {
Expand Down Expand Up @@ -84,16 +85,17 @@ class BuzzerSetupActivityTest {
return gameManager
}

@Test
fun checkDefaultSelect() {
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("One")))
}

@Test
fun textToNumberWrong(){
fun variousDefaultStateTest(){
var res:Int = 0
val intent = Intent(ApplicationProvider.getApplicationContext(), BuzzerSetupActivity::class.java)
val scn: ActivityScenario<BuzzerSetupActivity> = ActivityScenario.launch(intent)

//Check default selection
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("One")))

//Wrong Text to Number
scn.onActivity { activity ->
res = activity.textToNumber("Test")
}
Expand Down Expand Up @@ -123,47 +125,7 @@ class BuzzerSetupActivityTest {
assertEquals(4, res)
}

@Test
fun checkCustomSelectOne() {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(0).perform(scrollTo(),click())
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("One")))
}

@Test
fun checkCustomSelectTwo() {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(1).perform(scrollTo(),click())
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("Two")))
}

@Test
fun checkCustomSelectThree() {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(2).perform(scrollTo(),click())
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("Three")))
}

@Test
fun checkCustomSelectFour() {
onView(withId(R.id.nb_player_spinner)).perform(click())
onData(Matchers.anything()).atPosition(3).perform(scrollTo(),click())
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("Four")))
}
/*
@Test
fun checkNoIntentIfMissingName() {
val intent = Intent(ApplicationProvider.getApplicationContext(), BuzzerSetupActivity::class.java)
intent.putExtra("gameManager", setGameManager())
val scn: ActivityScenario<BuzzerSetupActivity> = ActivityScenario.launch(intent)
onView(withId(R.id.missingNameAlert)).check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE)))
onView(withId(R.id.nb_players_selected)).perform(click())
onView(withId(R.id.missingNameAlert)).check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
onView(withId(R.id.missingNameOk)).perform(click())
onView(withId(R.id.missingNameAlert)).check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE)))

}
*/
@Test
fun checkIntentOnProceedOne() {
val intent = Intent(ApplicationProvider.getApplicationContext(), BuzzerSetupActivity::class.java)
Expand Down