Skip to content

Commit

Permalink
Merge pull request #10212 from wordpress-mobile/issue/10161-hide-auto…
Browse files Browse the repository at this point in the history
…save-preview-on-jetpack-site

Hide previews for published posts on Jetpack sites
  • Loading branch information
shiki authored Aug 2, 2019
2 parents 1e8617f + 02779c3 commit 1655dfb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,23 @@ class RemotePreviewLogicHelper @Inject constructor(
helperFunctions.notifyEmptyDraft()
return PreviewLogicOperationResult.CANNOT_SAVE_EMPTY_DRAFT
}

helperFunctions.startUploading(false, updatedPost)
} else if (shouldRemoteAutoSave(updatedPost)) {
if (!postUtilsWrapper.isPublishable(updatedPost)) {
helperFunctions.notifyEmptyPost()
return PreviewLogicOperationResult.CANNOT_REMOTE_AUTO_SAVE_EMPTY_POST
}
// TODO: remove the following Jetpack exception when the API bug for Jetpack sites is fixed
// and previewing auto-saves are working. More informations about this on the following ticket:
// https://github.com/Automattic/wp-calypso/issues/20265
if (site.isJetpackConnected) {
activityLauncherWrapper.showActionableEmptyView(
activity,
WPWebViewUsageCategory.REMOTE_PREVIEW_NOT_AVAILABLE,
post.title
)
return PreviewLogicOperationResult.PREVIEW_NOT_AVAILABLE
}
helperFunctions.startUploading(true, updatedPost)
} else {
activityLauncherWrapper.previewPostOrPageForResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.lenient
import org.mockito.junit.MockitoJUnitRunner
import org.wordpress.android.fluxc.model.PostModel
import org.wordpress.android.fluxc.model.SiteModel
Expand Down Expand Up @@ -237,4 +238,68 @@ class RemotePreviewLogicHelperTest {
RemotePreviewLogicHelper.RemotePreviewType.REMOTE_PREVIEW
)
}

@Test
fun `preview not available for Jetpack sites on published post with modification`() {
// Given
doReturn(true).whenever(site).isJetpackConnected
doReturn(PostStatus.PUBLISHED.toString()).whenever(post).status
doReturn(true).whenever(post).isLocallyChanged

// When
val result = remotePreviewLogicHelper.runPostPreviewLogic(activity, site, post, mock())

// Then
assertThat(result).isEqualTo(RemotePreviewLogicHelper.PreviewLogicOperationResult.PREVIEW_NOT_AVAILABLE)
verify(activityLauncherWrapper, times(1)).showActionableEmptyView(
activity,
WPWebViewUsageCategory.REMOTE_PREVIEW_NOT_AVAILABLE,
post.title
)
}

@Test
fun `preview available for Jetpack sites on draft with modification`() {
// Given
// next stub not used (made lenient) in case we update future logic.
lenient().doReturn(true).whenever(site).isJetpackConnected
doReturn(true).whenever(post).isLocallyChanged

// When
val result = remotePreviewLogicHelper.runPostPreviewLogic(activity, site, post, helperFunctions)

// Then
assertThat(result).isEqualTo(RemotePreviewLogicHelper.PreviewLogicOperationResult.GENERATING_PREVIEW)
verify(helperFunctions, times(1)).startUploading(false, post)
}

@Test
fun `preview available for Jetpack sites on published post without modification`() {
// Given
// next stub not used (made lenient) in case we update future logic
lenient().doReturn(true).whenever(site).isJetpackConnected
doReturn(PostStatus.PUBLISHED.toString()).whenever(post).status
doReturn(false).whenever(post).isLocallyChanged

// When
val result = remotePreviewLogicHelper.runPostPreviewLogic(activity, site, post, helperFunctions)

// Then
assertThat(result).isEqualTo(RemotePreviewLogicHelper.PreviewLogicOperationResult.OPENING_PREVIEW)
verify(helperFunctions, never()).startUploading(false, post)
}

@Test
fun `preview available for Jetpack sites on draft without modification`() {
// Given
lenient().doReturn(true).whenever(site).isJetpackConnected
doReturn(false).whenever(post).isLocallyChanged

// When
val result = remotePreviewLogicHelper.runPostPreviewLogic(activity, site, post, helperFunctions)

// Then
assertThat(result).isEqualTo(RemotePreviewLogicHelper.PreviewLogicOperationResult.OPENING_PREVIEW)
verify(helperFunctions, never()).startUploading(false, post)
}
}

0 comments on commit 1655dfb

Please sign in to comment.