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

Commit

Permalink
Merge pull request #341 from MaximeZmt/kamila/fix_fragment_tests
Browse files Browse the repository at this point in the history
Kamila/fix fragment tests
  • Loading branch information
kamilababayeva authored May 24, 2022
2 parents 689c777 + 9ca6c29 commit 5cf6437
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package ch.sdp.vibester.fragment
/*

import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
Expand Down Expand Up @@ -102,5 +102,3 @@ class ScoreBoardFragmentTest {
onView(withId(R.id.scoreboard_btsButton)).perform(click())
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.sdp.vibester.R
import ch.sdp.vibester.activity.QrScanningActivity
import ch.sdp.vibester.auth.FireBaseAuthenticator
import ch.sdp.vibester.database.DataGetter
import ch.sdp.vibester.launchFragmentInHiltContainer
Expand Down Expand Up @@ -101,19 +103,14 @@ class SearchUserFragmentTest {
Intents.release()
}

//TODO fix the test that fails due to the media non initialization
// @Test
// fun goToScanQr() {
// val intent = Intent(ApplicationProvider.getApplicationContext(), SearchUserActivity::class.java)
// intent.putExtra("isTest", true)
//
// createMockInvocation()
// createMockAuthenticator()
// val scn: ActivityScenario<SearchUserActivity> = ActivityScenario.launch(intent)
//
// onView(withId(R.id.searchUser_scanning)).perform(click())
// Intents.intended(IntentMatchers.hasComponent(QrScanningActivity::class.java.name))
// }
//FIXME test is timed out
/*
@Test
fun goToScanQr() {
onView(withId(R.id.searchUser_scanning)).perform(click())
Intents.intended(IntentMatchers.hasComponent(QrScanningActivity::class.java.name))
}
*/

@Test
fun recycleViewToViewTest() {
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/ch/sdp/vibester/fragment/GameSetupFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import retrofit2.Response
* Game Setup fragment with a button in the bottom navigation.
*/
@AndroidEntryPoint
class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSelectedListener {
class GameSetupFragment : Fragment(R.layout.fragment_game_setup), View.OnClickListener, AdapterView.OnItemSelectedListener {
var difficulty = R.string.GameSetup_easy.toString()
var game = "local_buzzer"
var gameSize = R.string.one.toString()
Expand All @@ -42,12 +42,9 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
// TODO: OFFLINE
private var hasInternet: Boolean = true

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_game_setup, container, false)
val ctx = inflater.context
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val ctx = view.context

view.findViewById<Button>(R.id.local_buzzer_game_button).setOnClickListener(this)
view.findViewById<Button>(R.id.local_typing_game_button).setOnClickListener(this)
Expand All @@ -68,7 +65,6 @@ class GameSetupFragment : Fragment(), View.OnClickListener, AdapterView.OnItemSe
setReturnBtnListener(view)
setSpinnerListener(view, ctx, R.id.difficulty_spinner, R.array.difficulties_name)
setSpinnerListener(view, ctx, R.id.size_spinner, R.array.game_size_options)
return view
}


Expand Down
57 changes: 16 additions & 41 deletions app/src/main/java/ch/sdp/vibester/fragment/ScoreBoardFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class ScoreBoardFragment : Fragment(), OnItemClickListener, View.OnClickListener {
class ScoreBoardFragment : Fragment(R.layout.fragment_scoreboard), OnItemClickListener {
private val dbRef: DatabaseReference = Database.get().getReference("users")
private var players: MutableList<User> = mutableListOf()
private var userScoreboardAdapter: UserScoreboardAdapter? = null
Expand All @@ -40,29 +40,24 @@ class ScoreBoardFragment : Fragment(), OnItemClickListener, View.OnClickListener
@Inject
lateinit var imageGetter: ImageGetter

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_scoreboard, container, false)
val ctx = inflater.context
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val ctx = view.context

view.findViewById<Button>(R.id.scoreboard_kpopButton).setOnClickListener(this)
view.findViewById<Button>(R.id.scoreboard_rockButton).setOnClickListener(this)
view.findViewById<Button>(R.id.scoreboard_btsButton).setOnClickListener(this)
view.findViewById<Button>(R.id.scoreboard_topTracksButton).setOnClickListener(this)
view.findViewById<Button>(R.id.scoreboard_imagDragonsButton).setOnClickListener(this)
view.findViewById<Button>(R.id.scoreboard_billieEilishButton).setOnClickListener(this)
view.findViewById<Button>(R.id.scoreboard_kpopButton).setOnClickListener { setGenreListeners(view, "Kpop") }
view.findViewById<Button>(R.id.scoreboard_rockButton).setOnClickListener {setGenreListeners(view, "Rock") }
view.findViewById<Button>(R.id.scoreboard_btsButton).setOnClickListener { setGenreListeners(view, "BTS") }
view.findViewById<Button>(R.id.scoreboard_topTracksButton).setOnClickListener{ setGenreListeners(view, "top tracks") }
view.findViewById<Button>(R.id.scoreboard_imagDragonsButton).setOnClickListener{ setGenreListeners(view, "Imagine Dragons") }
view.findViewById<Button>(R.id.scoreboard_billieEilishButton).setOnClickListener { setGenreListeners(view, "Billie Eillish") }
setupRecycleView(view, ctx)

return view
}

private fun selectScoreboard() {
private fun selectScoreboard(view: View) {
val sortedBy = "scores/$genre"

requireView().findViewById<ConstraintLayout>(R.id.genrePerScoreboard).visibility = GONE
requireView().findViewById<NestedScrollView>(R.id.scoreboard_content_scrolling).visibility = VISIBLE
view.findViewById<ConstraintLayout>(R.id.genrePerScoreboard).visibility = GONE
view.findViewById<NestedScrollView>(R.id.scoreboard_content_scrolling).visibility = VISIBLE

loadPlayersSortedBy(sortedBy)
}
Expand Down Expand Up @@ -121,28 +116,8 @@ class ScoreBoardFragment : Fragment(), OnItemClickListener, View.OnClickListener
startActivity(intent)
}

override fun onClick(v: View?) {
when(v!!.id) {
R.id.scoreboard_btsButton -> {
genre = "BTS"; selectScoreboard()
}
R.id.scoreboard_kpopButton -> {
genre = "kpop"; selectScoreboard()
}
R.id.scoreboard_imagDragonsButton -> {
genre = "Imagine Dragons"; selectScoreboard()
}
R.id.scoreboard_billieEilishButton -> {
genre = "Billie Eilish"; selectScoreboard()
}
R.id.scoreboard_rockButton -> {
genre = "rock";selectScoreboard()
}
R.id.scoreboard_topTracksButton -> {
genre = "top tracks";selectScoreboard()
}

}

private fun setGenreListeners(view: View, genre: String){
this.genre = genre
selectScoreboard(view)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import javax.inject.Inject
* Search for users based on their usernames.
*/
@AndroidEntryPoint
class SearchUserFragment : Fragment(), OnItemClickListener {
class SearchUserFragment : Fragment(R.layout.fragment_search_user), OnItemClickListener {

@Inject
lateinit var usersRepo: DataGetter
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/fragment_search_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
android:layout_height="match_parent"
android:id="@+id/fragment_search_user"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/floral_white"
tools:context=".fragment.SearchUserFragment">
android:background="@color/floral_white">

<RelativeLayout
android:id="@+id/search_tool"
Expand Down

0 comments on commit 5cf6437

Please sign in to comment.