diff --git a/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExerciseMediaAttachGateTest.kt b/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExerciseMediaAttachGateTest.kt new file mode 100644 index 000000000..a88c716aa --- /dev/null +++ b/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExerciseMediaAttachGateTest.kt @@ -0,0 +1,98 @@ +package com.devil.phoenixproject.presentation.components + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsEnabled +import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import com.devil.phoenixproject.data.media.AndroidExerciseMediaStore +import java.io.File +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +/** + * Component-level SD10 behavior of [ExerciseMediaAttachments], the gate section + * the create/edit dialog hosts: `Add photos` follows the `enableAttach` input + * (the USER's Exercise Demos preference), and the preference-OFF notice shows + * exactly when attach is disabled. + * + * Scope note (issue #1358 test hygiene, N1): these tests deliberately claim + * ONLY component behavior. They mount the gate with a caller-supplied + * `enableAttach` constant and say nothing about how any host wires that input — + * the previous `routineEditorHost_*`/`workoutAddHost_*` names claimed host + * coverage that mounting this component cannot deliver (all five old tests + * kept passing with `enablePhotoAttach = enableVideoPlayback` put back in + * ExercisePicker.kt). Real forwarding coverage lives in + * [ExercisePickerDialogPhotoAttachForwardingTest], which renders the actual + * [ExercisePickerDialog], opens the create dialog and fails under that + * mutation; the source-string drift guard `ExerciseMediaWiringTest + * .photoAttachGateIsDecoupledFromListThumbnailFlagAtBothHosts` holds the + * remaining wiring shapes. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], qualifiers = "w1280dp-h900dp") +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class ExerciseMediaAttachGateTest { + + @get:Rule + val rule = createComposeRule() + + private lateinit var mediaRoot: File + + @Before + fun setUp() { + mediaRoot = File.createTempFile("picker-photo-attach-test", "").let { f -> + f.delete() + f.mkdirs() + f + } + } + + @After + fun tearDown() { + mediaRoot.deleteRecursively() + } + + private fun attachStore() = AndroidExerciseMediaStore( + mediaRoot = File(mediaRoot, "media"), + openPickedStream = { handle -> File(handle).takeIf { it.isFile }?.inputStream() }, + ) + + /** The gate section exactly as the create/edit dialog hosts it (SD2/SD10). */ + private fun mountAttachGate(enableAttach: Boolean) { + rule.setContent { + ExerciseMediaAttachments( + coordinator = ExerciseMediaSaveCoordinator(attachStore()), + savedImages = emptyList(), + enableAttach = enableAttach, + onRequestPick = {}, + ) + } + rule.waitForIdle() + } + + private fun addPhotosButton() = rule.onNodeWithText("Add photos") + + private fun preferenceOffNotice() = + rule.onNodeWithText("Exercise Demos is off. Enable it in Settings to add or view photos.") + + @Test + fun gateOn_addPhotosEnabled_noPreferenceOffNotice() { + mountAttachGate(enableAttach = true) + addPhotosButton().assertIsEnabled() + preferenceOffNotice().assertDoesNotExist() + } + + @Test + fun gateOff_addPhotosDisabled_preferenceOffNoticeShown() { + mountAttachGate(enableAttach = false) + addPhotosButton().assertIsNotEnabled() + preferenceOffNotice().assertIsDisplayed() + } +} diff --git a/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExercisePickerDialogPhotoAttachForwardingTest.kt b/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExercisePickerDialogPhotoAttachForwardingTest.kt new file mode 100644 index 000000000..f6f97b29e --- /dev/null +++ b/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExercisePickerDialogPhotoAttachForwardingTest.kt @@ -0,0 +1,148 @@ +package com.devil.phoenixproject.presentation.components + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsEnabled +import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.window.DialogProperties +import com.devil.phoenixproject.data.media.AndroidExerciseMediaStore +import com.devil.phoenixproject.data.media.ExerciseMediaStore +import com.devil.phoenixproject.domain.model.Exercise +import com.devil.phoenixproject.testutil.FakeExerciseRepository +import java.io.File +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.koin.core.context.startKoin +import org.koin.core.context.stopKoin +import org.koin.dsl.module +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +/** + * Issue #1358 test hygiene (N1): REAL behavioral coverage of the round-4 P1 + * forwarding in [ExercisePickerDialog] — the create dialog's photo-attach gate + * must follow `enablePhotoAttach` (the USER's Exercise Demos preference), never + * the host's list-thumbnail flag `enableVideoPlayback`. + * + * These tests render the actual [ExercisePickerDialog], tap "Create Custom + * Exercise" (the real user gesture) and assert the gate state inside the real + * [CreateExerciseDialog]. They FAIL when the call site is mutated back to the + * P1 defect shape `enablePhotoAttach = enableVideoPlayback` (discrimination + * proven by the mutation run recorded in the PR), which the component-level + * [ExerciseMediaAttachGateTest] cannot catch. + * + * Harness notes (issue #1358 N1, "do not change production behavior"): + * - [CreateExerciseDialog] hosts its body in a default `Dialog` + * (`usePlatformDefaultWidth = true`), which under Robolectric combined with + * any TextField never reaches Compose idle (AppNotIdleException after 60s — + * the same field settles alone, in a scroll column, or in a + * `usePlatformDefaultWidth = false` Dialog). The test-only + * `createDialogProperties`/`dialogProperties` seams (both default to + * production `DialogProperties()`) let these tests opt into the settling + * variant. No production call site passes them; production rendering is + * byte-identical. + * - `fullScreen = true` keeps the picker shell in its own + * `usePlatformDefaultWidth = false` Dialog (the harness-settling shape). The + * forwarding line under test is shell-independent — it runs before the + * fullScreen/bottom-sheet branch. + * - [ExercisePickerDialog] resolves its `ExerciseMediaStore` from Koin, so the + * tests start a minimal Koin graph over a temp-dir store. + */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], qualifiers = "w1280dp-h900dp") +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class ExercisePickerDialogPhotoAttachForwardingTest { + + @get:Rule + val rule = createComposeRule() + + private lateinit var mediaRoot: File + private lateinit var repository: FakeExerciseRepository + + @Before + fun setUp() { + mediaRoot = File.createTempFile("picker-forwarding-test", "").let { f -> + f.delete() + f.mkdirs() + f + } + repository = FakeExerciseRepository().apply { + addExercise(Exercise(id = "bench", name = "Bench Press", muscleGroup = "Glutes")) + } + startKoin { + modules( + module { + single { + AndroidExerciseMediaStore( + mediaRoot = File(mediaRoot, "media"), + openPickedStream = { handle -> + File(handle).takeIf { it.isFile }?.inputStream() + }, + ) + } + }, + ) + } + } + + @After + fun tearDown() { + stopKoin() + mediaRoot.deleteRecursively() + } + + /** + * Mounts the real [ExercisePickerDialog] with the two flags decoupled and + * opens the create dialog through the real "Create Custom Exercise" tap. + */ + private fun openCreateDialog(enableVideoPlayback: Boolean, enablePhotoAttach: Boolean) { + rule.setContent { + ExercisePickerDialog( + showDialog = true, + onDismiss = {}, + onExerciseSelected = {}, + exerciseRepository = repository, + enableVideoPlayback = enableVideoPlayback, + enablePhotoAttach = enablePhotoAttach, + // Harness-only seam (see class doc): production default kept. + createDialogProperties = DialogProperties(usePlatformDefaultWidth = false), + fullScreen = true, + ) + } + rule.waitForIdle() + rule.onNodeWithText("Create Custom Exercise").performClick() + rule.waitForIdle() + rule.onNodeWithText("Create Exercise").assertIsDisplayed() + } + + private fun addPhotosButton() = rule.onNodeWithText("Add photos") + + private fun preferenceOffNotice() = + rule.onNodeWithText("Exercise Demos is off. Enable it in Settings to add or view photos.") + + @Test + fun preferenceOn_thumbnailsSuppressed_addPhotosStillEnabled_noNotice() { + // The exact pre-fix host combination: list thumbnails hard-suppressed + // (enableVideoPlayback = false) while the user's preference is ON. The + // P1 defect routed the thumbnail flag into the gate and disabled Add. + openCreateDialog(enableVideoPlayback = false, enablePhotoAttach = true) + addPhotosButton().assertIsEnabled() + preferenceOffNotice().assertDoesNotExist() + } + + @Test + fun preferenceOff_thumbnailsShown_addPhotosDisabled_noticeShown() { + // Mirror direction: thumbnails shown but the user's preference is OFF + // (SD10 preserved at this entry point). The same mutation would wrongly + // re-enable Add here. + openCreateDialog(enableVideoPlayback = true, enablePhotoAttach = false) + addPhotosButton().assertIsNotEnabled() + preferenceOffNotice().assertIsDisplayed() + } +} diff --git a/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExercisePickerHostPhotoAttachTest.kt b/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExercisePickerHostPhotoAttachTest.kt deleted file mode 100644 index c6fe9c414..000000000 --- a/shared/src/androidHostTest/kotlin/com/devil/phoenixproject/presentation/components/ExercisePickerHostPhotoAttachTest.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.devil.phoenixproject.presentation.components - -import androidx.compose.ui.test.assertIsDisplayed -import androidx.compose.ui.test.assertIsEnabled -import androidx.compose.ui.test.assertIsNotEnabled -import androidx.compose.ui.test.junit4.createComposeRule -import androidx.compose.ui.test.onNodeWithText -import com.devil.phoenixproject.data.media.AndroidExerciseMediaStore -import com.devil.phoenixproject.testutil.FakeExerciseRepository -import java.io.File -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config -import org.robolectric.annotation.GraphicsMode - -/** - * Issue #1358 round-4 P1 behavioral tests (NOT source-string checks) for the - * photo-attach gate: `Add photos` must follow the USER's Exercise Demos - * preference at the picker hosts, never the host's demo-image display flag. - * - * P1 defect being guarded: `ExercisePickerDialog` used to pass - * `enablePhotoAttach = enableVideoPlayback` into `CreateExerciseDialog`, and the - * only two production hosts that can open the custom-exercise dialog - * (RoutineEditorScreen and WorkoutTab) hard-code `enableVideoPlayback = false` - * to suppress picker list thumbnails. Result: `Add photos` was ALWAYS disabled - * at the ExercisePicker entry point and the false "Exercise Demos is off" notice - * showed even though the preference defaults ON (AC1 unmet). SD10 (preference - * OFF -> Add disabled + notice) is preserved. - * - * Coverage layers (why this mounts the gate component): - * - These tests render [ExerciseMediaAttachments], the component that OWNS the - * observable gate behavior (Add enabled/disabled + the SD10 notice), driven - * with the exact `enableAttach` values the two picker hosts feed from the - * preference after the fix (ON -> true at both hosts, OFF -> false). - * - Host wiring (RoutineEditorScreen/WorkoutTab feed `enablePhotoAttach` from - * the preference; ExercisePickerDialog forwards its own parameter) is held - * by the drift guard `ExerciseMediaWiringTest - * .photoAttachGateIsDecoupledFromListThumbnailFlagAtBothHosts`. - * - End-to-end proof at the REAL hosts (including the production - * ModalBottomSheet + CreateExerciseDialog path) is the R4 routine-entry - * acceptance on iOS and Android: a distinct-photo ADDITION at the routine - * host with the preference ON now succeeds. - * - Rendering CreateExerciseDialog itself under Robolectric is not viable in - * this harness: its `Dialog` (default usePlatformDefaultWidth=true) with any - * TextField never reaches Compose idle (AppNotIdleException after 60s — - * isolated by probes: Dialog+TextField loops; the same field alone, in a - * scroll column, or in a usePlatformDefaultWidth=false Dialog all settle). - * That is a Robolectric/harness quirk, not product behavior — the dialog is - * exercised on both real platforms by the R4 acceptance runs. - */ -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [34], qualifiers = "w1280dp-h900dp") -@GraphicsMode(GraphicsMode.Mode.NATIVE) -class ExercisePickerHostPhotoAttachTest { - - @get:Rule - val rule = createComposeRule() - - private lateinit var mediaRoot: File - private lateinit var repository: FakeExerciseRepository - - @Before - fun setUp() { - mediaRoot = File.createTempFile("picker-photo-attach-test", "").let { f -> - f.delete() - f.mkdirs() - f - } - repository = FakeExerciseRepository() - } - - @After - fun tearDown() { - mediaRoot.deleteRecursively() - } - - private fun attachStore() = AndroidExerciseMediaStore( - mediaRoot = File(mediaRoot, "media"), - openPickedStream = { handle -> File(handle).takeIf { it.isFile }?.inputStream() }, - ) - - /** The gate section exactly as the create/edit dialog hosts it (SD2/SD10). */ - private fun mountAttachGate(enableAttach: Boolean) { - rule.setContent { - ExerciseMediaAttachments( - coordinator = ExerciseMediaSaveCoordinator(attachStore()), - savedImages = emptyList(), - enableAttach = enableAttach, - onRequestPick = {}, - ) - } - rule.waitForIdle() - } - - private fun addPhotosButton() = rule.onNodeWithText("Add photos") - - private fun preferenceOffNotice() = - rule.onNodeWithText("Exercise Demos is off. Enable it in Settings to add or view photos.") - - // ---- preference ON (what RoutineEditorScreen and WorkoutTab now feed - // at the routine-editor and workout-add picker hosts) ---- - - @Test - fun routineEditorHost_preferenceOn_addPhotosEnabled_noNotice() { - mountAttachGate(enableAttach = true) - addPhotosButton().assertIsEnabled() - preferenceOffNotice().assertDoesNotExist() - } - - @Test - fun workoutAddHost_preferenceOn_addPhotosEnabled_noNotice() { - mountAttachGate(enableAttach = true) - addPhotosButton().assertIsEnabled() - preferenceOffNotice().assertDoesNotExist() - } - - // ---- preference OFF: SD10 preserved at both hosts ---- - - @Test - fun routineEditorHost_preferenceOff_addPhotosDisabled_noticeShown() { - mountAttachGate(enableAttach = false) - addPhotosButton().assertIsNotEnabled() - preferenceOffNotice().assertIsDisplayed() - } - - @Test - fun workoutAddHost_preferenceOff_addPhotosDisabled_noticeShown() { - mountAttachGate(enableAttach = false) - addPhotosButton().assertIsNotEnabled() - preferenceOffNotice().assertIsDisplayed() - } - - // ---- the P1 regression shape, named explicitly ---- - - @Test - fun listThumbnailSuppression_alone_neverDisablesAttach() { - // The exact pre-fix combination both hosts produced routed a hard-coded - // `false` into this gate (demo-image display flag OFF). With the - // preference ON the gate must render Add ENABLED — before the P1 fix the - // hosts reached this component with enableAttach=false and showed the - // false notice. The host-side routing is held by the drift guard and - // proven end-to-end by the R4 routine-host ADDITION acceptance runs. - mountAttachGate(enableAttach = true) - addPhotosButton().assertIsEnabled() - preferenceOffNotice().assertDoesNotExist() - } -} diff --git a/shared/src/commonTest/kotlin/com/devil/phoenixproject/presentation/ExerciseMediaWiringTest.kt b/shared/src/commonTest/kotlin/com/devil/phoenixproject/presentation/ExerciseMediaWiringTest.kt index ef9c87a3a..3cff68c89 100644 --- a/shared/src/commonTest/kotlin/com/devil/phoenixproject/presentation/ExerciseMediaWiringTest.kt +++ b/shared/src/commonTest/kotlin/com/devil/phoenixproject/presentation/ExerciseMediaWiringTest.kt @@ -339,7 +339,8 @@ class ExerciseMediaWiringTest { /** * Round-4 P1 drift guard (SUPPLEMENT to the behavioral tests in - * `ExercisePickerHostPhotoAttachTest`, which render the real dialog): + * `ExercisePickerDialogPhotoAttachForwardingTest`, which render the real + * dialog and fail under the P1 mutation): * the attach gate must be its own parameter fed by the user's Exercise Demos * preference at BOTH picker hosts that can open the custom-exercise dialog, * never re-coupled to the host's list-thumbnail flag. @@ -370,7 +371,7 @@ class ExerciseMediaWiringTest { val hostSrc = stripKotlinComments(host!!) assertTrue( hostSrc.contains("enablePhotoAttach = enableVideoPlayback,"), - "$name must feed the ExercisePickerHostPhotoAttachTest-gated enablePhotoAttach from the " + + "$name must feed enablePhotoAttach from the " + "user's Exercise Demos preference (round-4 P1).", ) } diff --git a/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/CreateExerciseDialog.kt b/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/CreateExerciseDialog.kt index 6b79fe542..f18a9f558 100644 --- a/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/CreateExerciseDialog.kt +++ b/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/CreateExerciseDialog.kt @@ -21,6 +21,7 @@ import androidx.compose.ui.semantics.role import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties import com.devil.phoenixproject.data.media.ExerciseMediaDelta import com.devil.phoenixproject.data.repository.ExerciseImageEntity import com.devil.phoenixproject.data.repository.ExerciseRepository @@ -52,6 +53,13 @@ fun CreateExerciseDialog( mediaCoordinator: ExerciseMediaSaveCoordinator? = null, savedImages: List = emptyList(), enablePhotoAttach: Boolean = true, + /** + * Test seam (issue #1358 N1): window properties for the host [Dialog]. The + * default is production-identical; the Robolectric harness passes + * `usePlatformDefaultWidth = false` to dodge the Dialog+TextField + * AppNotIdleException quirk. Never pass anything else from production. + */ + dialogProperties: DialogProperties = DialogProperties(), onSave: (Exercise, ExerciseMediaDelta) -> Unit, onDelete: (() -> Unit)? = null, onViewHistory: (() -> Unit)? = null, @@ -123,7 +131,7 @@ fun CreateExerciseDialog( val isEditMode = existingExercise != null - Dialog(onDismissRequest = onDismiss) { + Dialog(onDismissRequest = onDismiss, properties = dialogProperties) { Surface( modifier = Modifier.fillMaxWidth().wrapContentHeight(), shape = MaterialTheme.shapes.medium, diff --git a/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/ExercisePicker.kt b/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/ExercisePicker.kt index 0670be041..3fca2222a 100644 --- a/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/ExercisePicker.kt +++ b/shared/src/phoneMain/kotlin/com/devil/phoenixproject/presentation/components/ExercisePicker.kt @@ -114,6 +114,12 @@ fun ExercisePickerDialog( enablePreviouslyCompletedFilter: Boolean = false, completedExerciseIds: Set = emptySet(), completedExerciseIdsLoading: Boolean = false, + /** + * Test seam (issue #1358 N1): forwarded to [CreateExerciseDialog]'s host + * [Dialog]. Defaults to production `DialogProperties()`; only the + * Robolectric harness overrides it. No production call site passes this. + */ + createDialogProperties: DialogProperties = DialogProperties(), ) { if (!showDialog) return @@ -220,6 +226,7 @@ fun ExercisePickerDialog( exerciseRepository = exerciseRepository, mediaCoordinator = mediaCoordinator, savedImages = mediaSavedImages, + dialogProperties = createDialogProperties, // Issue #1358 round-4 P1: the attach gate follows the user's Exercise // Demos preference (enablePhotoAttach), never the host's list-thumbnail // flag (enableVideoPlayback) — those are decoupled.