Add snapshot testing to Tessie (#108346)
* Redo Binary Sensors * Redo Button * Redo Climate * Stage unfixed platforms * Redo Cover * Redo device tracker * Redo lock * Redo Media Player * Redo Number * Redo Select * Redo Sensor * Redo Switch * Redo Update * Fix setup_platform * Add mixing snapshot * Fix config flow * Centralise entity testing * Update snapshot * Rename test_entities * Fix assert_entities
This commit is contained in:
parent
950660b953
commit
858fb1fa37
27 changed files with 5831 additions and 314 deletions
|
@ -6,41 +6,39 @@ from freezegun.api import FrozenDateTimeFactory
|
|||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.tessie.coordinator import TESSIE_SYNC_INTERVAL
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import (
|
||||
TEST_STATE_OF_ALL_VEHICLES,
|
||||
TEST_VEHICLE_STATE_ONLINE,
|
||||
setup_platform,
|
||||
)
|
||||
from .common import setup_platform
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
WAIT = timedelta(seconds=TESSIE_SYNC_INTERVAL)
|
||||
|
||||
MEDIA_INFO_1 = TEST_STATE_OF_ALL_VEHICLES["results"][0]["last_state"]["vehicle_state"][
|
||||
"media_info"
|
||||
]
|
||||
MEDIA_INFO_2 = TEST_VEHICLE_STATE_ONLINE["vehicle_state"]["media_info"]
|
||||
|
||||
|
||||
async def test_media_player_idle(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, snapshot: SnapshotAssertion
|
||||
async def test_media_player(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Tests that the media player entity is correct when idle."""
|
||||
|
||||
assert len(hass.states.async_all("media_player")) == 0
|
||||
entry = await setup_platform(hass, [Platform.MEDIA_PLAYER])
|
||||
|
||||
await setup_platform(hass)
|
||||
entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||
|
||||
assert len(hass.states.async_all("media_player")) == 1
|
||||
assert entity_entries
|
||||
for entity_entry in entity_entries:
|
||||
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
|
||||
assert (state := hass.states.get(entity_entry.entity_id))
|
||||
assert state == snapshot(name=f"{entity_entry.entity_id}-paused")
|
||||
|
||||
state = hass.states.get("media_player.test_media_player")
|
||||
assert state == snapshot
|
||||
# The refresh fixture has music playing
|
||||
freezer.tick(WAIT)
|
||||
async_fire_time_changed(hass)
|
||||
|
||||
# Trigger coordinator refresh since it has a different fixture.
|
||||
freezer.tick(WAIT)
|
||||
async_fire_time_changed(hass)
|
||||
|
||||
state = hass.states.get("media_player.test_media_player")
|
||||
assert state == snapshot
|
||||
assert hass.states.get(entity_entry.entity_id) == snapshot(
|
||||
name=f"{entity_entry.entity_id}-playing"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue