|
| 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