Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing translations and descriptions for notification fields in UI #132676

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/helpers/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from unittest.mock import Mock, call, patch

import pytest
import voluptuous as vol

from homeassistant import loader
from homeassistant.const import EVENT_CORE_CONFIG_UPDATE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import translation
import homeassistant.helpers.config_validation as cv
from homeassistant.setup import async_setup_component


Expand Down Expand Up @@ -712,3 +714,57 @@ async def test_get_translations_still_has_title_without_translations_files(
assert translations == {
"component.component1.title": "Component 1",
}


@pytest.fixture
async def mock_integration(hass: HomeAssistant):
"""Set up a mock notification service."""

async def test_service(call):
pass

hass.services.async_register(
"test_notify",
"send_message",
test_service,
schema=vol.Schema(
{
vol.Required("message"): cv.string,
vol.Optional("title"): cv.string,
}
),
)


async def test_translation_for_notify_service(
Copy link
Member

Choose a reason for hiding this comment

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

Since we want to test the notify integration service descriptions I'd expect this test to be part of the notify integration (legacy) tests.

hass: HomeAssistant, mock_integration
) -> None:
"""Test that the notification service description is translated correctly."""
translations = {
"component.test_notify.services.send_message.description": "Send a translated test notification",
"component.test_notify.services.send_message.fields.message.description": "Translated message description",
"component.test_notify.services.send_message.fields.title.description": "Translated title description",
}

with patch(
"homeassistant.helpers.translation.async_get_translations",
return_value=translations,
):
descriptions = await translation.async_get_translations(hass, "en", "services")
Copy link
Member

Choose a reason for hiding this comment

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

This isn't testing any production code. The call here is calling the mock patched above.


assert (
descriptions["component.test_notify.services.send_message.description"]
== "Send a translated test notification"
)
assert (
descriptions[
"component.test_notify.services.send_message.fields.message.description"
]
== "Translated message description"
)
assert (
descriptions[
"component.test_notify.services.send_message.fields.title.description"
]
== "Translated title description"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""notify."""

DOMAIN = "test_notify"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"domain": "test_notify",
"name": "Test Notify",
"documentation": "https://example.com",
"dependencies": [],
"codeowners": [],
"requirements": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
send_message:
description: "Sends a test notification"
fields:
message:
description: "The message to send"
title:
description: "The title of the message"
15 changes: 15 additions & 0 deletions tests/testing_config/custom_components/test_notify/strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"services": {
"send_message": {
"description": "Send a translated test notification",
"fields": {
"message": {
"description": "Translated message description"
},
"title": {
"description": "Translated title description"
}
}
}
}
}
Loading