Skip to content

Commit

Permalink
Merge branch 'develop' into oppia#3843
Browse files Browse the repository at this point in the history
  • Loading branch information
XichengSpencer authored Sep 22, 2023
2 parents 9c56e24 + c28b8ee commit 8d9cf96
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#25000000" />
<solid android:color="@color/component_color_button_shadow_color" />
<corners android:radius="@dimen/survey_shared_corner_radius" />
</shape>
</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-night/color_palette.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,5 @@
<color name="color_palette_nps_unselected_background_color">@color/color_def_pale_green</color>
<color name="color_palette_edit_text_inactive_color">@color/color_def_black_87</color>
<color name="color_palette_edit_text_active_color">@color/color_def_white</color>
<color name="color_palette_button_shadow_color">@color/color_def_black_25</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/color_defs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@

<color name="color_def_survey_disabled_button_grey">#E8E8E8</color>
<color name="color_def_pale_green">#E2F5F4</color>
<color name="color_def_black_25">#25000000</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/color_palette.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,5 @@
<color name="color_palette_edit_text_unselected_color">@color/color_def_grey</color>
<color name="color_palette_edit_text_inactive_color">@color/color_def_black_87</color>
<color name="color_palette_edit_text_active_color">@color/color_def_black_87</color>
<color name="color_palette_button_shadow_color">@color/color_def_black_25</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/component_colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,5 @@
<color name="component_color_survey_disabled_button_text_color">@color/color_palette_survey_disabled_button_text_color</color>
<color name="component_color_begin_survey_button_text_color">@color/color_palette_button_text_color</color>
<color name="component_color_survey_edit_text_unselected_color">@color/color_palette_edit_text_unselected_color</color>
<color name="component_color_button_shadow_color">@color/color_palette_button_shadow_color</color>
</resources>
13 changes: 13 additions & 0 deletions scripts/assets/file_content_validation_checks.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,19 @@ 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"
exempted_file_patterns: "app/src/main/res/drawable/survey_nps_radio_selected_color.xml"
exempted_file_patterns: "app/src/main/res/drawable/survey_nps_radio_unselected_color.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,6 +173,8 @@ 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 @@ -2343,7 +2345,35 @@ class RegexPatternValidationCheckTest {
)
}

// TODO(#5075): Add test for drawables file that checks color uses only component colors
@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()
)
}

@Test
fun testFileContent_kotlinFiles_includesNonColorComponentReferences_fileContentIsNotCorrect() {
Expand Down

0 comments on commit 8d9cf96

Please sign in to comment.