|
|
|
@ -14,19 +14,24 @@ import kotlinx.coroutines.runBlocking
|
|
|
|
|
import mozilla.components.browser.state.search.RegionState
|
|
|
|
|
import mozilla.components.concept.storage.Address
|
|
|
|
|
import mozilla.components.concept.storage.UpdatableAddressFields
|
|
|
|
|
import mozilla.components.service.glean.testing.GleanTestRule
|
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Assert.assertNotEquals
|
|
|
|
|
import org.junit.Assert.assertNotNull
|
|
|
|
|
import org.junit.Assert.assertNull
|
|
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Rule
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
import org.mozilla.fenix.GleanMetrics.Addresses
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.databinding.FragmentAddressEditorBinding
|
|
|
|
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
|
|
|
|
import org.mozilla.fenix.settings.address.interactor.AddressEditorInteractor
|
|
|
|
|
import org.mozilla.fenix.settings.address.view.AddressEditorView
|
|
|
|
|
|
|
|
|
|
@RunWith(FenixRobolectricTestRunner::class)
|
|
|
|
|
@RunWith(FenixRobolectricTestRunner::class) // For gleanTestRule
|
|
|
|
|
class AddressEditorViewTest {
|
|
|
|
|
|
|
|
|
|
private lateinit var view: View
|
|
|
|
@ -35,6 +40,9 @@ class AddressEditorViewTest {
|
|
|
|
|
private lateinit var binding: FragmentAddressEditorBinding
|
|
|
|
|
private lateinit var address: Address
|
|
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
|
val gleanTestRule = GleanTestRule(testContext)
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun setup() {
|
|
|
|
|
view = LayoutInflater.from(testContext).inflate(R.layout.fragment_address_editor, null)
|
|
|
|
@ -300,6 +308,30 @@ class AddressEditorViewTest {
|
|
|
|
|
assertEquals(AddressUtils.countries[DEFAULT_COUNTRY]!!.displayName, binding.countryDropDown.selectedItem.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `GIVEN an existing address WHEN the save button is clicked THEN proper metrics are recorded`() = runBlocking {
|
|
|
|
|
assertNull(Addresses.updated.testGetValue())
|
|
|
|
|
|
|
|
|
|
val addressEditorView = spyk(AddressEditorView(binding, interactor, address = address))
|
|
|
|
|
addressEditorView.bind()
|
|
|
|
|
|
|
|
|
|
binding.saveButton.performClick()
|
|
|
|
|
|
|
|
|
|
assertNotNull(Addresses.updated.testGetValue())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `GIVEN a new address WHEN the save button is clicked THEN proper metrics are recorded`() = runBlocking {
|
|
|
|
|
assertNull(Addresses.saved.testGetValue())
|
|
|
|
|
|
|
|
|
|
val addressEditorView = spyk(AddressEditorView(binding, interactor))
|
|
|
|
|
addressEditorView.bind()
|
|
|
|
|
|
|
|
|
|
binding.saveButton.performClick()
|
|
|
|
|
|
|
|
|
|
assertNotNull(Addresses.saved.testGetValue())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun generateAddress(country: String = "US", addressLevel1: String = "Oregon") = Address(
|
|
|
|
|
guid = "123",
|
|
|
|
|
givenName = "Given",
|
|
|
|
|