UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

145 lines (120 loc) 3.41 kB
import { getArtworkImage } from ".."; import { DEFAULT_IMAGE } from "../assets"; describe("getArtworkImage", () => { const entryWithImage = { media_group: [ { type: "image", media_item: [ { key: "artwork_key", src: "image_from_entry" }, { key: "other_key", src: "other_image" }, ], }, ], extensions: { artwork_key: "artwork_key", }, }; const entryWithoutImage = { media_group: [ { type: "image", media_item: [{ key: "other_key", src: "other_image" }], }, ], extensions: { artwork_key: "artwork_key", }, }; const pluginConfigWithImage = { artwork_key: "plugin_artwork_key", }; it("returns image from entry extensions key", () => { const result = getArtworkImage({ key: "artwork_key", entry: entryWithImage, plugin_configuration: {}, }); expect(result).toBe("image_from_entry"); }); it("returns image from plugin configuration key if not in entry", () => { const entryNoMatch = { ...entryWithoutImage, extensions: { artwork_key: "not_found_key" }, }; const pluginConfig = { artwork_key: "plugin_artwork_key", }; const entryWithPluginImage = { ...entryNoMatch, media_group: [ { type: "image", media_item: [{ key: "plugin_artwork_key", src: "image_from_plugin" }], }, ], }; const result = getArtworkImage({ key: "artwork_key", entry: entryWithPluginImage, plugin_configuration: pluginConfig, }); expect(result).toBe("image_from_plugin"); }); it("returns DEFAULT_IMAGE if neither entry nor plugin configuration has image", () => { const entryNoImage = { media_group: [ { type: "image", media_item: [{ key: "other_key", src: "other_image" }], }, ], extensions: { artwork_key: "not_found_key" }, }; const pluginConfig = { artwork_key: "not_found_key" }; const result = getArtworkImage({ key: "artwork_key", entry: entryNoImage, plugin_configuration: pluginConfig, }); expect(result).toBe(DEFAULT_IMAGE); }); it("handles undefined key gracefully", () => { const result = getArtworkImage({ key: undefined, entry: entryWithImage, plugin_configuration: pluginConfigWithImage, }); expect(result).toBe(DEFAULT_IMAGE); }); it("handles missing entry or plugin_configuration gracefully", () => { const result = getArtworkImage({ key: "artwork_key", entry: undefined, plugin_configuration: undefined, }); expect(result).toBe(DEFAULT_IMAGE); }); it("handles empty media_group", () => { const entryEmptyMedia = { media_group: [], extensions: { artwork_key: "artwork_key" }, }; const result = getArtworkImage({ key: "artwork_key", entry: entryEmptyMedia, plugin_configuration: pluginConfigWithImage, }); expect(result).toBe(DEFAULT_IMAGE); }); it("handles missing extensions/config keys", () => { const entryNoExt = { media_group: [], extensions: {} }; const pluginConfig = {}; const result = getArtworkImage({ key: "artwork_key", entry: entryNoExt, plugin_configuration: pluginConfig, }); expect(result).toBe(DEFAULT_IMAGE); }); });