Cotton code
46 lines · 2.1 KB · KotlinRaw
package com.cottondb.photosimport com.cottondb.photos.viewer.ViewerSetimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.JsonObjectimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalseimport org.junit.Assert.assertNullimport org.junit.Assert.assertTrueimport 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"))    }}