-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(git): merge pull request #559 from robercoding/fix-issue-537
- Loading branch information
Showing
18 changed files
with
267 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/androidTest/java/com/github/ashutoshgngwr/noice/fragment/RandomPresetFragmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.github.ashutoshgngwr.noice.fragment | ||
|
||
import androidx.fragment.app.testing.FragmentScenario | ||
import androidx.fragment.app.testing.launchFragmentInContainer | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.action.ViewActions | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.github.ashutoshgngwr.noice.InAppReviewFlowManager | ||
import com.github.ashutoshgngwr.noice.MediaPlayerService | ||
import com.github.ashutoshgngwr.noice.R | ||
import com.github.ashutoshgngwr.noice.RetryTestRule | ||
import com.github.ashutoshgngwr.noice.sound.Preset | ||
import com.github.ashutoshgngwr.noice.sound.Sound | ||
import io.mockk.clearMocks | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkObject | ||
import io.mockk.unmockkAll | ||
import io.mockk.verify | ||
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 RandomPresetFragmentTest { | ||
|
||
@Rule | ||
@JvmField | ||
val retryTestRule = RetryTestRule(5) | ||
|
||
private lateinit var fragmentScenario: FragmentScenario<RandomPresetFragment> | ||
|
||
@Before | ||
fun setup() { | ||
mockkObject(InAppReviewFlowManager, MediaPlayerService.Companion) | ||
fragmentScenario = launchFragmentInContainer(null, R.style.Theme_App) | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
unmockkAll() | ||
} | ||
|
||
@Test | ||
fun testRandomPresetButton_onClick() { | ||
val intensityExpectations = mapOf( | ||
R.id.preset_intensity__any to SoundLibraryFragment.RANGE_INTENSITY_ANY, | ||
R.id.preset_intensity__dense to SoundLibraryFragment.RANGE_INTENSITY_DENSE, | ||
R.id.preset_intensity__light to SoundLibraryFragment.RANGE_INTENSITY_LIGHT | ||
) | ||
|
||
val typeExpectations = mapOf( | ||
R.id.preset_type__any to null, | ||
R.id.preset_type__focus to Sound.Tag.FOCUS, | ||
R.id.preset_type__relax to Sound.Tag.RELAX | ||
) | ||
|
||
for ((typeID, tag) in typeExpectations) { | ||
for ((intensityID, intensityRange) in intensityExpectations) { | ||
Espresso.onView(withId(typeID)).perform(ViewActions.click()) | ||
Espresso.onView(withId(intensityID)).perform(ViewActions.click()) | ||
|
||
Espresso.onView(withId(R.id.play_preset_button)) | ||
.perform(ViewActions.click()) | ||
|
||
verify(exactly = 1) { MediaPlayerService.playRandomPreset(any(), tag, intensityRange) } | ||
clearMocks(MediaPlayerService.Companion) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/github/ashutoshgngwr/noice/fragment/RandomPresetFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.github.ashutoshgngwr.noice.fragment | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.github.ashutoshgngwr.noice.InAppReviewFlowManager | ||
import com.github.ashutoshgngwr.noice.MediaPlayerService | ||
import com.github.ashutoshgngwr.noice.R | ||
import com.github.ashutoshgngwr.noice.databinding.RandomPresetFragmentBinding | ||
import com.github.ashutoshgngwr.noice.sound.Sound | ||
|
||
class RandomPresetFragment : Fragment() { | ||
|
||
private lateinit var binding: RandomPresetFragmentBinding | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = RandomPresetFragmentBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
//flexCheckedButton in XML is not working so we set manually. | ||
binding.presetIntensityAny.isChecked = true | ||
binding.presetTypeAny.isChecked = true | ||
|
||
binding.playPresetButton.setOnClickListener { | ||
val tag = when (binding.presetType.checkedRadioButtonId) { | ||
R.id.preset_type__focus -> Sound.Tag.FOCUS | ||
R.id.preset_type__relax -> Sound.Tag.RELAX | ||
else -> null | ||
} | ||
|
||
val intensity = when (binding.presetIntensity.checkedRadioButtonId) { | ||
R.id.preset_intensity__light -> SoundLibraryFragment.RANGE_INTENSITY_LIGHT | ||
R.id.preset_intensity__dense -> SoundLibraryFragment.RANGE_INTENSITY_DENSE | ||
else -> SoundLibraryFragment.RANGE_INTENSITY_ANY | ||
} | ||
|
||
MediaPlayerService.playRandomPreset(requireContext(), tag, intensity) | ||
|
||
// maybe show in-app review dialog to the user | ||
InAppReviewFlowManager.maybeAskForReview(requireActivity()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 0 additions & 86 deletions
86
app/src/main/res/layout/dialog_fragment__random_preset.xml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.