Skip to content

Commit

Permalink
[RNMobile] Update setup media picker helper (#50398)
Browse files Browse the repository at this point in the history
* Update setup media picker helper to handle single and multiple items

* Include `metadata` param when notifying succeed state in `setupMediaUpload` helper

* [RNMobile] Add `testID` prop to SandBox component (#50399)
  • Loading branch information
fluiddot committed May 10, 2023
1 parent 2188ed6 commit e01f41f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/components/src/sandbox/index.native.js
Expand Up @@ -187,6 +187,7 @@ const Sandbox = forwardRef( function Sandbox(
onWindowEvents = {},
viewportProps = '',
onLoadEnd = () => {},
testID,
},
ref
) {
Expand Down Expand Up @@ -374,6 +375,7 @@ const Sandbox = forwardRef( function Sandbox(
showsVerticalScrollIndicator={ false }
mediaPlaybackRequiresUserAction={ false }
onLoadEnd={ onLoadEnd }
testID={ testID }
/>
);
} );
Expand Down
31 changes: 21 additions & 10 deletions test/native/integration-test-helpers/setup-media-picker.js
Expand Up @@ -20,9 +20,11 @@ import { requestMediaPicker } from '@wordpress/react-native-bridge';
*/
export const setupMediaPicker = () => {
let mediaPickerCallback;
let multipleItems;
requestMediaPicker.mockImplementation(
( source, filter, multiple, callback ) => {
mediaPickerCallback = callback;
multipleItems = multiple;
}
);
return {
Expand All @@ -34,16 +36,25 @@ export const setupMediaPicker = () => {
mediaPickerCallback
),
mediaPickerCallback: async ( ...mediaItems ) =>
act( async () =>
act( async () => {
const items = mediaItems.map(
( {
localId,
localUrl,
type = 'image',
url,
id,
metadata,
} ) => ( {
type,
url: url ?? localUrl,
id: id ?? localId,
metadata,
} )
);
mediaPickerCallback(
mediaItems.map(
( { localId, localUrl, type = 'image' } ) => ( {
type,
url: localUrl,
id: localId,
} )
)
)
),
items.length === 1 && ! multipleItems ? items[ 0 ] : items
);
} ),
};
};
1 change: 1 addition & 0 deletions test/native/integration-test-helpers/setup-media-upload.js
Expand Up @@ -50,6 +50,7 @@ export const setupMediaUpload = () => {
mediaId: mediaItem.localId,
mediaUrl: mediaItem.serverUrl,
mediaServerId: mediaItem.serverId,
metadata: mediaItem.metadata,
} );
} ),
notifyFailedState: async ( mediaItem ) =>
Expand Down

1 comment on commit e01f41f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e01f41f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4937685796
📝 Reported issues:

Please sign in to comment.