Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prompts] Build dailyprompt-id tag in code based on the Prompt ID #19971

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [**] Block Editor: Image block media uploads display a custom error message when there is no internet connection [https://github.com/wordpress-mobile/WordPress-Android/pull/19878]
* [**] Block Editor: Media uploads that failed due to lack of internet connectivity automatically retry once a connection is re-established [https://github.com/wordpress-mobile/WordPress-Android/pull/19803]
* [*] [Jetpack-only] Added opening domain management from the Site Domain screen by tapping on the domain cards [https://github.com/wordpress-mobile/WordPress-Android/pull/19910]
* [*] [Jetpack-only] Fix Prompt response posts not having one of the `dailyprompt` tags [https://github.com/wordpress-mobile/WordPress-Android/pull/19971]

24.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class BloggingPromptsPostTagProvider @Inject constructor(
private val readerUtilsWrapper: ReaderUtilsWrapper,
) {
fun promptIdTag(
tagUrl: String
): String = readerUtilsWrapper.getTagFromTagUrl(tagUrl)
.takeIf { it.isNotBlank() }
id: Int
): String = "$BLOGGING_PROMPT_ID_TAG_PREFIX$id"
.takeIf { id > 0 }
?: BLOGGING_PROMPT_TAG

fun promptIdSearchReaderTag(
fun promptSearchReaderTag(
tagUrl: String
): ReaderTag {
val promptIdTag = promptIdTag(tagUrl)
val promptIdTag = promptTagFromUrl(tagUrl)
return ReaderTag(
promptIdTag,
promptIdTag,
Expand All @@ -28,8 +28,15 @@ class BloggingPromptsPostTagProvider @Inject constructor(
)
}

private fun promptTagFromUrl(
tagUrl: String
): String = readerUtilsWrapper.getTagFromTagUrl(tagUrl)
.takeIf { it.isNotBlank() }
?: BLOGGING_PROMPT_TAG

companion object {
const val BLOGGING_PROMPT_TAG = "dailyprompt"
const val BLOGGING_PROMPT_ID_TAG_PREFIX = "dailyprompt-"
const val BLOGANUARY_TAG = "bloganuary"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BloggingPromptCardViewModelSlice @Inject constructor(

private fun onBloggingPromptViewAnswersClick(tagUrl: String) {
bloggingPromptsCardAnalyticsTracker.trackMySiteCardViewAnswersClicked()
val tag = bloggingPromptsPostTagProvider.promptIdSearchReaderTag(tagUrl)
val tag = bloggingPromptsPostTagProvider.promptSearchReaderTag(tagUrl)
_onNavigation.value = Event(BloggingPromptCardNavigationAction.ViewAnswers(tag))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EditorBloggingPromptsViewModel

private fun createPromptTags(prompt: BloggingPromptModel): List<String> = mutableListOf<String>().apply {
add(BloggingPromptsPostTagProvider.BLOGGING_PROMPT_TAG)
add(bloggingPromptsPostTagProvider.promptIdTag(prompt.answeredLink))
add(bloggingPromptsPostTagProvider.promptIdTag(prompt.id))
prompt.bloganuaryId?.let { bloganuaryIdTag ->
add(BloggingPromptsPostTagProvider.BLOGANUARY_TAG)
add(bloganuaryIdTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,21 @@ class BloggingPromptsPostTagProviderTest : BaseUnitTest() {
}

@Test
fun `Should return the expected tag when promptIdTag is called given valid url`() {
whenever(readerUtilsWrapper.getTagFromTagUrl(any())).thenReturn(BLOGGING_PROMPT_ID_TAG)

val actual = tagProvider.promptIdTag("valid-url")
fun `Should return the expected tag when promptIdTag is called given valid id`() {
val actual = tagProvider.promptIdTag(1234)

assertThat(actual).isEqualTo(BLOGGING_PROMPT_ID_TAG)
}

@Test
fun `Should return the generic tag when promptIdTag is called given invalid url`() {
whenever(readerUtilsWrapper.getTagFromTagUrl(any())).thenReturn("")

val actual = tagProvider.promptIdTag("invalid-url")
fun `Should return the generic tag when promptIdTag is called given invalid id`() {
val actual = tagProvider.promptIdTag(0)

assertThat(actual).isEqualTo(BloggingPromptsPostTagProvider.BLOGGING_PROMPT_TAG)
}

@Test
fun `Should return the expected ReaderTag when promptIdSearchReaderTag is called`() {
fun `Should return the expected ReaderTag when promptSearchReaderTag is called`() {
whenever(readerUtilsWrapper.getTagFromTagUrl(any())).thenReturn(BLOGGING_PROMPT_ID_TAG)
val expected = ReaderTag(
BLOGGING_PROMPT_ID_TAG,
Expand All @@ -54,11 +50,26 @@ class BloggingPromptsPostTagProviderTest : BaseUnitTest() {
ReaderPostLogic.formatFullEndpointForTag(BLOGGING_PROMPT_ID_TAG),
ReaderTagType.FOLLOWED,
)
val actual = tagProvider.promptIdSearchReaderTag("valid-url")
val actual = tagProvider.promptSearchReaderTag("valid-url")
assertEquals(expected, actual)
}

@Test
fun `Should return the base Prompt ReaderTag when promptSearchReaderTag is called`() {
whenever(readerUtilsWrapper.getTagFromTagUrl(any())).thenReturn("")
val expected = ReaderTag(
BLOGGING_PROMPT_TAG,
BLOGGING_PROMPT_TAG,
BLOGGING_PROMPT_TAG,
ReaderPostLogic.formatFullEndpointForTag(BLOGGING_PROMPT_TAG),
ReaderTagType.FOLLOWED,
)
val actual = tagProvider.promptSearchReaderTag("invalid-url")
assertEquals(expected, actual)
}

companion object {
private const val BLOGGING_PROMPT_ID_TAG = "dailyprompt-1234"
private const val BLOGGING_PROMPT_TAG = "dailyprompt"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class BloggingPromptCardViewModelSliceTest : BaseUnitTest() {
val tagUrl = "valid-url"

val expectedTag = mock<ReaderTag>()
whenever(bloggingPromptsPostTagProvider.promptIdSearchReaderTag(tagUrl)).thenReturn(expectedTag)
whenever(bloggingPromptsPostTagProvider.promptSearchReaderTag(tagUrl)).thenReturn(expectedTag)

val params = viewModelSlice.getBuilderParams(mock())
params.onViewAnswersClick(tagUrl)
Expand Down
Loading