Skip to content
Merged
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 @@ -70,4 +70,4 @@ val trigger = Button(context).apply {
<!-- @sample: com/sdds/uikit/fixtures/NotificationContent_Simple.xml -->
```

<!-- @screenshot: com.sdds.uikit.fixtures.samples.notification.content.NotificationContent.Simple -->
<!-- @screenshot: com.sdds.uikit.fixtures.samples.notificationcontent.NotificationContent.Simple -->
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import androidx.compose.ui.test.onRoot
import androidx.test.core.app.ApplicationProvider
import com.github.takahirom.roborazzi.RoborazziOptions
import com.github.takahirom.roborazzi.RoborazziRule
import com.github.takahirom.roborazzi.captureRoboImage
import com.sdds.compose.docs.ComposableSample
import com.sdds.compose.docs.ComposableSamples
import org.json.JSONObject
import org.junit.AfterClass
import org.junit.Rule
import org.junit.rules.TestWatcher
import org.junit.runner.Description
Expand All @@ -26,6 +29,8 @@ open class RoborazziConfigDocs(
val composableSample: ComposableSampleInfo,
) {

private val providedStyles: Set<String> by lazy { ProvidedStyleKeys }

/**
* Правило для регистрации Activity до запуска тестов
*/
Expand Down Expand Up @@ -75,6 +80,27 @@ open class RoborazziConfigDocs(
@Suppress("UndocumentedPublicClass")
data class ComposableSampleInfo(val id: String, val sample: ComposableSample)

/**
* Добавляем скриншот, если компонент входит в список
*/
fun ifNeedScreenshot() {
var shouldCapture = true
val componentName = composableSample.id
.substringAfterLast(".")
.substringBefore("_")
.lowercase()
shouldCapture = providedStyles.any { styleKey ->
componentName == styleKey.lowercase()
}
println(" componentName: $componentName, ищем в: $providedStyles, совпали: $shouldCapture")
if (shouldCapture) {
composeTestRule.onRoot().captureRoboImage()
} else {
skippedTests.add(composableSample.id)
println("Skipped tests: ${composableSample.id}")
}
}

companion object {
/**
* Папка для сохранения скриншотов
Expand All @@ -84,6 +110,44 @@ open class RoborazziConfigDocs(
"override-docs/static/screenshots-docusaurus",
)

private val skippedTests = mutableListOf<String>()

/**
* Поиск названия компонентов в config-info-view-system.json
*/
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())
}
}
}

/**
* Выводим список пропущенных тестов
*/
@AfterClass
@JvmStatic
fun skippedTests() {
if (skippedTests.isNotEmpty()) {
println("Skipped tests: ${skippedTests.size} screenshots:")
skippedTests.forEach { println(" - $it") }
}
}

/**
* Параметризированные тесты
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sdds.uikit.fixtures.samples.content
package com.sdds.uikit.fixtures.samples.notificationcontent

import android.content.Context
import android.view.LayoutInflater
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.takahirom.roborazzi.RoborazziRule
import com.sdds.docs.ViewSample
import com.sdds.docs.ViewSamples
import com.sdds.uikit.utils.TextAppearanceConfig
import org.json.JSONObject
import org.junit.Before
import org.junit.Rule
import org.robolectric.ParameterizedRobolectricTestRunner
Expand Down Expand Up @@ -66,6 +67,33 @@ open class RoborazziConfigDocsXml(
"override-docs/static/screenshots-docusaurus",
)

/**
* Поиск названия компонентов в config-info-view-system.json
*/
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)
add(component.getString("key").replace("-", "").lowercase())
add(component.getString("coreName").lowercase())
add(component.getString("styleName").lowercase())
}
}
}

/**
* Параметризированные тесты
*/
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,8 +1,6 @@
package com.sdkit.star.designsystem

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.Test
Expand All @@ -23,7 +21,7 @@ class ComposeDocScreenshotTest(composableSample: ComposableSampleInfo) : Roboraz
composableSample.sample.reference.invoke()
}
composeTestRule.waitForIdle()
composeTestRule.onRoot().captureRoboImage()
ifNeedScreenshot()
} catch (e: Throwable) {
throw AssertionError(
"Screenshot test failed: \n${composableSample.id}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 +97,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 @@ -202,6 +206,7 @@ fun ThemeSetup(
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 @@ -3,6 +3,7 @@ package com.sdkit.star.designsystem
import android.view.View
import com.sdds.uikit.fixtures.ComponentScope
import com.sdds.uikit.fixtures.component
import com.sdds.uikit.fixtures.samples.RoborazziConfigDocsXml.Companion.ProvidedStyleKeys
import org.hamcrest.Matcher

internal fun themedComponent(
Expand All @@ -20,3 +21,33 @@ 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)
}
println(" componentName: $componentName, ищем в: $ProvidedStyleKeys, совпали: $shouldCapture")

if (!shouldCapture) {
println("Пропущены: $sampleId")
return
}
themedComponent(
viewMatcherFactory = viewMatcherFactory,
action = action,
skipDefaultCaptureRoboImage = skipDefaultCaptureRoboImage,
factory = factory,
)
}
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.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.sdds.plasma.giga

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.Test
Expand All @@ -23,7 +21,7 @@ class ComposeDocScreenshotTest(composableSample: ComposableSampleInfo) : Roboraz
composableSample.sample.reference.invoke()
}
composeTestRule.waitForIdle()
composeTestRule.onRoot().captureRoboImage()
ifNeedScreenshot()
} catch (e: Throwable) {
throw AssertionError(
"Screenshot test failed: \n${composableSample.id}",
Expand Down
Loading
Loading