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

Tsathogguaa/welcome #48

Merged
merged 15 commits into from
Mar 10, 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
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 115 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/GameSetupScreenTest.kt
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"))
}
}
5 changes: 5 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/MainActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ class MainActivityTest {
intended(hasComponent(ScoreBoardActivity::class.qualifiedName))
}

@Test
fun checkIntentOnWelcome(){ //FILLER TESTING
onView(withId(R.id.placeholder_welcome)).perform(click())
intended(hasComponent(WelcomeScreen::class.qualifiedName))
}

}
70 changes: 70 additions & 0 deletions app/src/androidTest/java/ch/sdp/vibester/WelcomeScreenTest.kt
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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

fun checkIntentOnLogin(){ //FILLER TESTING
onView(withId(R.id.welcome_login)).perform(click())
intended(hasComponent(GameSetupScreen::class.java.name))
}*/
}
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name="ch.sdp.vibester.GreetingActivity"
android:name=".GameSetupScreen"
android:exported="false" />
<activity android:name=".scoreboard.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="ch.sdp.vibester.MainActivity"
android:name=".WelcomeScreen"
android:exported="false" />
<activity
android:name=".GreetingActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/ch/sdp/vibester/GameSetupScreen.kt
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)
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/ch/sdp/vibester/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,4 +32,9 @@ class MainActivity : AppCompatActivity() {
startActivity(scoreboardIntent)
}
}

fun switchToWelcome(view: View) {
Copy link

Choose a reason for hiding this comment

The 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)
}
}
48 changes: 48 additions & 0 deletions app/src/main/java/ch/sdp/vibester/WelcomeScreen.kt
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
Copy link

Choose a reason for hiding this comment

The 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) {
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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)
}*/
}
Loading