forked from sduduzog/slim-launcher
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
41 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/jkuester/unlauncher/dialog/SearchBarPositionDialog.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,33 @@ | ||
package com.jkuester.unlauncher.dialog | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import com.jkuester.unlauncher.datasource.CorePreferencesRepository | ||
import com.jkuester.unlauncher.datasource.setSearchBarPosition | ||
import com.jkuester.unlauncher.datastore.proto.SearchBarPosition | ||
import com.sduduzog.slimlauncher.R | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class SearchBarPositionDialog : DialogFragment() { | ||
@Inject | ||
lateinit var corePreferencesRepo: CorePreferencesRepository | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog | ||
.Builder(context) | ||
.setTitle(R.string.choose_search_bar_position_dialog_title) | ||
.setSingleChoiceItems( | ||
R.array.search_bar_position_array, | ||
corePreferencesRepo.get().searchBarPosition.number, | ||
this::onSelection | ||
) | ||
.create() | ||
|
||
private fun onSelection(dialogInterface: DialogInterface, i: Int) = dialogInterface | ||
.dismiss() | ||
.also { corePreferencesRepo.updateAsync(setSearchBarPosition(SearchBarPosition.forNumber(i))) } | ||
} |
38 changes: 0 additions & 38 deletions
38
app/src/main/java/com/sduduzog/slimlauncher/ui/dialogs/ChooseSearchBarPositionDialog.kt
This file was deleted.
Oops, something went wrong.
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
76 changes: 76 additions & 0 deletions
76
app/src/test/java/com/jkuester/unlauncher/dialog/SearchBarPositionDialogTest.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,76 @@ | ||
package com.jkuester.unlauncher.dialog | ||
|
||
import android.app.AlertDialog | ||
import android.content.DialogInterface | ||
import com.jkuester.unlauncher.datasource.CorePreferencesRepository | ||
import com.jkuester.unlauncher.datasource.setSearchBarPosition | ||
import com.jkuester.unlauncher.datastore.proto.SearchBarPosition | ||
import com.sduduzog.slimlauncher.R | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.justRun | ||
import io.mockk.mockk | ||
import io.mockk.mockkConstructor | ||
import io.mockk.mockkStatic | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@MockKExtension.CheckUnnecessaryStub | ||
// @MockKExtension.ConfirmVerification Weird bug between mockk/kotlin/Java is causing this to fail | ||
@ExtendWith(MockKExtension::class) | ||
class SearchBarPositionDialogTest { | ||
@MockK | ||
lateinit var corePrefsRepo: CorePreferencesRepository | ||
@MockK | ||
lateinit var alertDialog: AlertDialog | ||
|
||
@Test | ||
fun onCreateDialog() { | ||
mockkConstructor(AlertDialog.Builder::class) | ||
val onSelectionSlot = slot<DialogInterface.OnClickListener>() | ||
every { anyConstructed<AlertDialog.Builder>().setTitle(any(Int::class)) } answers | ||
{ self as AlertDialog.Builder } | ||
every { | ||
anyConstructed<AlertDialog.Builder>().setSingleChoiceItems( | ||
any(Int::class), | ||
any(Int::class), | ||
capture(onSelectionSlot) | ||
) | ||
} answers { self as AlertDialog.Builder } | ||
every { anyConstructed<AlertDialog.Builder>().create() } returns alertDialog | ||
every { corePrefsRepo.get().searchBarPosition.number } returns 0 | ||
justRun { alertDialog.dismiss() } | ||
every { corePrefsRepo.updateAsync(any()) } returns mockk() | ||
mockkStatic(::setSearchBarPosition) | ||
every { setSearchBarPosition(any()) } returns mockk() | ||
|
||
val dialogFragment = SearchBarPositionDialog() | ||
.apply { corePreferencesRepo = corePrefsRepo } | ||
val result = dialogFragment.onCreateDialog(null) | ||
|
||
result shouldBe alertDialog | ||
verify(exactly = 1) { | ||
anyConstructed<AlertDialog.Builder>().setTitle(R.string.choose_search_bar_position_dialog_title) | ||
} | ||
verify(exactly = 1) { | ||
anyConstructed<AlertDialog.Builder>().setSingleChoiceItems( | ||
R.array.search_bar_position_array, | ||
0, | ||
onSelectionSlot.captured | ||
) | ||
} | ||
verify(exactly = 1) { anyConstructed<AlertDialog.Builder>().create() } | ||
verify(exactly = 1) { corePrefsRepo.get().searchBarPosition.number } | ||
|
||
// Trigger the listener | ||
onSelectionSlot.captured.onClick(alertDialog, 0) | ||
|
||
verify(exactly = 1) { alertDialog.dismiss() } | ||
verify(exactly = 1) { corePrefsRepo.updateAsync(any()) } | ||
verify(exactly = 1) { setSearchBarPosition(SearchBarPosition.forNumber(0)) } | ||
} | ||
} |