-
Notifications
You must be signed in to change notification settings - Fork 0
Tsathogguaa/welcome #48
Changes from all commits
8e7fbca
52cce3a
4e7ea04
55ee9c0
6ec4401
91e9fec
c4910e4
df9e06f
9c50f02
27761a9
c58e5d5
a1f8a5e
eb5ec6c
121362d
ee6882a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.widget.AdapterView | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.Espresso.onData | ||
import androidx.test.espresso.action.ViewActions | ||
import androidx.test.espresso.intent.Intents | ||
import androidx.test.espresso.intent.matcher.IntentMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.espresso.intent.Intents.intended | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.ViewAssertion | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.intent.matcher.IntentMatchers.* | ||
import androidx.test.espresso.matcher.ViewMatchers.withSpinnerText | ||
import org.hamcrest.Matchers | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GameSetupScreenTest { | ||
|
||
@get: Rule | ||
val activityRule = ActivityScenarioRule(GameSetupScreen::class.java) | ||
|
||
@Before | ||
fun setUp() { | ||
Intents.init() | ||
} | ||
|
||
@After | ||
fun clean() { | ||
Intents.release() | ||
} | ||
|
||
@Test | ||
fun checkDefaultSelect() { | ||
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("One"))) | ||
} | ||
|
||
@Test | ||
fun checkCustomSelectOne() { | ||
onView(withId(R.id.nb_player_spinner)).perform(click()) | ||
onData(Matchers.anything()).atPosition(0).perform(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(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(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(click()) | ||
onView(withId(R.id.nb_player_spinner)).check(matches(withSpinnerText("Four"))) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnProceedDefault() { //FILLER TEST | ||
onView(withId(R.id.nb_players_selected)).perform(click()) | ||
intended(hasComponent(WelcomeScreen::class.java.name)) | ||
intended(hasExtra("Number of players", "One")) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnProceedOne() { //FILLER TEST | ||
onView(withId(R.id.nb_player_spinner)).perform(click()) | ||
onData(Matchers.anything()).atPosition(0).perform(click()) | ||
onView(withId(R.id.nb_players_selected)).perform(click()) | ||
intended(hasComponent(WelcomeScreen::class.java.name)) | ||
intended(hasExtra("Number of players", "One")) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnProceedTwo() { //FILLER TEST | ||
onView(withId(R.id.nb_player_spinner)).perform(click()) | ||
onData(Matchers.anything()).atPosition(1).perform(click()) | ||
onView(withId(R.id.nb_players_selected)).perform(click()) | ||
intended(hasComponent(WelcomeScreen::class.java.name)) | ||
intended(hasExtra("Number of players", "Two")) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnProceedThree() { //FILLER TEST | ||
onView(withId(R.id.nb_player_spinner)).perform(click()) | ||
onData(Matchers.anything()).atPosition(2).perform(click()) | ||
onView(withId(R.id.nb_players_selected)).perform(click()) | ||
intended(hasComponent(WelcomeScreen::class.java.name)) | ||
intended(hasExtra("Number of players", "Three")) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnProceedFour() { //FILLER TEST | ||
onView(withId(R.id.nb_player_spinner)).perform(click()) | ||
onData(Matchers.anything()).atPosition(3).perform(click()) | ||
onView(withId(R.id.nb_players_selected)).perform(click()) | ||
intended(hasComponent(WelcomeScreen::class.java.name)) | ||
intended(hasExtra("Number of players", "Four")) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ch.sdp.vibester | ||
|
||
import androidx.test.espresso.intent.Intents.intended | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.intent.Intents | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.espresso.intent.matcher.IntentMatchers.* | ||
import ch.sdp.vibester.scoreboard.ScoreBoardActivity | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class WelcomeScreenTest { | ||
@get: Rule | ||
val activityRule = ActivityScenarioRule(WelcomeScreen::class.java) | ||
|
||
@Before | ||
fun setUp() { | ||
Intents.init() | ||
} | ||
|
||
@After | ||
fun clean() { | ||
Intents.release() | ||
} | ||
|
||
@Test | ||
fun checkIntentOnPlay(){ | ||
onView(withId(R.id.welcome_play)).perform(click()) | ||
intended(hasComponent(GameSetupScreen::class.java.name)) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnProfile(){ //FILLER TESTING | ||
onView(withId(R.id.welcome_profile)).perform(click()) | ||
intended(hasComponent(GameSetupScreen::class.java.name)) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnScoreboard(){ | ||
onView(withId(R.id.welcome_scoreboard)).perform(click()) | ||
intended(hasComponent(ScoreBoardActivity::class.java.name)) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnListen(){ //FILLER TESTING | ||
onView(withId(R.id.welcome_listen)).perform(click()) | ||
intended(hasComponent(GameSetupScreen::class.java.name)) | ||
} | ||
|
||
@Test | ||
fun checkIntentOnSettings(){ //FILLER TESTING | ||
onView(withId(R.id.welcome_settings)).perform(click()) | ||
intended(hasComponent(GameSetupScreen::class.java.name)) | ||
} | ||
|
||
/* | ||
* Belongs to a previously implemented button, taken out for UI purposes. | ||
* Might bring it back, thus leaving the code for now. | ||
*/ | ||
|
||
/*@Test | ||
fun checkIntentOnLogin(){ //FILLER TESTING | ||
onView(withId(R.id.welcome_login)).perform(click()) | ||
intended(hasComponent(GameSetupScreen::class.java.name)) | ||
}*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.AdapterView | ||
import android.widget.ArrayAdapter | ||
import android.widget.Spinner | ||
import android.widget.Toast | ||
|
||
class GameSetupScreen : AppCompatActivity(), AdapterView.OnItemSelectedListener { | ||
var text = "One" | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_game_setup_screen) | ||
|
||
val spinner: Spinner = findViewById(R.id.nb_player_spinner) | ||
ArrayAdapter.createFromResource( | ||
this, | ||
R.array.nb_players, | ||
android.R.layout.simple_spinner_item | ||
).also { | ||
adapter -> adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||
spinner.adapter = adapter | ||
spinner.onItemSelectedListener = this | ||
} | ||
} | ||
|
||
override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) { | ||
text = parent.getItemAtPosition(position).toString() | ||
} | ||
|
||
override fun onNothingSelected(parent: AdapterView<*>) {text = "One"} | ||
|
||
fun proceedToGame(view: View) { //FILLER INTENT | ||
val intent = Intent(this, WelcomeScreen::class.java) | ||
intent.putExtra("Number of players", text) | ||
startActivity(intent) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package ch.sdp.vibester | |
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
@@ -31,4 +32,9 @@ class MainActivity : AppCompatActivity() { | |
startActivity(scoreboardIntent) | ||
} | ||
} | ||
|
||
fun switchToWelcome(view: View) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
val intent = Intent(this, WelcomeScreen::class.java) | ||
startActivity(intent) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ch.sdp.vibester | ||
|
||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.view.View | ||
import ch.sdp.vibester.scoreboard.ScoreBoardActivity | ||
|
||
class WelcomeScreen : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_welcome_screen) | ||
} | ||
|
||
private fun sendDirectIntent(arg: Class<*>?) { | ||
val intent = Intent(this, arg) | ||
startActivity(intent) | ||
} | ||
|
||
fun switchToPlay(view: View) { | ||
sendDirectIntent(GameSetupScreen::class.java) | ||
} | ||
|
||
fun switchToProfile(view: View) { //FILLER INTENT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
sendDirectIntent(GameSetupScreen::class.java) | ||
} | ||
|
||
fun switchToScoreboard(view: View) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
sendDirectIntent(ScoreBoardActivity::class.java) | ||
} | ||
|
||
fun switchToListen(view: View) { //FILLER INTENT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
sendDirectIntent(GameSetupScreen::class.java) | ||
} | ||
|
||
fun switchToSettings(view: View) { //FILLER INTENT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 6 locations. Consider refactoring. |
||
sendDirectIntent(GameSetupScreen::class.java) | ||
} | ||
|
||
/* | ||
* Belongs to a previously implemented button, taken out for UI purposes. | ||
* Might bring it back, thus leaving the code for now. | ||
*/ | ||
|
||
/*fun switchToLogin(view: View) { //FILLER INTENT | ||
sendDirectIntent(GameSetupScreen::class.java) | ||
}*/ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this test is in the comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed a button that was causing problems, as it wasn't fitting in whatever emulator they are using for the CI tests. It all passed locally until then. This test is for that button, since it doesn't exist for now, I removed it, however am thinking of readding it in some form.