Test previews with a11y details and add a first example with HomeViewA11yPreview.

This commit is contained in:
Benoit Marty 2025-08-23 16:43:50 +02:00 committed by Benoit Marty
parent 4653164572
commit c13d9a935b
5 changed files with 105 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import com.google.common.truth.Truth.assertThat
import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.ext.list.withAllAnnotationsOf
import com.lemonappdev.konsist.api.ext.list.withName
import com.lemonappdev.konsist.api.ext.list.withNameEndingWith
import com.lemonappdev.konsist.api.ext.list.withoutName
import com.lemonappdev.konsist.api.verify.assertEmpty
import com.lemonappdev.konsist.api.verify.assertTrue
@ -32,6 +33,26 @@ class KonsistPreviewTest {
}
}
@Test
fun `Check functions with 'A11yPreview'`() {
Konsist
.scopeFromProject()
.functions()
.withNameEndingWith("A11yPreview")
.assertTrue(
additionalMessage = "Functions with 'A11yPreview' suffix should have '@Previews' annotation and not '@PreviewsDayNight'," +
" should contain 'ElementPreview' composable," +
" should contain the tested view" +
" and should be internal"
) {
val testedView = it.name.removeSuffix("A11yPreview")
it.text.contains("$testedView(") &&
it.hasAllAnnotationsOf(PreviewsDayNight::class).not() &&
it.text.contains("ElementPreview") &&
it.hasInternalModifier
}
}
@Test
fun `Functions with '@PreviewsDayNight' annotation should contain 'ElementPreview' composable`() {
Konsist