Add Konsist test to check preview function names.

This commit is contained in:
Benoit Marty 2024-04-19 12:56:19 +02:00 committed by Benoit Marty
parent 74a9a54719
commit ff254554c6

View file

@ -19,6 +19,7 @@ package io.element.android.tests.konsist
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.ext.list.withAllAnnotationsOf
import com.lemonappdev.konsist.api.ext.list.withoutName
import com.lemonappdev.konsist.api.verify.assertEmpty
import com.lemonappdev.konsist.api.verify.assertTrue
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
@ -60,6 +61,82 @@ class KonsistPreviewTest {
}
}
@Test
fun `Functions with '@PreviewsDayNight' have correct name`() {
Konsist
.scopeFromProject()
.functions()
.withAllAnnotationsOf(PreviewsDayNight::class)
.withoutName(
"AsyncIndicatorFailurePreview",
"AsyncIndicatorLoadingPreview",
"BloomInitialsPreview",
"BloomPreview",
"ColorAliasesPreview",
"DefaultRoomListTopBarWithIndicatorPreview",
"GradientFloatingActionButtonCircleShapePreview",
"IconTitleSubtitleMoleculeWithResIconPreview",
"IconsCompoundPreview",
"IconsOtherPreview",
"MentionSpanPreview",
"MessageComposerViewVoicePreview",
"MessagesReactionButtonAddPreview",
"MessagesReactionButtonExtraPreview",
"MessagesViewWithTypingPreview",
"PageTitleWithIconFullPreview",
"PageTitleWithIconMinimalPreview",
"PendingMemberRowWithLongNamePreview",
"PinUnlockViewInAppPreview",
"PollAnswerViewDisclosedNotSelectedPreview",
"PollAnswerViewDisclosedSelectedPreview",
"PollAnswerViewEndedSelectedPreview",
"PollAnswerViewEndedWinnerNotSelectedPreview",
"PollAnswerViewEndedWinnerSelectedPreview",
"PollAnswerViewUndisclosedNotSelectedPreview",
"PollAnswerViewUndisclosedSelectedPreview",
"PollContentViewCreatorEditablePreview",
"PollContentViewCreatorEndedPreview",
"PollContentViewCreatorPreview",
"PollContentViewDisclosedPreview",
"PollContentViewEndedPreview",
"PollContentViewUndisclosedPreview",
"ReadReceiptBottomSheetPreview",
"RoomListModalBottomSheetContentForDmPreview",
"RoomMemberListViewBannedPreview",
"SasEmojisPreview",
"SecureBackupSetupViewChangePreview",
"SelectedUserCannotRemovePreview",
"TextComposerEditPreview",
"TextComposerFormattingPreview",
"TextComposerLinkDialogCreateLinkPreview",
"TextComposerLinkDialogCreateLinkWithoutTextPreview",
"TextComposerLinkDialogEditLinkPreview",
"TextComposerReplyPreview",
"TextComposerSimplePreview",
"TextComposerVoicePreview",
"TimelineImageWithCaptionRowPreview",
"TimelineItemEventRowForDirectRoomPreview",
"TimelineItemEventRowTimestampPreview",
"TimelineItemEventRowWithManyReactionsPreview",
"TimelineItemEventRowWithRRPreview",
"TimelineItemEventRowWithReplyPreview",
"TimelineItemGroupedEventsRowContentCollapsePreview",
"TimelineItemGroupedEventsRowContentExpandedPreview",
"TimelineItemVoiceViewUnifiedPreview",
"TimelineVideoWithCaptionRowPreview",
"UserAvatarColorsPreview",
)
.assertTrue(
additionalMessage = "Functions for Preview should be named like this: <ViewUnderPreview>Preview. " +
"Exception can be added to the test, for multiple Previews of the same view",
) {
val testedView = it.name.removeSuffix("Preview")
it.text.contains("$testedView(") ||
it.text.contains("$testedView {") ||
it.text.contains("ContentToPreview(")
}
}
@Test
fun `Ensure that '@PreviewLightDark' is not used`() {
Konsist