From ff254554c6e7f28edbb0e2fc8d1dc102256ee49d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 19 Apr 2024 12:56:19 +0200 Subject: [PATCH] Add Konsist test to check preview function names. --- .../tests/konsist/KonsistPreviewTest.kt | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt index 04f5e2c0b3..be7780b4e7 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt @@ -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: 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