Skip to content

Commit

Permalink
Fix #5072 : Remove condition of hex color for drawables from regex (#…
Browse files Browse the repository at this point in the history
…5076)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Fix #5072 : Remove
condition of hex color for drawables from regex

<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [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
<!-- Delete these section if this PR does not include UI-related
changes. -->
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
  • Loading branch information
MohitGupta121 authored Jun 28, 2023
1 parent 1c1841b commit 5427c11
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
11 changes: 0 additions & 11 deletions scripts/assets/file_content_validation_checks.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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_).+"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5427c11

Please sign in to comment.