fix(media-library-cloudinary): when 'multiple' is true, always return an array (#2656)

This commit is contained in:
Zachary Sierakowski 2019-09-09 16:18:34 -04:00 committed by Shawn Erquhart
parent 49e142ef59
commit 4c32ee4aed
2 changed files with 12 additions and 1 deletions

View File

@ -147,6 +147,17 @@ Object {
expect(handleInsert).toHaveBeenCalledWith(expect.any(Array));
});
it('calls insert function with array when only one asset is returned and config.multiple is true', async () => {
const options = {
config: {
multiple: true,
},
};
await cloudinary.init({ options, handleInsert });
cloudinaryInsertHandler({ assets: [asset] });
expect(handleInsert).toHaveBeenCalledWith(expect.any(Array));
});
it('calls insert function with secure url', async () => {
await cloudinary.init({ handleInsert });
cloudinaryInsertHandler({ assets: [asset] });

View File

@ -60,7 +60,7 @@ async function init({ options = {}, handleInsert } = {}) {
const insertHandler = data => {
const assets = data.assets.map(asset => getAssetUrl(asset, resolvedOptions));
handleInsert(assets.length > 1 ? assets : assets[0]);
handleInsert(providedConfig.multiple || assets.length > 1 ? assets : assets[0]);
};
const mediaLibrary = window.cloudinary.createMediaLibrary(cloudinaryConfig, { insertHandler });