Skip to content

Commit

Permalink
Merge pull request #118 from makeen-project/ALS-1818
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfilimonov authored Dec 5, 2024
2 parents a2ee117 + 9093492 commit 64eb042
Show file tree
Hide file tree
Showing 35 changed files with 4,871 additions and 3,785 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.junit.*
@UninstallModules(AppModule::class)
@HiltAndroidTest
class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {

private val uiDevice = UiDevice.getInstance(getInstrumentation())

@Throws(java.lang.Exception::class)
Expand All @@ -38,6 +37,9 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {
preferenceManager.setValue(IS_APP_FIRST_TIME_OPENED, true)
preferenceManager.removeValue(KEY_AVOID_TOLLS)
preferenceManager.removeValue(KEY_AVOID_FERRIES)
preferenceManager.removeValue(KEY_AVOID_DIRT_ROADS)
preferenceManager.removeValue(KEY_AVOID_U_TURN)
preferenceManager.removeValue(KEY_AVOID_TUNNEL)

super.before()
}
Expand All @@ -52,8 +54,17 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {

toggleSwitch(R.id.switch_avoid_tools)
toggleSwitch(R.id.switch_avoid_ferries)

checkDefaultRouteOptions(avoidTollsShouldBe = true, avoidFerriesShouldBe = true)
toggleSwitch(R.id.switch_avoid_dirt_roads)
toggleSwitch(R.id.switch_avoid_u_turn)
toggleSwitch(R.id.switch_avoid_tunnels)

checkDefaultRouteOptions(
avoidTollsShouldBe = true,
avoidFerriesShouldBe = true,
avoidDirtRoadShouldBe = true,
avoidUTurnShouldBe = true,
avoidTunnelsShouldBe = true,
)
} catch (_: Exception) {
Assert.fail(TEST_FAILED)
}
Expand All @@ -71,16 +82,19 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {
uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.menu_setting)))
explorer.click()

val routeOptions = waitForView(
allOf(
withId(R.id.cl_route_option),
isDisplayed(),
),
)
val routeOptions =
waitForView(
allOf(
withId(R.id.cl_route_option),
isDisplayed(),
),
)
routeOptions?.perform(click())
}

private fun toggleSwitch(@IdRes switchId: Int) {
private fun toggleSwitch(
@IdRes switchId: Int,
) {
waitForView(
allOf(
withId(switchId),
Expand All @@ -89,7 +103,13 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {
)?.perform(click())
}

private fun checkDefaultRouteOptions(avoidTollsShouldBe: Boolean, avoidFerriesShouldBe: Boolean) {
private fun checkDefaultRouteOptions(
avoidTollsShouldBe: Boolean,
avoidFerriesShouldBe: Boolean,
avoidDirtRoadShouldBe: Boolean,
avoidUTurnShouldBe: Boolean,
avoidTunnelsShouldBe: Boolean,
) {
val explorer =
uiDevice.findObject(By.text(mActivityRule.activity.getString(R.string.menu_explore)))
explorer.click()
Expand All @@ -103,18 +123,20 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {

Thread.sleep(DELAY_2000)

val sourceEdt = waitForView(CoreMatchers.allOf(withId(R.id.edt_search_direction), isDisplayed()))
val sourceEdt =
waitForView(CoreMatchers.allOf(withId(R.id.edt_search_direction), isDisplayed()))
sourceEdt?.perform(replaceText(SEARCH_TEST_WORD_1))

Thread.sleep(DELAY_2000)

val suggestionListSrcRv = waitForView(
CoreMatchers.allOf(
withId(R.id.rv_search_places_suggestion_direction),
isDisplayed(),
hasMinimumChildCount(1),
),
)
val suggestionListSrcRv =
waitForView(
CoreMatchers.allOf(
withId(R.id.rv_search_places_suggestion_direction),
isDisplayed(),
hasMinimumChildCount(1),
),
)
suggestionListSrcRv?.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
0,
Expand All @@ -124,24 +146,26 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {

Thread.sleep(DELAY_2000)

val destinationEdt = waitForView(
CoreMatchers.allOf(
withId(R.id.edt_search_dest),
isDisplayed(),
),
)
val destinationEdt =
waitForView(
CoreMatchers.allOf(
withId(R.id.edt_search_dest),
isDisplayed(),
),
)
destinationEdt?.perform(click())
destinationEdt?.perform(typeText(SEARCH_TEST_WORD_2))

Thread.sleep(DELAY_2000)

val suggestionListDestRv = waitForView(
CoreMatchers.allOf(
withId(R.id.rv_search_places_suggestion_direction),
isDisplayed(),
hasMinimumChildCount(1),
),
)
val suggestionListDestRv =
waitForView(
CoreMatchers.allOf(
withId(R.id.rv_search_places_suggestion_direction),
isDisplayed(),
hasMinimumChildCount(1),
),
)
suggestionListDestRv?.perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
0,
Expand All @@ -156,22 +180,36 @@ class SettingsFragmentDefaultRouteTest : BaseTestMainActivity() {
),
)

val cardRoutingOption = waitForView(
CoreMatchers.allOf(
withId(R.id.card_routing_option),
withEffectiveVisibility(Visibility.VISIBLE),
),
)
val cardRoutingOption =
waitForView(
CoreMatchers.allOf(
withId(R.id.card_routing_option),
withEffectiveVisibility(Visibility.VISIBLE),
),
)
cardRoutingOption?.perform(click())

Thread.sleep(DELAY_2000)

getInstrumentation().waitForIdleSync()
getInstrumentation().runOnMainSync {
val switchAvoidToll = mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_tools)
val switchAvoidFerry = mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_ferries)

if (switchAvoidToll.isChecked != avoidTollsShouldBe || switchAvoidFerry.isChecked != avoidFerriesShouldBe) {
val switchAvoidToll =
mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_tools)
val switchAvoidFerry =
mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_ferries)
val switchAvoidDirtRoads =
mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_dirt_roads)
val switchAvoidUTurn =
mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_u_turn)
val switchAvoidTunnels =
mActivityRule.activity.findViewById<SwitchCompat>(R.id.switch_avoid_tunnels)

if (switchAvoidToll.isChecked != avoidTollsShouldBe ||
switchAvoidFerry.isChecked != avoidFerriesShouldBe ||
switchAvoidDirtRoads.isChecked != avoidDirtRoadShouldBe ||
switchAvoidUTurn.isChecked != avoidUTurnShouldBe ||
switchAvoidTunnels.isChecked != avoidTunnelsShouldBe
) {
Assert.fail(TEST_FAILED_DEFAULT_ROUTE_OPTIONS_NOT_LOADED)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aws.amazonlocation.data.datasource

import aws.sdk.kotlin.services.location.model.ListGeofenceResponseEntry
import com.aws.amazonlocation.ui.main.explore.AvoidanceOption
import com.aws.amazonlocation.domain.`interface`.BatchLocationUpdateInterface
import com.aws.amazonlocation.domain.`interface`.DistanceInterface
import com.aws.amazonlocation.domain.`interface`.GeofenceAPIInterface
Expand Down Expand Up @@ -38,8 +39,7 @@ interface RemoteDataSource {
lngDeparture: Double?,
latDestination: Double?,
lngDestination: Double?,
isAvoidFerries: Boolean?,
isAvoidTolls: Boolean?,
avoidanceOptions: ArrayList<AvoidanceOption>,
travelMode: String?,
distanceInterface: DistanceInterface
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import aws.sdk.kotlin.services.location.model.ListGeofenceResponseEntry
import com.aws.amazonlocation.R
import com.aws.amazonlocation.data.common.DataSourceException
import com.aws.amazonlocation.ui.main.explore.AvoidanceOption
import com.aws.amazonlocation.domain.`interface`.BatchLocationUpdateInterface
import com.aws.amazonlocation.domain.`interface`.DistanceInterface
import com.aws.amazonlocation.domain.`interface`.GeofenceAPIInterface
Expand Down Expand Up @@ -107,8 +108,7 @@ class RemoteDataSourceImpl(
lngDeparture: Double?,
latDestination: Double?,
lngDestination: Double?,
isAvoidFerries: Boolean?,
isAvoidTolls: Boolean?,
avoidanceOptions: ArrayList<AvoidanceOption>,
travelMode: String?,
distanceInterface: DistanceInterface,
) {
Expand All @@ -117,8 +117,7 @@ class RemoteDataSourceImpl(
lngDeparture,
latDestination,
lngDestination,
isAvoidFerries,
isAvoidTolls,
avoidanceOptions,
travelMode,
mLocationProvider.getBaseActivity(),
mLocationProvider.getGeoRoutesClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.aws.amazonlocation.data.repository

import aws.sdk.kotlin.services.geoplaces.GeoPlacesClient
import com.aws.amazonlocation.data.datasource.RemoteDataSourceImpl
import com.aws.amazonlocation.ui.main.explore.AvoidanceOption
import com.aws.amazonlocation.domain.`interface`.DistanceInterface
import com.aws.amazonlocation.domain.`interface`.PlaceInterface
import com.aws.amazonlocation.domain.`interface`.SearchDataInterface
import com.aws.amazonlocation.domain.`interface`.SearchPlaceInterface
import com.aws.amazonlocation.domain.repository.LocationSearchRepository
import com.aws.amazonlocation.ui.base.BaseActivity

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand Down Expand Up @@ -39,8 +38,7 @@ class LocationSearchImp(private val mRemoteDataSource: RemoteDataSourceImpl) :
lngDeparture: Double?,
latDestination: Double?,
lngDestination: Double?,
isAvoidFerries: Boolean?,
isAvoidTolls: Boolean?,
avoidanceOptions: ArrayList<AvoidanceOption>,
travelMode: String?,
distanceInterface: DistanceInterface
) {
Expand All @@ -49,8 +47,7 @@ class LocationSearchImp(private val mRemoteDataSource: RemoteDataSourceImpl) :
lngDeparture,
latDestination,
lngDestination,
isAvoidFerries,
isAvoidTolls,
avoidanceOptions,
travelMode,
distanceInterface
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.aws.amazonlocation.domain.repository

import aws.sdk.kotlin.services.georoutes.model.CalculateRoutesResponse
import aws.sdk.kotlin.services.location.model.Step
import com.aws.amazonlocation.ui.main.explore.AvoidanceOption
import com.aws.amazonlocation.domain.`interface`.DistanceInterface
import com.aws.amazonlocation.domain.`interface`.NavigationDataInterface
import com.aws.amazonlocation.domain.`interface`.PlaceInterface
import com.aws.amazonlocation.domain.`interface`.SearchDataInterface
import com.aws.amazonlocation.domain.`interface`.SearchPlaceInterface
Expand Down Expand Up @@ -33,8 +31,7 @@ interface LocationSearchRepository {
lngDeparture: Double?,
latDestination: Double?,
lngDestination: Double?,
isAvoidFerries: Boolean?,
isAvoidTolls: Boolean?,
avoidanceOptions: ArrayList<AvoidanceOption>,
travelMode: String?,
distanceInterface: DistanceInterface
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.aws.amazonlocation.domain.usecase

import aws.sdk.kotlin.services.georoutes.model.CalculateRoutesResponse
import aws.sdk.kotlin.services.location.model.Step
import com.aws.amazonlocation.ui.main.explore.AvoidanceOption
import com.aws.amazonlocation.domain.`interface`.DistanceInterface
import com.aws.amazonlocation.domain.`interface`.NavigationDataInterface
import com.aws.amazonlocation.domain.`interface`.PlaceInterface
import com.aws.amazonlocation.domain.`interface`.SearchDataInterface
import com.aws.amazonlocation.domain.`interface`.SearchPlaceInterface
Expand Down Expand Up @@ -36,17 +34,15 @@ class LocationSearchUseCase @Inject constructor(private val mLocationSearchRepos
lngDeparture: Double?,
latDestination: Double?,
lngDestination: Double?,
isAvoidFerries: Boolean?,
isAvoidTolls: Boolean?,
avoidanceOptions: ArrayList<AvoidanceOption>,
travelMode: String?,
distanceInterface: DistanceInterface
) = mLocationSearchRepository.calculateDistance(
latDeparture,
lngDeparture,
latDestination,
lngDestination,
isAvoidFerries,
isAvoidTolls,
avoidanceOptions,
travelMode,
distanceInterface
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ import com.aws.amazonlocation.utils.KEY_ACCESS_KEY
import com.aws.amazonlocation.utils.KEY_ACCESS_TOKEN
import com.aws.amazonlocation.utils.KEY_AUTH_EXPIRES_IN
import com.aws.amazonlocation.utils.KEY_AUTH_FETCH_TIME
import com.aws.amazonlocation.utils.KEY_AVOID_DIRT_ROADS
import com.aws.amazonlocation.utils.KEY_AVOID_FERRIES
import com.aws.amazonlocation.utils.KEY_AVOID_TOLLS
import com.aws.amazonlocation.utils.KEY_AVOID_TUNNEL
import com.aws.amazonlocation.utils.KEY_AVOID_U_TURN
import com.aws.amazonlocation.utils.KEY_CLOUD_FORMATION_STATUS
import com.aws.amazonlocation.utils.KEY_CODE
import com.aws.amazonlocation.utils.KEY_EXPIRATION
Expand Down Expand Up @@ -282,6 +285,9 @@ class MainActivity :
if (!isAppNotFirstOpened) {
mPreferenceManager.setValue(KEY_AVOID_TOLLS, true)
mPreferenceManager.setValue(KEY_AVOID_FERRIES, true)
mPreferenceManager.setValue(KEY_AVOID_TUNNEL, true)
mPreferenceManager.setValue(KEY_AVOID_DIRT_ROADS, true)
mPreferenceManager.setValue(KEY_AVOID_U_TURN, true)
}
val inflater = mNavHostFragment.navController.navInflater
val graph = inflater.inflate(R.navigation.nav_graph)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.aws.amazonlocation.ui.main.explore

enum class AvoidanceOption {
FERRIES, TOLL_ROADS, DIRT_ROADS, TUNNELS, U_TURNS
}
Loading

0 comments on commit 64eb042

Please sign in to comment.