Skip to content

Test widget background type mapping#7010

Closed
sgallese wants to merge 1 commit into
home-assistant:mainfrom
sgallese:showcase/entity-widget-config-mapping-test
Closed

Test widget background type mapping#7010
sgallese wants to merge 1 commit into
home-assistant:mainfrom
sgallese:showcase/entity-widget-config-mapping-test

Conversation

@sgallese

Copy link
Copy Markdown
Contributor

Summary

  • Add tests for WidgetUtils.getWidgetBackgroundType().
  • Reuse that helper when saving the entity widget background type.
  • Prep for the entity widget XML-to-Compose migration by covering the shared background type mapping.

Refs #6307.

Testing

  • ./gradlew :app:testFullDebugUnitTest --tests '*WidgetUtilsTest*'
  • ./gradlew :app:ktlintCheck
  • ./gradlew :app:assembleFullDebug
  • Manually launched EntityWidgetConfigureActivity on Pixel_8_API_35 and verified the theme dropdown behavior.
Manual verification screenshots

Captured from Pixel_8_API_35.

Default Theme menu Transparent Light/dark
Default widget configuration Theme dropdown Transparent theme selected Light/dark theme selected
entity-widget-config.mp4

Copilot AI review requested due to automatic review settings June 12, 2026 03:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds centralized widget background-type parsing via WidgetUtils.getWidgetBackgroundType and covers it with Robolectric tests, then reuses it in entity widget configuration to keep background + text color logic consistent.

Changes:

  • Added WidgetUtilsTest to verify background option string → WidgetBackgroundType mapping (including fallback behavior).
  • Refactored EntityWidgetConfigureActivity to use WidgetUtils.getWidgetBackgroundType and derive text color from the resolved enum.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
app/src/test/kotlin/io/homeassistant/companion/android/widgets/common/WidgetUtilsTest.kt Adds Robolectric unit tests for widget background type mapping.
app/src/main/kotlin/io/homeassistant/companion/android/widgets/entity/EntityWidgetConfigureActivity.kt Uses WidgetUtils for background type selection and updates text color selection accordingly.

Comment on lines +345 to +346
val selectedBackgroundOption = binding.backgroundType.selectedItem as String? ?: ""
val selectedBackgroundType = WidgetUtils.getWidgetBackgroundType(this, selectedBackgroundOption)
@RunWith(RobolectricTestRunner::class)
@Config(application = HiltTestApplication::class)
class WidgetUtilsTest {
private val context = ApplicationProvider.getApplicationContext<HiltTestApplication>()
@sgallese

Copy link
Copy Markdown
Contributor Author

Closing because #7007 already covers this migration work.

@sgallese sgallese closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants