-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13721 from wordpress-mobile/issue/13268-activity-…
…log-filters-visibility Issue/13268 activity log filters visibility
- Loading branch information
Showing
7 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
WordPress/src/main/java/org/wordpress/android/ui/jetpack/FetchJetpackCapabilitiesUseCase.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,48 @@ | ||
package org.wordpress.android.ui.jetpack | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.withContext | ||
import org.greenrobot.eventbus.Subscribe | ||
import org.greenrobot.eventbus.ThreadMode | ||
import org.wordpress.android.fluxc.Dispatcher | ||
import org.wordpress.android.fluxc.generated.SiteActionBuilder | ||
import org.wordpress.android.fluxc.store.SiteStore | ||
import org.wordpress.android.fluxc.store.SiteStore.FetchJetpackCapabilitiesPayload | ||
import org.wordpress.android.fluxc.store.SiteStore.OnJetpackCapabilitiesFetched | ||
import org.wordpress.android.modules.BG_THREAD | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
import kotlin.coroutines.Continuation | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
class FetchJetpackCapabilitiesUseCase @Inject constructor( | ||
@Suppress("unused") private val siteStore: SiteStore, | ||
private val dispatcher: Dispatcher, | ||
@param:Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher | ||
) { | ||
private var continuation: Continuation<OnJetpackCapabilitiesFetched>? = null | ||
|
||
suspend fun fetchJetpackCapabilities(remoteSiteId: Long): OnJetpackCapabilitiesFetched { | ||
return withContext(bgDispatcher) { | ||
if (continuation != null) { | ||
throw IllegalStateException("Request already in progress.") | ||
} | ||
|
||
dispatcher.register(this@FetchJetpackCapabilitiesUseCase) | ||
suspendCoroutine { cont -> | ||
val payload = FetchJetpackCapabilitiesPayload(remoteSiteId) | ||
continuation = cont | ||
dispatcher.dispatch(SiteActionBuilder.newFetchJetpackCapabilitiesAction(payload)) | ||
} | ||
} | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.BACKGROUND) | ||
@SuppressWarnings("unused") | ||
fun onJetpackCapabilitiesFetched(event: OnJetpackCapabilitiesFetched) { | ||
dispatcher.unregister(this@FetchJetpackCapabilitiesUseCase) | ||
continuation?.resume(event) | ||
continuation = null | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
WordPress/src/main/java/org/wordpress/android/util/config/ActivityLogFiltersFeatureConfig.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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
package org.wordpress.android.util.config | ||
|
||
import org.wordpress.android.BuildConfig | ||
import org.wordpress.android.annotation.FeatureInDevelopment | ||
import org.wordpress.android.annotation.Feature | ||
import org.wordpress.android.util.config.ActivityLogFiltersFeatureConfig.Companion.ACTIVITY_LOG_FILTERS | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Configuration of the Activity Log Filters feature. | ||
*/ | ||
@FeatureInDevelopment | ||
@Feature(remoteField = ACTIVITY_LOG_FILTERS) | ||
class ActivityLogFiltersFeatureConfig | ||
@Inject constructor(appConfig: AppConfig) : FeatureConfig( | ||
appConfig, | ||
BuildConfig.ACTIVITY_LOG_FILTERS | ||
) | ||
BuildConfig.ACTIVITY_LOG_FILTERS, | ||
ACTIVITY_LOG_FILTERS | ||
) { | ||
companion object { | ||
const val ACTIVITY_LOG_FILTERS = "activity_log_filters_enabled" | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...ess/src/test/java/org/wordpress/android/ui/jetpack/FetchJetpackCapabilitiesUseCaseTest.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,65 @@ | ||
package org.wordpress.android.ui.jetpack | ||
|
||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import com.nhaarman.mockitokotlin2.any | ||
import com.nhaarman.mockitokotlin2.verify | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.wordpress.android.TEST_DISPATCHER | ||
import org.wordpress.android.fluxc.Dispatcher | ||
import org.wordpress.android.fluxc.store.SiteStore | ||
import org.wordpress.android.fluxc.store.SiteStore.OnJetpackCapabilitiesFetched | ||
import org.wordpress.android.test | ||
|
||
private const val SITE_ID = 1L | ||
@InternalCoroutinesApi | ||
@RunWith(MockitoJUnitRunner::class) | ||
class FetchJetpackCapabilitiesUseCaseTest { | ||
@Rule | ||
@JvmField val rule = InstantTaskExecutorRule() | ||
|
||
@Mock private lateinit var dispatcher: Dispatcher | ||
@Mock private lateinit var store: SiteStore | ||
private lateinit var useCase: FetchJetpackCapabilitiesUseCase | ||
private lateinit var event: OnJetpackCapabilitiesFetched | ||
|
||
@Before | ||
fun setUp() { | ||
useCase = FetchJetpackCapabilitiesUseCase(store, dispatcher, TEST_DISPATCHER) | ||
event = OnJetpackCapabilitiesFetched(SITE_ID, listOf(), null) | ||
} | ||
|
||
@Test | ||
fun `coroutine resumed, when result event dispatched`() = test { | ||
whenever(dispatcher.dispatch(any())).then { useCase.onJetpackCapabilitiesFetched(event) } | ||
|
||
val resultEvent = useCase.fetchJetpackCapabilities(SITE_ID) | ||
|
||
assertThat(resultEvent).isEqualTo(event) | ||
} | ||
|
||
@Test | ||
fun `useCase subscribes to event bus`() = test { | ||
whenever(dispatcher.dispatch(any())).then { useCase.onJetpackCapabilitiesFetched(event) } | ||
|
||
useCase.fetchJetpackCapabilities(SITE_ID) | ||
|
||
verify(dispatcher).register(useCase) | ||
} | ||
|
||
@Test | ||
fun `useCase unsubscribes from event bus`() = test { | ||
whenever(dispatcher.dispatch(any())).then { useCase.onJetpackCapabilitiesFetched(event) } | ||
|
||
useCase.fetchJetpackCapabilities(SITE_ID) | ||
|
||
verify(dispatcher).unregister(useCase) | ||
} | ||
} |
Oops, something went wrong.