diff --git a/compose/designsystem/build.gradle.kts b/compose/designsystem/build.gradle.kts index d84479e731..b4389d2150 100644 --- a/compose/designsystem/build.gradle.kts +++ b/compose/designsystem/build.gradle.kts @@ -114,3 +114,36 @@ tasks.named("desktopTest") { exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL } } + +// vcase pilot (vcase repo, docs/pilot-raft-mobile.md; Raft #proj-mobile:#211). desktopTest also +// compiles src/desktopVcase (the @VCase cases, RaftVCaseHost, DesignSystemVCases and the +// LegacyGoldenParityTest migration gate) against build.raft.vcase from maven.artifacts.botiverse.dev. +// Goldens live next to the Roborazzi ones, at screenshots/vcase/desktop-skiko/, with the manifest +// at screenshots/vcase/vcase.manifest.json, so the record_screenshots dispatch collects them too. +// - desktopTest / verifyRoborazziDesktop: verify, zero tolerance (inputs: screenshotGoldens covers screenshots/vcase). +// - recordRoborazziDesktop: record (vcase.mode=record) alongside Roborazzi. +// - -Pvcase.mode=record|verify|scan and -Pvcase.filter= override; -Pvcase.version picks +// another release (or 0.1.0-SNAPSHOT from mavenLocal). +val vcaseVersion = providers.gradleProperty("vcase.version").getOrElse("0.1.0") +val vcaseDir = screenshotGoldenDir.dir("vcase") +val vcaseRecording = gradle.startParameter.taskNames.any { it.substringAfterLast(':') == "recordRoborazziDesktop" } +kotlin { + sourceSets.named("desktopTest") { + kotlin.srcDir("src/desktopVcase/kotlin") + dependencies { + implementation("build.raft.vcase:vcase-compose-desktop:$vcaseVersion") + } + } +} +tasks.named("desktopTest") { + val mode = providers.gradleProperty("vcase.mode").orNull ?: "record".takeIf { vcaseRecording } + if (mode != null) { + systemProperty("vcase.mode", mode) + outputs.upToDateWhen { false } + } + providers.gradleProperty("vcase.filter").orNull?.let { systemProperty("vcase.filter", it) } + systemProperty("vcase.goldens", vcaseDir.asFile.absolutePath) + systemProperty("vcase.manifest", vcaseDir.file("vcase.manifest.json").asFile.absolutePath) + systemProperty("vcase.out", screenshotReportDir.get().dir("vcase").asFile.absolutePath) + systemProperty("vcase.sourceRoot", "compose/designsystem/src/desktopVcase/kotlin") +} diff --git a/compose/designsystem/screenshots/vcase/desktop-skiko/ds.composer-drop-overlay.default@dark,compact.png b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.composer-drop-overlay.default@dark,compact.png new file mode 100644 index 0000000000..407c8a8e5a Binary files /dev/null and b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.composer-drop-overlay.default@dark,compact.png differ diff --git a/compose/designsystem/screenshots/vcase/desktop-skiko/ds.composer-drop-overlay.default@light,compact.png b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.composer-drop-overlay.default@light,compact.png new file mode 100644 index 0000000000..1698ab3528 Binary files /dev/null and b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.composer-drop-overlay.default@light,compact.png differ diff --git a/compose/designsystem/screenshots/vcase/desktop-skiko/ds.empty-state.gallery@dark,compact.png b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.empty-state.gallery@dark,compact.png new file mode 100644 index 0000000000..048636b92b Binary files /dev/null and b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.empty-state.gallery@dark,compact.png differ diff --git a/compose/designsystem/screenshots/vcase/desktop-skiko/ds.empty-state.gallery@light,compact.png b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.empty-state.gallery@light,compact.png new file mode 100644 index 0000000000..929e1eda4b Binary files /dev/null and b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.empty-state.gallery@light,compact.png differ diff --git a/compose/designsystem/screenshots/vcase/desktop-skiko/ds.save-status.gallery@dark,compact.png b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.save-status.gallery@dark,compact.png new file mode 100644 index 0000000000..87e045f058 Binary files /dev/null and b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.save-status.gallery@dark,compact.png differ diff --git a/compose/designsystem/screenshots/vcase/desktop-skiko/ds.save-status.gallery@light,compact.png b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.save-status.gallery@light,compact.png new file mode 100644 index 0000000000..31f1eeb9a2 Binary files /dev/null and b/compose/designsystem/screenshots/vcase/desktop-skiko/ds.save-status.gallery@light,compact.png differ diff --git a/compose/designsystem/screenshots/vcase/vcase.manifest.json b/compose/designsystem/screenshots/vcase/vcase.manifest.json new file mode 100644 index 0000000000..3356981e67 --- /dev/null +++ b/compose/designsystem/screenshots/vcase/vcase.manifest.json @@ -0,0 +1,53 @@ +{ + "schema": "vcase/1", + "project": "raft-designsystem", + "defaults": { + "theme": [ + "light", + "dark" + ], + "viewport": [ + { + "name": "compact", + "w": 1200, + "h": 2400, + "density": 2.0 + } + ], + "locale": [ + "en" + ], + "pointer": [ + "touch" + ] + }, + "cases": [ + { + "id": "ds.composer-drop-overlay.default", + "kind": "component", + "source": "compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/ComposerDropOverlayCases.kt:24", + "fixture": null, + "axes": {}, + "parity": [], + "divergences": [] + }, + { + "id": "ds.empty-state.gallery", + "kind": "component", + "source": "compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/EmptyStateCases.kt:23", + "fixture": null, + "axes": {}, + "parity": [], + "divergences": [] + }, + { + "id": "ds.save-status.gallery", + "kind": "component", + "source": "compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/SaveStatusCases.kt:25", + "fixture": null, + "axes": {}, + "parity": [], + "divergences": [] + } + ] +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/ComposerDropOverlayCases.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/ComposerDropOverlayCases.kt new file mode 100644 index 0000000000..ba6127fe41 --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/ComposerDropOverlayCases.kt @@ -0,0 +1,31 @@ +package build.raft.designsystem.vcase + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import build.raft.designsystem.components.RaftComposerDropOverlay +import build.raft.designsystem.text.RaftText +import build.raft.designsystem.theme.RaftTheme +import dev.vcase.VCase + +/** + * raft-ui Composer > `ComposerDropOverlay` (web MessageInput while files are dragged over it), + * over a composer-sized box with text under it, which the overlay must hide. + * Replaces ComposerDropOverlayScreenshotTest (composer_drop_overlay_light/_dark). + */ +@VCase("ds.composer-drop-overlay.default") +@Composable +fun ComposerDropOverlayCase() { + Box(Modifier.width(360.dp).height(104.dp).background(RaftTheme.colors.layerCanvas)) { + Column(Modifier.padding(12.dp)) { + RaftText("Message #launch-week", color = RaftTheme.colors.foregroundHint) + } + RaftComposerDropOverlay(label = "Drop files to attach", modifier = Modifier.matchParentSize()) + } +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/DesignSystemVCases.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/DesignSystemVCases.kt new file mode 100644 index 0000000000..680ff1da14 --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/DesignSystemVCases.kt @@ -0,0 +1,14 @@ +package build.raft.designsystem.vcase + +import dev.vcase.compose.desktop.VCaseDesktopTest + +/** + * Every @VCase in build.raft.designsystem.vcase, rendered with [RaftVCaseHost] and checked + * against screenshots/vcase/desktop-skiko/ (zero tolerance) and screenshots/vcase/vcase.manifest.json. + * Verified by desktopTest; recorded by recordRoborazziDesktop or -Pvcase.mode=record (CI only). + */ +class DesignSystemVCases : VCaseDesktopTest() { + override val host = RaftVCaseHost + override val packages = listOf("build.raft.designsystem.vcase") + override val sourceRoot = "compose/designsystem/src/desktopVcase/kotlin" +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/EmptyStateCases.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/EmptyStateCases.kt new file mode 100644 index 0000000000..81a848de6a --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/EmptyStateCases.kt @@ -0,0 +1,60 @@ +package build.raft.designsystem.vcase + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import build.raft.designsystem.components.RaftButton +import build.raft.designsystem.components.RaftEmptyState +import build.raft.designsystem.components.RaftGlyph +import build.raft.designsystem.components.RaftGlyphIcon +import dev.vcase.VCase + +/** + * [RaftEmptyState] (raft-ui EmptyState): icon, title, description and an action; title and + * description; the title alone; a long description cut at three lines; and one centred in a + * taller box (`justify-center`). Replaces EmptyStateScreenshotTest (empty_state_light/_dark). + */ +@VCase("ds.empty-state.gallery") +@Composable +fun EmptyStateGallery() { + Column(Modifier.width(358.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { + Caption("Icon, title, description, action") + CanvasSurface { + RaftEmptyState( + title = "No saved messages", + description = "Save a message to find it here later.", + icon = { RaftGlyphIcon(RaftGlyph.Bookmark, size = 36.dp) }, + actions = { RaftButton(text = "Browse channels", onClick = {}) }, + ) + } + Caption("Title and description") + CanvasSurface { + RaftEmptyState(title = "No results", description = "Try another word.") + } + Caption("Title only") + CanvasSurface { RaftEmptyState(title = "Nothing here yet") } + Caption("Long text: title one line, description three") + CanvasSurface { + RaftEmptyState( + title = "No agents have been added to this workspace so far", + description = + "Agents you add show up here with their status, their computer and the channels " + + "they work in. Add one from the members page, or ask an admin to add one for you.", + icon = { RaftGlyphIcon(RaftGlyph.Search, size = 36.dp) }, + ) + } + Caption("Centred in a 320dp box") + CanvasSurface { + RaftEmptyState( + title = "No tasks", + description = "Tasks you create show up here.", + modifier = Modifier.height(320.dp), + icon = { RaftGlyphIcon(RaftGlyph.CircleCheck, size = 36.dp) }, + ) + } + } +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/Gallery.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/Gallery.kt new file mode 100644 index 0000000000..a39e79c805 --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/Gallery.kt @@ -0,0 +1,25 @@ +package build.raft.designsystem.vcase + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import build.raft.designsystem.text.RaftText +import build.raft.designsystem.theme.RaftTheme + +// Gallery helpers the screenshot tests each kept privately. + +@Composable +internal fun Caption(text: String) { + RaftText(text = text, style = RaftTheme.typography.monoMeta, color = RaftTheme.colors.foregroundHint) +} + +@Composable +internal fun CanvasSurface( + padded: Boolean = false, + content: @Composable () -> Unit, +) { + Column(Modifier.background(RaftTheme.colors.layerCanvas).then(if (padded) Modifier.padding(16.dp) else Modifier)) { content() } +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/LegacyGoldenParityTest.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/LegacyGoldenParityTest.kt new file mode 100644 index 0000000000..a4b7f450b8 --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/LegacyGoldenParityTest.kt @@ -0,0 +1,39 @@ +package build.raft.designsystem.vcase + +import dev.vcase.core.ImageCompare +import java.io.File +import kotlin.test.Test +import kotlin.test.assertTrue +import org.junit.Assume.assumeTrue + +/** + * Migration gate (vcase design, phase 1): a gallery test is deleted only once its vcase + * goldens equal the legacy RaftScreenshot goldens pixel for pixel. Runs after a + * vcase record (recordRoborazziDesktop); skipped while the vcase goldens do not exist yet. + */ +class LegacyGoldenParityTest { + private val legacyDir = File(System.getProperty("raft.screenshot.goldenDir") ?: "screenshots") + private val vcaseDir = File(System.getProperty("vcase.goldens") ?: "screenshots/vcase", "desktop-skiko") + + /** vcase capture stem to the legacy golden name it replaces. */ + private val pairs = + listOf("light", "dark").flatMap { theme -> + listOf( + "ds.empty-state.gallery@$theme,compact" to "empty_state_$theme", + "ds.save-status.gallery@$theme,compact" to "save_status_$theme", + "ds.composer-drop-overlay.default@$theme,compact" to "composer_drop_overlay_$theme", + ) + } + + @Test + fun vcaseGoldensEqualLegacyGoldens() { + assumeTrue("record the vcase goldens first", pairs.all { File(vcaseDir, "${it.first}.png").isFile }) + val report = + pairs.map { (stem, legacy) -> + val r = ImageCompare.compare(File(legacyDir, "$legacy.png"), File(vcaseDir, "$stem.png")) + Triple(stem, legacy, r) + } + report.forEach { (stem, legacy, r) -> println("$legacy.png vs $stem.png: ${r.describe()}") } + assertTrue(report.all { it.third.matches }, report.filterNot { it.third.matches }.joinToString("\n") { "${it.second} -> ${it.first}: ${it.third.describe()}" }) + } +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/RaftVCaseHost.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/RaftVCaseHost.kt new file mode 100644 index 0000000000..ca88bc28af --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/RaftVCaseHost.kt @@ -0,0 +1,58 @@ +package build.raft.designsystem.vcase + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import build.raft.designsystem.theme.RaftAppearance +import build.raft.designsystem.theme.RaftPointerInput +import build.raft.designsystem.theme.RaftScale +import build.raft.designsystem.theme.RaftTheme +import dev.vcase.VCasePointer +import dev.vcase.compose.desktop.CaptureSize +import dev.vcase.compose.desktop.VCaseHost +import dev.vcase.core.ManifestDefaults +import dev.vcase.core.ManifestViewport +import dev.vcase.core.VCaseVariant + +/** + * How the design system renders a vcase case: the same frame as [build.raft.designsystem.screenshot.RaftScreenshot] + * (RaftTheme with the axis appearance, the theme canvas, 16dp of padding, sized to the content, + * at most 1200 x 2400 dp, 1dp = 2px), so a case and the gallery test it replaces should give the + * same pixels. + * + * Axes: theme light / dark -> [RaftAppearance]; pointer touch / fine -> [RaftPointerInput]. + * [RaftScale] stays pinned to Compact (the theme would otherwise pick it from the scene width). + * Locale is not applied yet: the existing goldens use the inherited one. + */ +object RaftVCaseHost : VCaseHost { + override val project = "raft-designsystem" + + override val defaults = + ManifestDefaults( + theme = listOf("light", "dark"), + // A gallery canvas, not a device: the width and height bound the wrap-content capture. + viewport = listOf(ManifestViewport("compact", 1200, 2400, 2f)), + locale = listOf("en"), + pointer = listOf("touch"), + ) + + override fun captureSize(variant: VCaseVariant): CaptureSize = CaptureSize.WrapContent(maxWidthDp = 1200, maxHeightDp = 2400) + + @Composable + override fun Wrap( + variant: VCaseVariant, + content: @Composable () -> Unit, + ) { + RaftTheme( + appearance = if (variant.axes.theme == "dark") RaftAppearance.Dark else RaftAppearance.Light, + systemDark = false, + scale = RaftScale.Compact, + pointerInput = if (variant.axes.pointer == VCasePointer.Fine) RaftPointerInput.Fine else RaftPointerInput.Touch, + ) { + Box(Modifier.background(RaftTheme.colors.layerCanvas).padding(16.dp)) { content() } + } + } +} diff --git a/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/SaveStatusCases.kt b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/SaveStatusCases.kt new file mode 100644 index 0000000000..2f815000f2 --- /dev/null +++ b/compose/designsystem/src/desktopVcase/kotlin/build/raft/designsystem/vcase/SaveStatusCases.kt @@ -0,0 +1,51 @@ +package build.raft.designsystem.vcase + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import build.raft.designsystem.components.RaftField +import build.raft.designsystem.components.RaftListRow +import build.raft.designsystem.components.RaftListRowVariant +import build.raft.designsystem.components.RaftSaveStatusState +import build.raft.designsystem.components.RaftSelectTrigger +import build.raft.designsystem.components.RaftSwitch +import dev.vcase.VCase + +/** + * [build.raft.designsystem.components.RaftSaveStatus] (raft-ui 0.84.0 SaveStatus, + * `save-status/compositions/preview` and `failed`): under a select in a field and under a + * settings row's description, idle (no line, no room) and failed. + * Replaces SaveStatusScreenshotTest (save_status_light/_dark). + */ +@VCase("ds.save-status.gallery") +@Composable +fun SaveStatusGallery() { + val states = listOf("Idle" to RaftSaveStatusState.Idle, "Failed" to null) + Column(Modifier.width(358.dp), verticalArrangement = Arrangement.spacedBy(14.dp)) { + states.forEach { (name, idle) -> + Caption("$name: field with a select") + CanvasSurface(padded = true) { + RaftField( + label = "Time zone", + description = "Used for times in messages.", + saveStatus = idle ?: RaftSaveStatusState.Failed("Couldn't change the time zone. Try again."), + ) { + RaftSelectTrigger(value = "Asia/Shanghai", onClick = {}) + } + } + Caption("$name: settings row") + CanvasSurface { + RaftListRow( + title = "Mute this server", + variant = RaftListRowVariant.Plain, + description = "No notifications from its channels.", + saveStatus = idle ?: RaftSaveStatusState.Failed("Couldn't mute this server. Try again."), + trailing = { RaftSwitch(checked = true, onCheckedChange = {}) }, + ) + } + } + } +} diff --git a/compose/settings.gradle.kts b/compose/settings.gradle.kts index eef7513af4..c55c66637d 100644 --- a/compose/settings.gradle.kts +++ b/compose/settings.gradle.kts @@ -97,6 +97,7 @@ dependencyResolutionManagement { includeModuleByRegex("com\\.tencent\\.kuiklybase", "resource-core.*") includeModuleByRegex("build\\.raft\\.kuiklybase", "datetime.*") includeModuleByRegex("build\\.raft\\.mermaid", ".*") + includeGroup("build.raft.vcase") } } }