Skip to content

Commit 380fcc7

Browse files
committed
Add documentation and test for EditorLauncherParams field mapping
Ensures all EditorLauncherParams fields are handled in EditorLauncher.addEditorExtras() through documentation and a unit test that validates completeness. Changes: - Add cross-reference documentation in EditorLauncherParams and EditorLauncher - Add EditorLauncherTest with detailed field-to-method mapping documentation - Test validates that all fields are accounted for in addEditorExtras methods - Filter out Kotlin synthetic fields in test validation
1 parent 3bb2201 commit 380fcc7

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

WordPress/src/main/java/org/wordpress/android/ui/posts/EditorLauncher.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class EditorLauncher @Inject constructor(
7272

7373
/**
7474
* Adds all editor parameters as Intent extras.
75+
*
76+
* Each field in EditorLauncherParams must be handled by one of the add*Extras methods.
77+
* See EditorLauncherTest for complete field-to-method mapping documentation.
7578
*/
7679
private fun Intent.addEditorExtras(params: EditorLauncherParams) {
7780
addBasicExtras(params)

WordPress/src/main/java/org/wordpress/android/ui/posts/EditorLauncherParams.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import org.wordpress.android.ui.posts.PostUtils.EntryPoint
99
*
1010
* This data class replaces the Bundle-based approach with named parameters in Kotlin
1111
* and provides a builder pattern for Java compatibility.
12+
*
13+
* All fields are mapped to Intent extras in EditorLauncher.addEditorExtras().
14+
* See EditorLauncherTest for field-to-method mapping documentation.
1215
*/
1316
data class EditorLauncherParams(
1417
val site: SiteModel,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.wordpress.android.ui.posts
2+
3+
import org.junit.Test
4+
import org.junit.Assert.assertEquals
5+
6+
class EditorLauncherTest {
7+
@Test
8+
fun `all EditorLauncherParams fields should be handled in addEditorExtras`() {
9+
// This test ensures that every field in EditorLauncherParams is handled by one of the
10+
// add*Extras methods in EditorLauncher. When adding new fields to EditorLauncherParams,
11+
// you must update both this test and the corresponding add*Extras method.
12+
13+
val handledFields = setOf(
14+
// addBasicExtras()
15+
"site", // -> WordPress.SITE
16+
"isPage", // -> EditPostActivityConstants.EXTRA_IS_PAGE
17+
"isPromo", // -> EditPostActivityConstants.EXTRA_IS_PROMO
18+
19+
// addPostExtras()
20+
"postLocalId", // -> EditPostActivityConstants.EXTRA_POST_LOCAL_ID
21+
"postRemoteId", // -> EditPostActivityConstants.EXTRA_POST_REMOTE_ID
22+
"loadAutoSaveRevision", // -> EditPostActivityConstants.EXTRA_LOAD_AUTO_SAVE_REVISION
23+
"isQuickPress", // -> EditPostActivityConstants.EXTRA_IS_QUICKPRESS
24+
"isLandingEditor", // -> EditPostActivityConstants.EXTRA_IS_LANDING_EDITOR
25+
"isLandingEditorOpenedForNewSite", // -> EditPostActivityConstants.EXTRA_IS_LANDING_EDITOR_OPENED_FOR_NEW_SITE
26+
27+
// addReblogExtras()
28+
"reblogPostTitle", // -> EditPostActivityConstants.EXTRA_REBLOG_POST_TITLE
29+
"reblogPostQuote", // -> EditPostActivityConstants.EXTRA_REBLOG_POST_QUOTE
30+
"reblogPostImage", // -> EditPostActivityConstants.EXTRA_REBLOG_POST_IMAGE
31+
"reblogPostCitation", // -> EditPostActivityConstants.EXTRA_REBLOG_POST_CITATION
32+
"reblogAction", // -> Intent.setAction()
33+
34+
// addPageExtras()
35+
"pageTitle", // -> EditPostActivityConstants.EXTRA_PAGE_TITLE
36+
"pageContent", // -> EditPostActivityConstants.EXTRA_PAGE_CONTENT
37+
"pageTemplate", // -> EditPostActivityConstants.EXTRA_PAGE_TEMPLATE
38+
39+
// addMiscExtras()
40+
"voiceContent", // -> EditPostActivityConstants.EXTRA_VOICE_CONTENT
41+
"insertMedia", // -> EditPostActivityConstants.EXTRA_INSERT_MEDIA
42+
"source", // -> AnalyticsUtils.EXTRA_CREATION_SOURCE_DETAIL
43+
"promptId", // -> EditPostActivityConstants.EXTRA_PROMPT_ID
44+
"entryPoint" // -> EditPostActivityConstants.EXTRA_ENTRY_POINT
45+
)
46+
47+
val actualFields = EditorLauncherParams::class.java.declaredFields
48+
.filter { !it.isSynthetic && !it.name.contains("$") } // Filter out Kotlin synthetic fields
49+
.map { it.name }
50+
.toSet()
51+
52+
assertEquals(
53+
"All EditorLauncherParams fields must be handled in addEditorExtras(). " +
54+
"Missing: ${actualFields - handledFields}, " +
55+
"Extra: ${handledFields - actualFields}",
56+
handledFields,
57+
actualFields
58+
)
59+
}
60+
}

0 commit comments

Comments
 (0)