Skip to content

Commit

Permalink
Merge pull request #20580 from wordpress-mobile/fix/failing-unit-test…
Browse files Browse the repository at this point in the history
…s-in-PostListItemUiStateHelperTest

Fix failing unit tests in post list item UI state helper test
  • Loading branch information
notandyvee authored Apr 3, 2024
2 parents 25e1b6f + deee44f commit 15001b9
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.AppLog.T.POSTS
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.util.HtmlUtils
import org.wordpress.android.viewmodel.pages.PostModelUploadUiStateUseCase
import org.wordpress.android.viewmodel.pages.PostModelUploadUiStateUseCase.PostUploadUiState
Expand Down Expand Up @@ -76,6 +77,7 @@ class PostListItemUiStateHelper @Inject constructor(
private val labelColorUseCase: PostPageListLabelColorUseCase,
private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper,
private val blazeFeatureUtils: BlazeFeatureUtils,
private val buildConfigWrapper: BuildConfigWrapper
) {
@Suppress("LongParameterList", "LongMethod")
fun createPostListItemUiState(
Expand Down Expand Up @@ -438,7 +440,7 @@ class PostListItemUiStateHelper @Inject constructor(

if (canShowViewButton) {
buttonTypes.addViewOrPreviewAction(isLocalDraft || isLocallyChanged)
if (BuildConfig.IS_JETPACK_APP) {
if (buildConfigWrapper.isJetpackApp) {
buttonTypes.addReadAction(isLocalDraft || isLocallyChanged)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.wordpress.android.ui.posts.PostModelUploadStatusTracker
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.ui.utils.UiString.UiStringText
import org.wordpress.android.ui.utils.UiString.UiStringRes
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.viewmodel.pages.PostModelUploadUiStateUseCase
import org.wordpress.android.viewmodel.pages.PostModelUploadUiStateUseCase.PostUploadUiState.UploadFailed
import org.wordpress.android.viewmodel.pages.PostModelUploadUiStateUseCase.PostUploadUiState.UploadQueued
Expand Down Expand Up @@ -66,6 +67,9 @@ class PostListItemUiStateHelperTest {
@Mock
private lateinit var blazeFeatureUtils: BlazeFeatureUtils

@Mock
private lateinit var buildConfigWrapper: BuildConfigWrapper

private lateinit var helper: PostListItemUiStateHelper

@Before
Expand All @@ -75,9 +79,11 @@ class PostListItemUiStateHelperTest {
uploadUiStateUseCase,
labelColorUseCase,
jetpackFeatureRemovalPhaseHelper,
blazeFeatureUtils
blazeFeatureUtils,
buildConfigWrapper
)
whenever(appPrefsWrapper.isAztecEditorEnabled).thenReturn(true)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
}

@Test
Expand All @@ -88,7 +94,8 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `verify draft actions`() {
fun `given wordpress app, verify draft actions`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_DRAFT)
)
Expand All @@ -100,6 +107,21 @@ class PostListItemUiStateHelperTest {
assertThat(state.moreActions.actions).hasSize(5)
}

@Test
fun `given jetpack app, verify draft actions`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_DRAFT)
)
assertThat(state.moreActions.actions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(state.moreActions.actions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(state.moreActions.actions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_PUBLISH)
assertThat(state.moreActions.actions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_COPY)
assertThat(state.moreActions.actions[4].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(state.moreActions.actions[5].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(state.moreActions.actions).hasSize(6)
}

@Test
fun `verify local draft actions`() {
val state = createPostListItemUiState(
Expand All @@ -114,7 +136,8 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `verify draft actions without publishing rights`() {
fun `given wordpress app, verify draft actions without publishing rights`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_DRAFT),
capabilitiesToPublish = false
Expand All @@ -129,6 +152,24 @@ class PostListItemUiStateHelperTest {
assertThat(moreActions).hasSize(5)
}

@Test
fun `given jetpack app, verify draft actions without publishing rights`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_DRAFT),
capabilitiesToPublish = false
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_SUBMIT)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_COPY)
assertThat(moreActions[4].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[5].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(6)
}

@Test
fun `verify local draft actions without publishing rights`() {
val state = createPostListItemUiState(
Expand Down Expand Up @@ -212,8 +253,9 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `verify published post actions`() {
fun `given wordpress app, verify published post actions`() {
whenever(jetpackFeatureRemovalPhaseHelper.shouldShowPublishedPostStatsButton()).thenReturn(true)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH)
)
Expand All @@ -230,10 +272,31 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `verify published post actions when stats are not supported`() {
fun `given jetpack app, verify published post actions`() {
whenever(jetpackFeatureRemovalPhaseHelper.shouldShowPublishedPostStatsButton()).thenReturn(true)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH)
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_MOVE_TO_DRAFT)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_COPY)
assertThat(moreActions[4].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[5].buttonType).isEqualTo(PostListButtonType.BUTTON_STATS)
assertThat(moreActions[6].buttonType).isEqualTo(PostListButtonType.BUTTON_COMMENTS)
assertThat(moreActions[7].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(8)
}

@Test
fun `given wordpress app, verify published post actions when stats are not supported`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH),
statsSupported = false
statsSupported = false,
)

val moreActions = state.moreActions.actions
Expand All @@ -247,8 +310,28 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `given published post with stats access when jetpack removal phase then stats is in menu`() {
fun `given jetpack app, verify published post actions when stats are not supported`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH),
statsSupported = false,
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_MOVE_TO_DRAFT)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_COPY)
assertThat(moreActions[4].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[5].buttonType).isEqualTo(PostListButtonType.BUTTON_COMMENTS)
assertThat(moreActions[6].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(7)
}

@Test
fun `given wordpress app, published post with stats access when jetpack removal phase then stats is in menu`() {
whenever(jetpackFeatureRemovalPhaseHelper.shouldShowPublishedPostStatsButton()).thenReturn(true)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH)
)
Expand All @@ -265,8 +348,29 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `given published post with stats access when not jetpack removal phase then stats is not in menu`() {
fun `given jetpack app, published post with stats access when jetpack removal phase then stats is in menu`() {
whenever(jetpackFeatureRemovalPhaseHelper.shouldShowPublishedPostStatsButton()).thenReturn(true)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH)
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_MOVE_TO_DRAFT)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_COPY)
assertThat(moreActions[4].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[5].buttonType).isEqualTo(PostListButtonType.BUTTON_STATS)
assertThat(moreActions[6].buttonType).isEqualTo(PostListButtonType.BUTTON_COMMENTS)
assertThat(moreActions[7].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(8)
}

@Test
fun `given wordpress, published post with stats access when not jetpack removal phase then stats is not in menu`() {
whenever(jetpackFeatureRemovalPhaseHelper.shouldShowPublishedPostStatsButton()).thenReturn(false)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH)
)
Expand All @@ -281,6 +385,24 @@ class PostListItemUiStateHelperTest {
assertThat(moreActions).hasSize(6)
}

@Test
fun `given jetpack, published post with stats access when not jetpack removal phase then stats is not in menu`() {
whenever(jetpackFeatureRemovalPhaseHelper.shouldShowPublishedPostStatsButton()).thenReturn(false)
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PUBLISH)
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_MOVE_TO_DRAFT)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_COPY)
assertThat(moreActions[4].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[5].buttonType).isEqualTo(PostListButtonType.BUTTON_COMMENTS)
assertThat(moreActions[6].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(7)
}
@Test
fun `verify published post with changes actions`() {
val state = createPostListItemUiState(
Expand Down Expand Up @@ -329,7 +451,8 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `verify scheduled post actions`() {
fun `given wordpress app, verify scheduled post actions`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_SCHEDULED)
)
Expand All @@ -341,6 +464,21 @@ class PostListItemUiStateHelperTest {
assertThat(moreActions).hasSize(3)
}

@Test
fun `given jetpack app, verify scheduled post actions`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_SCHEDULED)
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(4)
}

@Test
fun `verify scheduled post with changes actions`() {
val state = createPostListItemUiState(
Expand Down Expand Up @@ -385,7 +523,8 @@ class PostListItemUiStateHelperTest {
}

@Test
fun `verify post pending review without publishing rights`() {
fun `given wordpress app, verify post pending review without publishing rights`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PENDING),
capabilitiesToPublish = false
Expand All @@ -398,6 +537,21 @@ class PostListItemUiStateHelperTest {
assertThat(moreActions).hasSize(3)
}

@Test
fun `given jetpack app, verify post pending review without publishing rights`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)
val state = createPostListItemUiState(
post = createPostModel(status = POST_STATE_PENDING),
capabilitiesToPublish = false
)

val moreActions = state.moreActions.actions
assertThat(moreActions[0].buttonType).isEqualTo(PostListButtonType.BUTTON_VIEW)
assertThat(moreActions[1].buttonType).isEqualTo(PostListButtonType.BUTTON_READ)
assertThat(moreActions[2].buttonType).isEqualTo(PostListButtonType.BUTTON_SHARE)
assertThat(moreActions[3].buttonType).isEqualTo(PostListButtonType.BUTTON_TRASH)
assertThat(moreActions).hasSize(4)
}
@Test
fun `verify published post with local changes eligible for auto upload`() {
whenever(uploadUiStateUseCase.createUploadUiState(anyOrNull(), anyOrNull(), anyOrNull())).thenReturn(
Expand Down

0 comments on commit 15001b9

Please sign in to comment.