Skip to content

Commit

Permalink
Merge branch 'trunk' into issue/mysite-cards-m3
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury authored Nov 11, 2024
2 parents 4f91b45 + 17f9039 commit c0fb895
Show file tree
Hide file tree
Showing 29 changed files with 137 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .configure
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"project_name": "WordPress-Android",
"branch": "trunk",
"pinned_hash": "4b536af182cc61c263b07262e41c141f06fd5de6",
"pinned_hash": "04a650613d9f0bb3fde8f0961e2494343f0df26d",
"files_to_copy": [
{
"file": "android/WPAndroid/gradle.properties",
Expand Down
Binary file modified .configure-files/gradle.properties.enc
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ local-builds.gradle
# gitignore for retrocompatibility, so that it won't appear as a new file and
# be accidentally checked in the repository.
google-upload-credentials.json

# Kotlin
.kotlin/
31 changes: 18 additions & 13 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import io.sentry.android.gradle.extensions.InstrumentationFeature
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.kotlin.allopen)
alias(libs.plugins.sentry)
Expand Down Expand Up @@ -191,8 +193,8 @@ android {
compileOptions {
// Enables Java 8+ API desugaring support
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JvmTarget.fromTarget(libs.versions.java.get()).target
targetCompatibility JvmTarget.fromTarget(libs.versions.java.get()).target
}

flavorDimensions "app", "buildType"
Expand Down Expand Up @@ -330,10 +332,6 @@ android {
buildConfig true
viewBinding true
compose true

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}
}
}

Expand Down Expand Up @@ -590,25 +588,32 @@ if ((file('google-services.json').text) == (file('google-services.json-example')
}

tasks.register("printVersionName") {
def versionName = android.defaultConfig.versionName
doLast {
println android.defaultConfig.versionName
println versionName
}
}

tasks.register("printAllVersions") {
def versions = android.applicationVariants.collect {
[it.name, it.versionName, it.versionCode]
}

doLast {
android.applicationVariants.all { variant ->
println "${variant.name}: ${variant.versionName} (${variant.versionCode})"
versions.each { name, versionName, versionCode ->
println "$name: $versionName ($versionCode)"
}
}
}

tasks.register("printResourceConfigurations") {
def flavorInfo = android.productFlavors
.findAll { it.dimension == "app" }
.collect { [it.name, it.resourceConfigurations] }

doLast {
android.productFlavors.each { flavor ->
if (flavor.dimension == "app") {
println "${flavor.name}: ${flavor.resourceConfigurations}"
}
flavorInfo.each { name, resourceConfigurations ->
println "$name: $resourceConfigurations"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SupportWebViewClient(
}

// to support API < 21
@Deprecated("Deprecated in Java")
override fun shouldInterceptRequest(
view: WebView,
url: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ class SignupEpilogueFragment : LoginBaseFormFragment<SignupEpilogueListener?>(),
}
}

@Deprecated("Deprecated in Java")
@Suppress("deprecation", "NestedBlockDepth", "LongMethod")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class JetpackMigrationFragment : Fragment() {
}
}

@Deprecated("Deprecated in Java")
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (requestCode == WPPermissionUtils.NOTIFICATIONS_PERMISSION_REQUEST_CODE) {
WPPermissionUtils.setPermissionListAsked(requireActivity(), requestCode, permissions, grantResults, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.wordpress.android.ui.sitecreation.services.SiteCreationServiceState.S
import org.wordpress.android.ui.sitecreation.services.SiteCreationServiceState.SiteCreationStep.SUCCESS
import org.wordpress.android.util.AutoForeground

data class SiteCreationServiceState internal constructor(
data class SiteCreationServiceState(
val step: SiteCreationStep,
val payload: Any? = null
) : AutoForeground.ServiceState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class EnumWithFallbackValueTypeAdapterFactory : TypeAdapterFactory {
.asSequence()
.filter { it.type == type.rawType && it.isAnnotationPresent(FallbackValue::class.java) }
.map { field ->
@Suppress("UNCHECKED_CAST")
type.rawType.enumConstants.single { enumValue ->
@Suppress("UNCHECKED_CAST", "UNNECESSARY_SAFE_CALL")
type?.rawType?.enumConstants?.single { enumValue ->
field.get(null) == enumValue
} as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ internal class WPRemoteResourceViewTarget(
drawable?.colorFilter = colorFilter
}

@Deprecated("Deprecated in Java")
@Suppress("DEPRECATION")
override fun getOpacity(): Int {
return drawable?.opacity ?: PixelFormat.UNKNOWN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MigrationEmailHelperTest : BaseUnitTest() {

@Test
fun `Should call migrationComplete when notifyMigrationComplete is called`() = test {
whenever(jetpackMigrationStore.migrationComplete()).thenReturn(MigrationCompleteFetchedPayload.Success)
classToTest.notifyMigrationComplete()
verify(jetpackMigrationStore).migrationComplete()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ class CampaignListingViewModelTest : BaseUnitTest() {
}

@Test
fun `when viewmodel start, then should track campaign listing page shown`() {
fun `when viewmodel start, then should track campaign listing page shown`() = runTest {
val campaignFetchResult: Result<NoCampaigns, List<CampaignModel>> = Result.Success(mock())
whenever(getCampaignListFromDbUseCase.execute(siteModel)).thenReturn(campaignFetchResult)

viewModel.start(CampaignListingPageSource.DASHBOARD_CARD)
advanceUntilIdle()

assertThat(uiStates.first() is CampaignListingUiState.Loading).isTrue
verify(blazeFeatureUtils).trackCampaignListingPageShown(CampaignListingPageSource.DASHBOARD_CARD)
Expand Down Expand Up @@ -148,8 +152,8 @@ class CampaignListingViewModelTest : BaseUnitTest() {
whenever(selectedSiteRepository.getSelectedSite()).thenReturn(siteModel)
whenever(getCampaignListFromDbUseCase.execute(siteModel)).thenReturn(campaignFetchResult)


viewModel.start(CampaignListingPageSource.DASHBOARD_CARD)
advanceUntilIdle()
val success = uiStates.last() as CampaignListingUiState.Success
success.itemClick.invoke(success.campaigns.first())

Expand All @@ -164,6 +168,7 @@ class CampaignListingViewModelTest : BaseUnitTest() {


viewModel.start(CampaignListingPageSource.DASHBOARD_CARD)
advanceUntilIdle()
val success = uiStates.last() as CampaignListingUiState.Success
success.createCampaignClick.invoke()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class ThreatDetailsViewModelTest : BaseUnitTest() {

@Test
fun `when ok button on fix action confirmation dialog is clicked, then action buttons are disabled`() = test {
whenever(fixThreatsUseCase.fixThreats(any(), any())).thenReturn(FixThreatsState.Success)
val observers = init()

triggerFixThreatAction(observers)
Expand Down Expand Up @@ -327,6 +328,7 @@ class ThreatDetailsViewModelTest : BaseUnitTest() {

@Test
fun `when ok button on ignore action confirmation dialog is clicked, then action buttons are disabled`() = test {
whenever(ignoreThreatUseCase.ignoreThreat(any(), any())).thenReturn(Success)
val observers = init()

triggerIgnoreThreatAction(observers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ class ReaderInterestsViewModelTest : BaseUnitTest() {
val interests = getInterests()
whenever(readerTagRepository.getInterests()).thenReturn(SuccessWithData(interests))
val selectInterestAtIndex = 2
whenever(readerTagRepository.saveInterests(eq(listOf(interests[selectInterestAtIndex]))))
.thenReturn(Success)

// When
initViewModel()
Expand Down Expand Up @@ -566,7 +568,7 @@ class ReaderInterestsViewModelTest : BaseUnitTest() {
}

@Test
fun `discover close reader screen on back button click`() {
fun `discover close reader screen on back button click`() = testWithEmptyUserTags {
// When
initViewModel(EntryPoint.DISCOVER)

Expand All @@ -577,7 +579,7 @@ class ReaderInterestsViewModelTest : BaseUnitTest() {
}

@Test
fun `settings close reader screen on back button click`() {
fun `settings close reader screen on back button click`() = testWithEmptyUserTags {
// When
initViewModel(EntryPoint.SETTINGS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
fun `given local post not found, when show post is triggered, then loading state is shown`() =
testWithoutLocalPost {
val observers = init(showPost = false)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(FetchReaderPostState.Success)

viewModel.onShowPost(blogId = readerPost.blogId, postId = readerPost.postId)

Expand Down Expand Up @@ -383,6 +385,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
fun `given local post not found, when show post is triggered, then post is fetched from remote server`() =
testWithoutLocalPost {
init(showPost = false)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(FetchReaderPostState.Success)

viewModel.onShowPost(blogId = readerPost.blogId, postId = readerPost.postId)

Expand Down Expand Up @@ -422,8 +426,11 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
/* SHOW POST - FETCH ERROR HANDLING */
@Test
fun `given no network, when post is fetched, then no network message is shown`() = testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init()
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean())).thenReturn(Failed.NoNetwork)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NoNetwork)

viewModel.onShowPost(blogId = readerPost.blogId, postId = readerPost.postId)

Expand All @@ -432,6 +439,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {

@Test
fun `given request failed, when post is fetched, then request failed message is shown`() = testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init()
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.RequestFailed)
Expand All @@ -444,6 +453,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given request already running, when post is fetched, then no error is shown`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init()
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(AlreadyRunning)
Expand All @@ -455,6 +466,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {

@Test
fun `given post not found, when post is fetched, then post not found message is shown`() = testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init()
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.PostNotFound)
Expand All @@ -467,6 +480,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {

@Test
fun `given unauthorised, when post is fetched, then error ui is shown`() = testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init()
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.PostNotFound)
Expand All @@ -479,6 +494,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given unauthorised with signin offer, when error ui shown, then sign in button is visible`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init(offerSignIn = true)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NotAuthorised)
Expand All @@ -491,6 +508,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given unauthorised without signin offer, when error ui shown, then sign in button is not visible`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init(offerSignIn = false)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NotAuthorised)
Expand All @@ -503,6 +522,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given unauthorised with no signin offer and no intercept uri, when error ui shown, then correct msg exists`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init(offerSignIn = false, interceptedUrPresent = false)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NotAuthorised)
Expand All @@ -516,6 +537,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given unauthorised with no signin offer and intercept uri, when error ui shown, then correct msg exists`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init(offerSignIn = false, interceptedUrPresent = true)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NotAuthorised)
Expand All @@ -529,6 +552,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given unauthorised with signin offer and no intercept uri, when error ui shown, then correct msg exists`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init(offerSignIn = true, interceptedUrPresent = false)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NotAuthorised)
Expand All @@ -542,6 +567,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given unauthorised with signin offer and intercept uri, when error ui shown, then correct msg exists`() =
testWithoutLocalPost {
whenever(readerFetchPostUseCase.fetchPost(readerPost.blogId, readerPost.postId, viewModel.isFeed))
.thenReturn(FetchReaderPostState.Success)
val observers = init(offerSignIn = true, interceptedUrPresent = true)
whenever(readerFetchPostUseCase.fetchPost(anyLong(), anyLong(), anyBoolean()))
.thenReturn(Failed.NotAuthorised)
Expand Down Expand Up @@ -811,7 +838,8 @@ class ReaderPostDetailViewModelTest : BaseUnitTest() {
@Test
fun `given wp com post, when related posts are requested, then related posts are fetched`() =
test {
whenever(readerFetchRelatedPostsUseCase.fetchRelatedPosts(readerPost)).thenReturn(mock())
whenever(readerFetchRelatedPostsUseCase.fetchRelatedPosts(readerPost))
.thenReturn(FetchRelatedPostsState.Success(ReaderSimplePostList(), ReaderSimplePostList()))

viewModel.onRelatedPostsRequested(readerPost)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ class StatsViewModelTest : BaseUnitTest() {
@Test
fun `given enable stats module is clicked, then state reflects progress`() = test {
val uiModel = initObservers().uiModelObserver
whenever(statsModuleActivateUseCase.postActivateStatsModule(anyOrNull())).thenReturn(success)

startViewModel(statsModuleEnabled = false)
viewModel.onEnableStatsModuleClick()

assertThat(uiModel.last().disabledStatsProgressVisible).isTrue
assertThat(uiModel.last().disabledStatsProgressVisible).isFalse()
}

@Test
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.automattic.android.measure.reporters.InternalA8cCiReporter
import com.automattic.android.measure.reporters.SlowSlowTasksMetricsReporter
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -13,6 +14,7 @@ plugins {
alias(libs.plugins.google.services).apply(false)
alias(libs.plugins.kotlin.allopen).apply(false)
alias(libs.plugins.kotlin.android).apply(false)
alias(libs.plugins.kotlin.compose).apply(false)
alias(libs.plugins.kotlin.jvm).apply(false)
alias(libs.plugins.kotlin.parcelize).apply(false)
alias(libs.plugins.kotlin.serialization).apply(false)
Expand Down Expand Up @@ -69,7 +71,7 @@ allprojects {

tasks.withType(KotlinCompile).all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
jvmTarget = JvmTarget.fromTarget(libs.versions.java.get()).target
allWarningsAsErrors = true
freeCompilerArgs += [
"-opt-in=kotlin.RequiresOptIn",
Expand Down
Loading

0 comments on commit c0fb895

Please sign in to comment.