package com.tt.honeyDue.testing

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.fail

/**
 * Sanity checks on the canonical parity-gallery manifest.
 *
 * These run on every platform's test target because the manifest lives in
 * [commonMain]; they guard against obvious mistakes (duplicate names,
 * empty-platform screens) before the platform-specific parity tests run.
 */
class GalleryManifestTest {

    @Test
    fun manifest_has_no_duplicate_names() {
        val duplicates = GalleryScreens.all
            .groupingBy { it.name }
            .eachCount()
            .filterValues { it > 1 }
        assertTrue(
            duplicates.isEmpty(),
            "Duplicate canonical screen names in manifest: $duplicates",
        )
    }

    @Test
    fun every_screen_has_at_least_one_platform() {
        val orphans = GalleryScreens.all.filter { it.platforms.isEmpty() }
        assertTrue(
            orphans.isEmpty(),
            "Screens with no platforms — they'd never be captured: ${orphans.map { it.name }}",
        )
    }

    @Test
    fun snake_case_names_only() {
        val malformed = GalleryScreens.all.filter { !it.name.matches(Regex("^[a-z][a-z0-9_]*$")) }
        assertTrue(
            malformed.isEmpty(),
            "Non-snake_case screen names: ${malformed.map { it.name }}",
        )
    }

    @Test
    fun expected_counts_match_plan() {
        // Canaries: if someone adds/removes a screen without updating the
        // docs/parity-gallery.md summary, this test fails loudly. Bump
        // both in the same PR.
        assertEquals(43, GalleryScreens.all.size, "Total canonical screen count")
        assertEquals(
            12,
            GalleryScreens.all.count { it.category == GalleryCategory.DataCarrying },
            "Data-carrying screen count",
        )
        assertEquals(
            31,
            GalleryScreens.all.count { it.category == GalleryCategory.DataFree },
            "Data-free screen count",
        )
    }

    @Test
    fun android_subset_matches_count() {
        assertEquals(40, GalleryScreens.forAndroid.size, "Android-reachable screen count")
    }

    @Test
    fun ios_subset_matches_count() {
        assertEquals(40, GalleryScreens.forIos.size, "iOS-reachable screen count")
    }
}
