package com.cottondb.photos import com.cottondb.photos.viewer.ViewerSet import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test /** The viewer's set read off `shell.deck`'s answer (the shape cotton-ffi's photos_tests pins); every key synthetic. */ class ViewerSetTest { private fun json(text: String): JsonObject = Json.parseToJsonElement(text).jsonObject private val deck = json( """{"table":"media","viewer":{"close":"Close","position":"{n} of {count}","share":"Share"}, "cards":[ {"id":"photo:a","slots":{"photo":"w/photos/a.jpg"},"acts":["share","favourite","group","delete"],"record":{"data":{"kind":"photo"}}}, {"id":"note:x","slots":{}}, {"id":"video:b","slots":{"photo":"w/videos/b.mp4"},"acts":["favourite"],"record":{"data":{"kind":"video"}}} ]}""", ) /** A tap on a print opens on it among the deck's pictures alone, and says its place in the viewer's words. */ @Test fun the_set_is_the_decks_pictures_opening_on_the_tapped_one() { val set = ViewerSet.of(deck, "video:b")!! assertEquals(listOf("photo:a", "video:b"), set.cards.map { it["id"].toString().trim('"') }) assertEquals(1, set.start) assertEquals("2 of 2", set.position(1)) assertTrue(ViewerSet.isVideo(set.cards[1])) assertFalse(ViewerSet.isVideo(set.cards[0])) } /** Share shows where the card offers it; a card with no picture, or a deck with no viewer words, opens nothing. */ @Test fun share_is_the_cards_and_nothing_opens_without_a_picture_or_words() { val set = ViewerSet.of(deck, "photo:a")!! assertTrue(ViewerSet.offers(set.cards[0], "share")) assertFalse(ViewerSet.offers(set.cards[1], "share")) assertNull(ViewerSet.of(deck, "note:x")) assertNull(ViewerSet.of(json("""{"cards":[{"id":"photo:a","slots":{"photo":"k"}}]}"""), "photo:a")) } }