|
| 1 | +package dev.dimension.flare.data.datasource.pixiv |
| 2 | + |
| 3 | +import dev.dimension.flare.data.network.pixiv.model.PixivIllust |
| 4 | +import dev.dimension.flare.data.network.pixiv.model.PixivImageUrls |
| 5 | +import dev.dimension.flare.data.network.pixiv.model.PixivMetaPage |
| 6 | +import dev.dimension.flare.data.network.pixiv.model.PixivMetaSinglePage |
| 7 | +import dev.dimension.flare.data.network.pixiv.model.PixivUser |
| 8 | +import dev.dimension.flare.ui.model.UiMedia |
| 9 | +import kotlin.test.Test |
| 10 | +import kotlin.test.assertEquals |
| 11 | +import kotlin.test.assertIs |
| 12 | + |
| 13 | +class PixivMapperTest { |
| 14 | + @Test |
| 15 | + fun singlePageIllustUsesMetaSinglePageOriginalImageUrl() { |
| 16 | + val post = |
| 17 | + pixivIllust( |
| 18 | + imageUrls = |
| 19 | + PixivImageUrls( |
| 20 | + squareMedium = "https://example.com/square.jpg", |
| 21 | + medium = "https://example.com/medium.jpg", |
| 22 | + large = "https://example.com/large.jpg", |
| 23 | + ), |
| 24 | + metaSinglePage = |
| 25 | + PixivMetaSinglePage( |
| 26 | + originalImageUrl = "https://example.com/original.png", |
| 27 | + ), |
| 28 | + ).toUiMedia() |
| 29 | + |
| 30 | + val image = assertIs<UiMedia.Image>(post.single()) |
| 31 | + assertEquals("https://example.com/original.png", image.url) |
| 32 | + assertEquals("https://example.com/medium.jpg", image.previewUrl) |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun multiPageIllustUsesPageImageUrls() { |
| 37 | + val post = |
| 38 | + pixivIllust( |
| 39 | + imageUrls = |
| 40 | + PixivImageUrls( |
| 41 | + medium = "https://example.com/cover-medium.jpg", |
| 42 | + large = "https://example.com/cover-large.jpg", |
| 43 | + ), |
| 44 | + metaSinglePage = |
| 45 | + PixivMetaSinglePage( |
| 46 | + originalImageUrl = "https://example.com/cover-original.png", |
| 47 | + ), |
| 48 | + metaPages = |
| 49 | + listOf( |
| 50 | + PixivMetaPage( |
| 51 | + imageUrls = |
| 52 | + PixivImageUrls( |
| 53 | + medium = "https://example.com/page-0-medium.jpg", |
| 54 | + large = "https://example.com/page-0-large.jpg", |
| 55 | + original = "https://example.com/page-0-original.png", |
| 56 | + ), |
| 57 | + ), |
| 58 | + ), |
| 59 | + ).toUiMedia() |
| 60 | + |
| 61 | + val image = assertIs<UiMedia.Image>(post.single()) |
| 62 | + assertEquals("https://example.com/page-0-original.png", image.url) |
| 63 | + assertEquals("https://example.com/page-0-medium.jpg", image.previewUrl) |
| 64 | + } |
| 65 | + |
| 66 | + private fun pixivIllust( |
| 67 | + imageUrls: PixivImageUrls, |
| 68 | + metaSinglePage: PixivMetaSinglePage? = null, |
| 69 | + metaPages: List<PixivMetaPage> = emptyList(), |
| 70 | + ): PixivIllust = |
| 71 | + PixivIllust( |
| 72 | + id = 146347478, |
| 73 | + title = "As if in a dream", |
| 74 | + type = "illust", |
| 75 | + imageUrls = imageUrls, |
| 76 | + user = |
| 77 | + PixivUser( |
| 78 | + id = 21714218, |
| 79 | + name = "Hyde", |
| 80 | + account = "hidetohyde", |
| 81 | + ), |
| 82 | + createDate = "2026-06-22T22:09:00+00:00", |
| 83 | + width = 4000, |
| 84 | + height = 3000, |
| 85 | + metaSinglePage = metaSinglePage, |
| 86 | + metaPages = metaPages, |
| 87 | + ) |
| 88 | +} |
0 commit comments