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 #102 from MaximeZmt/jwen/lyrics-belong
Browse files Browse the repository at this point in the history
Jwen/lyrics belong
  • Loading branch information
MaximeZmt authored Mar 24, 2022
2 parents c2890f6 + 5c00063 commit 6089689
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 99 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ dependencies {
testImplementation 'org.robolectric:robolectric:4.6'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'org.mockito.kotlin:mockito-kotlin:4.0.0'
testImplementation 'org.mockito:mockito-inline:2.13.0'
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GenreTemporaryTest {
}

@Test
fun GenreLayoutIsDisplayed() {
fun genreLayoutIsDisplayed() {
onView(withId(R.id.rockButton)).check(matches(isDisplayed()))
onView(withId(R.id.kpopButton)).check(matches(isDisplayed()))
onView(withId(R.id.topTracksButton)).check(matches(isDisplayed()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package ch.sdp.vibester.activity

import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.GrantPermissionRule
import ch.sdp.vibester.R
import ch.sdp.vibester.api.LyricsOVHApiInterface

import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LyricsBelongGameActivityTest {

@get: Rule
val activityRule = ActivityScenarioRule(LyricsBelongGameActivity::class.java)

@get:Rule
var permissionRule: GrantPermissionRule =
GrantPermissionRule.grant(android.Manifest.permission.RECORD_AUDIO)

@Before
fun setUp() {
Intents.init()
}

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

@Test
fun getLyricsFromAPICorrectly() {
val service = LyricsOVHApiInterface.create()
val lyric = service.getLyrics("Imagine Dragons", "Thunder").execute()

assertThat(
lyric.body().lyrics?.replace("\n", "")?.replace("\r", ""),
equalTo(("Just a young gun with a quick fuse\n" +
"I was uptight, wanna let loose\n" +
"I was dreaming of bigger things in\n" +
"And wanna leave my own life behind\n" +
"Not a yes sir, not a follower\n" +
"Fit the box, fit the mold\n" +
"Have a seat in the foyer, take a number\n" +
"I was lightning before the thunder\n" +
"Thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder\n" +
"Thunder, feel the thunder\n" +
"Lightning and the thunder\n" +
"Thunder, feel the thunder\n" +
"Lightning and the thunder\n" +
"Thunder, thunder\n" +
"Thunder\n" +

"Kids were laughing in my classes\n" +
"While I was scheming for the masses\n" +
"Who do you think you are?\n" +
"Dreaming 'bout being a big star\n" +
"You say you're basic, you say you're easy\n" +
"You're always riding in the back seat\n" +
"Now I'm smiling from the stage while\n" +
"You were clapping in the nose bleeds\n" +

"Thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder\n" +

"Thunder, feel the thunder\n" +
"Lightning and the thunder\n" +
"Thunder, feel the thunder\n" +
"Lightning and the thunder\n" +
"Thunder\n" +
"Thunder, feel the thunder\n" +
"Lightning and the thunder, thunder\n" +

"Thunder, feel the thunder\n" +
"Lightning and the thunder, thunder\n" +
"Thunder, feel the thunder\n" +
"Lightning and the thunder, thunder\n" +
"Thunder, feel the thunder\n" +
"Lightning and the thunder, thunder\n" +
"Thunder, feel the thunder (feel the)\n" +
"Lightning and the thunder, thunder\n" +

"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder\n" +
"Thunder, thun-, thunder\n" +
"Thun-thun-thunder, thunder").replace("\r", "").replace("\n", ""))
)
}

@Test
fun btnCheckVisibleAfterSpeak() {
val intent = Intent(ApplicationProvider.getApplicationContext(), LyricsBelongGameActivity::class.java)
val scn: ActivityScenario<LyricsBelongGameActivity> = ActivityScenario.launch(intent)
scn.onActivity { activity ->
activity.testUpdateSpeechResult("hey")
}
onView(withId(R.id.lyricMatchResult)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

@Test
fun checkLyricsShouldReturnCorrect() {
val intent = Intent(ApplicationProvider.getApplicationContext(), LyricsBelongGameActivity::class.java)
val scn: ActivityScenario<LyricsBelongGameActivity> = ActivityScenario.launch(intent)
scn.onActivity { activity ->
activity.testCheckLyrics("Just a young gun with a quick fuse")
}
Thread.sleep(5000)
onView(withId(R.id.lyricMatchResult)).check(matches(withText("res: correct")))
}

@Test
fun checkLyricsShouldReturnTooBad() {
val intent = Intent(ApplicationProvider.getApplicationContext(), LyricsBelongGameActivity::class.java)
val scn: ActivityScenario<LyricsBelongGameActivity> = ActivityScenario.launch(intent)
scn.onActivity { activity ->
activity.testCheckLyrics("I don't remember the lyrics")
}
Thread.sleep(5000)
onView(withId(R.id.lyricMatchResult)).check(matches(withText("res: too bad")))
}

@Test
fun shouldUpdateSpeechFromInput() {
val intent = Intent(ApplicationProvider.getApplicationContext(), LyricsBelongGameActivity::class.java)
val scn: ActivityScenario<LyricsBelongGameActivity> = ActivityScenario.launch(intent)
scn.onActivity { activity ->
activity.testUpdateSpeechResult("hey")
}
onView(withId(R.id.lyricResult)).check(matches(withText("hey")))
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ class MainActivityTest {
@Test
fun checkIntentOnLyric() {
onView(withId(R.id.lyricButton)).perform(click())
intended(hasComponent(LyricTemporary::class.qualifiedName))
intended(hasComponent(LyricsBelongGameActivity::class.qualifiedName))
}
}
124 changes: 64 additions & 60 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.sdp.vibester">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
android:usesCleartextTraffic="true">
<activity
android:name=".activity.IncorrectSongsActivity"
android:exported="false" />
<activity
android:name=".activity.GameEndingActivity"
android:exported="false" />
<activity
android:name=".activity.TypingGameActivity"
android:exported="false" />
<activity
android:name=".activity.GamescreenActivity"
android:exported="false" />
<activity
android:name=".activity.ProfileActivity"
android:exported="false" />
<activity
android:name=".LyricTemporary"
android:exported="false" />
<activity
android:name=".activity.GameSetupActivity"
android:exported="false" />
<activity
android:name=".activity.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.WelcomeActivity"
android:exported="false" />
<activity
android:name=".activity.AuthenticationActivity"
android:exported="true" />
<activity
android:name=".GenreTemporary"
android:exported="false" />
<activity
android:name=".activity.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.sdp.vibester">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
android:usesCleartextTraffic="true">
<activity
android:name=".activity.IncorrectSongsActivity"
android:exported="false" />
<activity
android:name=".activity.LyricsBelongGameActivity"
android:exported="false" />
<activity
android:name=".activity.GameEndingActivity"
android:exported="false" />
<activity
android:name=".activity.TypingGameActivity"
android:exported="false" />
<activity
android:name=".activity.GamescreenActivity"
android:exported="false" />
<activity
android:name=".activity.ProfileActivity"
android:exported="false" />
<activity
android:name=".LyricTemporary"
android:exported="false" />
<activity
android:name=".activity.GameSetupActivity"
android:exported="false" />
<activity
android:name=".activity.ScoreBoardActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.WelcomeActivity"
android:exported="false" />
<activity
android:name=".activity.AuthenticationActivity"
android:exported="true" />
<activity
android:name=".GenreTemporary"
android:exported="false" />
<activity
android:name=".activity.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit 6089689

Please sign in to comment.