From 5427c113f07c7d6e8525bd67a4ac93f719d4e77e Mon Sep 17 00:00:00 2001 From: MOHIT GUPTA <76530270+MohitGupta121@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:04:24 -0600 Subject: [PATCH] Fix #5072 : Remove condition of hex color for drawables from regex (#5076) ## Explanation Fix https://github.com/oppia/oppia-android/issues/5072 : Remove condition of hex color for drawables from regex ## Essential Checklist - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## For UI-specific PRs only If your PR includes UI-related changes, then: - Add screenshots for portrait/landscape for both a tablet & phone of the before & after UI changes - For the screenshots above, include both English and pseudo-localized (RTL) screenshots (see [RTL guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines)) - Add a video showing the full UX flow with a screen reader enabled (see [accessibility guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide)) - Add a screenshot demonstrating that you ran affected Espresso tests locally & that they're passing --- .../file_content_validation_checks.textproto | 11 ------- .../regex/RegexPatternValidationCheckTest.kt | 32 +------------------ 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/scripts/assets/file_content_validation_checks.textproto b/scripts/assets/file_content_validation_checks.textproto index ab9c8af53ec..40a355c58f2 100644 --- a/scripts/assets/file_content_validation_checks.textproto +++ b/scripts/assets/file_content_validation_checks.textproto @@ -352,17 +352,6 @@ file_content_checks { prohibited_content_regex: "@color/(?!component_color_).+|\"#\\p{XDigit}+\"" failure_message: "Only colors from component_colors.xml may be used in layouts." } -file_content_checks { - file_path_regex: "app/src/main/res/drawable.*?/.+?\\.xml" - prohibited_content_regex: "@color/(?!component_color_).+|\"#\\p{XDigit}+\"" - failure_message: "Only colors from component_colors.xml may be used in drawables except vector assets." - exempted_file_patterns: "app/src/main/res/drawable.*?/(ic_|lesson_thumbnail_graphic_).+?\\.xml" - exempted_file_patterns: "app/src/main/res/drawable/full_oppia_logo.xml" - exempted_file_patterns: "app/src/main/res/drawable/rounded_white_background_with_shadow.xml" - exempted_file_patterns: "app/src/main/res/drawable/profile_image_shadow.xml" - exempted_file_patterns: "app/src/main/res/drawable/selected_region_background.xml" - exempted_file_patterns: "app/src/main/res/drawable/splash_page.xml" -} file_content_checks { file_path_regex: "app/src/main/java/org/oppia/android/app.?/.+(ActivityPresenter|FragmentPresenter|ViewPresenter|Activity|Fragment|View)\\.kt" prohibited_content_regex: "R.color.(?!component_color_).+" diff --git a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt index 20fd219f857..ae1d4fa60ff 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt @@ -173,8 +173,6 @@ class RegexPatternValidationCheckTest { "Only colors from color_defs.xml may be used in color_palette.xml." private val doesNotReferenceColorFromComponentColorInLayouts = "Only colors from component_colors.xml may be used in layouts." - private val doesNotReferenceColorFromComponentColorInDrawables = - "Only colors from component_colors.xml may be used in drawables except vector assets." private val doesNotReferenceColorFromComponentColorInKotlinFiles = "Only colors from component_colors.xml may be used in Kotlin Files (Activities, Fragments, " + "Views and Presenters)." @@ -2345,35 +2343,7 @@ class RegexPatternValidationCheckTest { ) } - @Test - fun testFileContent_xmlDrawables_includesNonColorComponentReferences_fileContentIsNotCorrect() { - val prohibitedContent = - """ - android:color="@color/component_color_shared_primary_text_color" - android:color="@color/color_defs_shared_primary_text_color" - android:color="@color/color_palette_primary_text_color" - android:color="#003933" - """.trimIndent() - tempFolder.newFolder("testfiles", "app", "src", "main", "res", "drawable") - val stringFilePath = "app/src/main/res/drawable/test_layout.xml" - tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent) - - val exception = assertThrows(Exception::class) { - runScript() - } - - // Verify that all patterns are properly detected & prohibited. - assertThat(exception).hasMessageThat().contains(REGEX_CHECK_FAILED_OUTPUT_INDICATOR) - assertThat(outContent.toString().trim()) - .isEqualTo( - """ - $stringFilePath:2: $doesNotReferenceColorFromComponentColorInDrawables - $stringFilePath:3: $doesNotReferenceColorFromComponentColorInDrawables - $stringFilePath:4: $doesNotReferenceColorFromComponentColorInDrawables - $wikiReferenceNote - """.trimIndent() - ) - } + // TODO(#5075): Add test for drawables file that checks color uses only component colors @Test fun testFileContent_kotlinFiles_includesNonColorComponentReferences_fileContentIsNotCorrect() {