Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ android {
testOptions {
unitTests {
isIncludeAndroidResources = true
all {
it.systemProperty("moduleDir", projectDir.absolutePath)
}
}
}
tasks.withType<Test> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ fun Project.filterComponents(docsDir: File, componentsConfig: File) {
}

fun File.needScreenshots(components: Set<String>): Boolean {
val componentName = name.removeSuffix("Usage.md")
return components.any { it.contains(componentName) || componentName.contains(it) }
val componentName = name.removeSuffix("Usage.md").lowercase()
return components.any { it.lowercase() == componentName }
}

fun Project.resolveComponents(componentsConfig: File): Set<String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: ModalBottomSheet
title: BottomSheet
---

Модальное, диалоговое окно в формате bottom sheet. Используется для отображения дополнительного контента
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ title: IconButton
// @sample: com/sdds/compose/uikit/fixtures/samples/button/IconButton_Simple.kt
```

<!-- @screenshot: com.sdds.compose.uikit.fixtures.samples.button.IconButton_Simple -->

## Стиль IconButton

Стиль IconButton можно настроить с помощью ButtonStyle.builder(). Так же существует набор сгенерированных стилей.
Expand All @@ -24,6 +26,8 @@ title: IconButton
// @sample: com/sdds/compose/uikit/fixtures/samples/button/IconButton_isLoading.kt
```

<!-- @screenshot: com.sdds.compose.uikit.fixtures.samples.button.IconButton.isLoading -->

## Произвольный контент в IconButton

Вместо указания ресурса иконки, имеется возможность передать самостоятельно настроенный контент.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ title: Icon
// @sample: com/sdds/compose/uikit/fixtures/samples/icon/Icon_ImageVector.kt
```

<!-- @screenshot: com.sdds.compose.uikit.fixtures.samples.icon.Icon_Image -->

### ImageBitmap

Используется для отображения растровых изображений:
Expand All @@ -69,6 +71,8 @@ title: Icon
// @sample: com/sdds/compose/uikit/fixtures/samples/icon/Icon_Brush.kt
```

<!-- @screenshot: com.sdds.compose.uikit.fixtures.samples.icon.IconCompositionLocal_Simple -->

## Настройка размера

Размер изображения (иконки) определяется:
Expand All @@ -81,6 +85,8 @@ title: Icon
// @sample: com/sdds/compose/uikit/fixtures/samples/icon/Icon_DefaultSize.kt
```

<!-- @screenshot: com.sdds.compose.uikit.fixtures.samples.icon.IconCompositionLocalSize_Simple -->

## Semantics

Если передан contentDescription, иконка будет доступна для систем доступности (например TalkBack).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun Avatar_Simple() {
}

@Composable
@DocSample(needScreenshot = true)
@DocSample(needScreenshot = false)
fun Avatar_ActionDisabled() {
composableCodeSnippet {
Avatar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fun ModalBottomSheet_Simple() {
}

@Composable
@DocSample(needScreenshot = true)
@DocSample(needScreenshot = false)
fun ModalBottomSheet_HalfExpanded_Skip() {
composableCodeSnippet {
val sheetState = rememberModalBottomSheetState(
Expand Down Expand Up @@ -138,7 +138,7 @@ fun ModalBottomSheet_HalfExpanded_Skip() {
}

@Composable
@DocSample(needScreenshot = true)
@DocSample(needScreenshot = false)
fun ModalBottomSheet_HalfExpanded_Fraction() {
composableCodeSnippet {
val sheetState = rememberModalBottomSheetState(
Expand Down Expand Up @@ -167,7 +167,7 @@ fun ModalBottomSheet_HalfExpanded_Fraction() {
}

@Composable
@DocSample(needScreenshot = true)
@DocSample(needScreenshot = false)
fun ModalBottomSheet_HalfExpanded_Height() {
composableCodeSnippet {
val sheetState = rememberModalBottomSheetState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,10 @@ fun Carousel_Style() {
indicatorPadding(8.0.dp)
gap(8.dp)
}
.prevButtonStyle(
placeholder(
ButtonStyle.iconButtonBuilder().style(),
"/** Стиль компонента IconButton */",
),
)
.nextButtonStyle(
placeholder(
ButtonStyle.iconButtonBuilder().style(),
"/** Стиль компонента IconButton */",
),
)
.prevButtonStyle(placeholder(ButtonStyle.iconButtonBuilder().style(), "/** Стиль компонента IconButton */"))
.nextButtonStyle(placeholder(ButtonStyle.iconButtonBuilder().style(), "/** Стиль компонента IconButton */"))
.indicatorStyle(
placeholder(
PaginationDotsStyle.builder().style(),
"/** Стиль компонента PaginationDots */",
),
placeholder(PaginationDotsStyle.builder().style(), "/** Стиль компонента PaginationDots */"),
)
.prevButtonIcon(R.drawable.ic_chevron_left_36)
.nextButtonIcon(R.drawable.ic_chevron_right_36)
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.sdkit.star.designsystem

import androidx.compose.runtime.SideEffect
import androidx.compose.ui.test.onRoot
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
import com.github.takahirom.roborazzi.captureRoboImage
import com.sdds.compose.uikit.fixtures.SDK_NUMBER
import com.sdds.compose.uikit.fixtures.samples.RoborazziConfigDocs
import org.junit.AfterClass
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
Expand All @@ -18,17 +20,48 @@ class ComposeDocScreenshotTest(composableSample: ComposableSampleInfo) : Roboraz

@Test
fun docs_screenshot_test() {
var shouldCapture = true

try {
composeTestRule.content {
val providedStyles = LocalProvidedStyles.current
SideEffect {
val componentName = composableSample.id
.substringAfterLast(".")
.substringBefore("_")
.lowercase()
shouldCapture = providedStyles.any { styleKey ->
componentName == styleKey.lowercase()
}
println(" componentName: $componentName, ищем в: $providedStyles, совпали: $shouldCapture")
}
composableSample.sample.reference.invoke()
}
composeTestRule.waitForIdle()
composeTestRule.onRoot().captureRoboImage()
if (shouldCapture) {
composeTestRule.onRoot().captureRoboImage()
} else {
skippedTests.add(composableSample.id)
println("Skipped tests: ${composableSample.id}")
}
} catch (e: Throwable) {
throw AssertionError(
"Screenshot test failed: \n${composableSample.id}",
e,
)
}
}

companion object {
private val skippedTests = mutableListOf<String>()

@AfterClass
@JvmStatic
fun skippedTests() {
if (skippedTests.isNotEmpty()) {
println("Skipped tests: ${skippedTests.size} screenshots:")
skippedTests.forEach { println(" - $it") }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
Expand All @@ -28,6 +29,7 @@ import com.sdds.compose.uikit.LocalDividerStyle
import com.sdds.compose.uikit.LocalDrawerStyle
import com.sdds.compose.uikit.LocalDropdownMenuStyle
import com.sdds.compose.uikit.LocalIconBadgeStyle
import com.sdds.compose.uikit.LocalIconButtonStyle
import com.sdds.compose.uikit.LocalImageStyle
import com.sdds.compose.uikit.LocalIndicatorStyle
import com.sdds.compose.uikit.LocalListStyle
Expand Down Expand Up @@ -96,6 +98,9 @@ import com.sdkit.star.designsystem.styles.dropdownmenu.M
import com.sdkit.star.designsystem.styles.iconbadge.Default
import com.sdkit.star.designsystem.styles.iconbadge.IconBadgeSolid
import com.sdkit.star.designsystem.styles.iconbadge.M
import com.sdkit.star.designsystem.styles.iconbutton.Clear
import com.sdkit.star.designsystem.styles.iconbutton.IconButton
import com.sdkit.star.designsystem.styles.iconbutton.M
import com.sdkit.star.designsystem.styles.image.Image
import com.sdkit.star.designsystem.styles.image.Ratio3x4
import com.sdkit.star.designsystem.styles.indicator.Default
Expand Down Expand Up @@ -156,12 +161,37 @@ import com.sdkit.star.designsystem.theme.darkStarDsColors
import com.sdkit.star.designsystem.theme.darkStarDsGradients
import com.sdkit.star.designsystem.theme.lightStarDsColors
import com.sdkit.star.designsystem.theme.lightStarDsGradients
import org.json.JSONObject
import java.io.File

private val DarkColors = darkStarDsColors()
private val LightColors = lightStarDsColors()
private val DarkGradients = darkStarDsGradients()
private val LightGradients = lightStarDsGradients()

val LocalProvidedStyles = compositionLocalOf { emptySet<String>() }

val ProvidedStyleKeys: Set<String> by lazy {
val moduleDir = System.getProperty("moduleDir") ?: ""
println("mooduleDir: $moduleDir")
val jsonFile = File(moduleDir).parentFile?.resolve("config-info-compose.json")
?: return@lazy emptySet()

if (!jsonFile.exists()) return@lazy emptySet()

val json = JSONObject(jsonFile.readText())
val components = json.getJSONArray("components")

buildSet {
for (i in 0 until components.length()) {
val component = components.getJSONObject(i)
add(component.getString("key").replace("-", "").lowercase())
add(component.getString("coreName").lowercase())
add(component.getString("styleName").lowercase())
}
}
}

/**
* Тема для тестов
*/
Expand Down Expand Up @@ -196,12 +226,14 @@ fun ThemeSetup(
gradients = if (darkTheme) DarkGradients else LightGradients,
) {
CompositionLocalProvider(
LocalProvidedStyles provides ProvidedStyleKeys,
LocalAvatarGroupStyle provides AvatarGroup.S.style(),
LocalAvatarStyle provides Avatar.M.style(),
LocalBadgeStyle provides BadgeSolid.M.Default.style(),
LocalIconBadgeStyle provides IconBadgeSolid.M.Default.style(),
LocalButtonGroupStyle provides BasicButtonGroup.M.Dense.Default.style(),
LocalButtonStyle provides BasicButton.M.Default.style(),
LocalIconButtonStyle provides IconButton.M.Clear.style(),
LocalCellStyle provides Cell.M.style(),
LocalCheckBoxGroupStyle provides CheckBoxGroup.M.style(),
LocalCheckBoxStyle provides CheckBox.M.Default.style(),
Expand Down
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.view.View
import com.sdds.uikit.fixtures.ComponentScope
import com.sdds.uikit.fixtures.component
import org.hamcrest.Matcher
import org.json.JSONObject
import java.io.File

internal fun themedComponent(
viewMatcherFactory: ((View) -> Matcher<View>)? = null,
Expand All @@ -20,3 +22,57 @@ internal fun themedComponent(
factory,
)
}

internal fun themedComponentStyleProvided(
sampleId: String,
viewMatcherFactory: ((View) -> Matcher<View>)? = null,
action: ((View) -> Unit)? = null,
skipDefaultCaptureRoboImage: Boolean = false,
factory: ComponentScope.() -> View,
) {
val componentName = sampleId.substringBeforeLast(".").split(".")
val component = componentName.takeLast(2).joinToString("").lowercase()
val lastSegment = componentName.last().lowercase()

val shouldCapture = ProvidedStyleKeys.any { styleKey ->
val key = styleKey.replace("-", "").lowercase()
component.contains(key) || key.contains(component) ||
key.contains(lastSegment) || lastSegment.contains(key)
}

if (!shouldCapture) {
println("Пропущены: $sampleId")
return
}
themedComponent(
viewMatcherFactory = viewMatcherFactory,
action = action,
skipDefaultCaptureRoboImage = skipDefaultCaptureRoboImage,
factory = factory,
)
}

val ProvidedStyleKeys: Set<String> by lazy {
val moduleDir = System.getProperty("moduleDir") ?: ""
println("mooduleDir: $moduleDir")
val jsonFile = File(moduleDir).parentFile?.resolve("config-info-view-system.json")
?: return@lazy emptySet()

if (!jsonFile.exists()) return@lazy emptySet()

println("jsonFile: ${jsonFile.absolutePath}")
println("jsonFile.exists(): ${jsonFile.exists()}")

val json = JSONObject(jsonFile.readText())
val components = json.getJSONArray("components")

buildSet {
for (i in 0 until components.length()) {
val component = components.getJSONObject(i)
val key = component.getString("key")
.replace("-", "")
.lowercase()
add(key)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ViewSystemDocScreenshotTest(viewSample: ViewSampleInfo) :
@Test
fun docs_view_screenshot_test() {
try {
themedComponent(
themedComponentStyleProvided(
sampleId = viewSample.id,
factory = {
viewSample.sample.reference(context)
},
Expand Down
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading
Loading