Skip to content

Commit

Permalink
Update setup media picker helper to handle single and multiple items
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed May 5, 2023
1 parent 8379426 commit 92ef384
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions test/native/integration-test-helpers/setup-media-picker.js
Original file line number Diff line number Diff line change
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
);
} ),
};
};

0 comments on commit 92ef384

Please sign in to comment.