Add support for re-ordering Google Tasks (#104769)

* Add reorder and task ordering

* Remove un-needed js id code

* Revert dead code deletion

* Remove reverted test and dead logger

* Update comment name
This commit is contained in:
Allen Porter 2023-12-22 09:49:41 -08:00 committed by GitHub
parent 32a5345a85
commit 656d0696bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 154 additions and 0 deletions

View file

@ -74,6 +74,29 @@ LIST_TASKS_RESPONSE_MULTIPLE = {
},
],
}
LIST_TASKS_RESPONSE_REORDER = {
"items": [
{
"id": "some-task-id-2",
"title": "Milk",
"status": "needsAction",
"position": "00000000000000000002",
},
{
"id": "some-task-id-1",
"title": "Water",
"status": "needsAction",
"position": "00000000000000000001",
},
# Task 3 moved after task 1
{
"id": "some-task-id-3",
"title": "Cheese",
"status": "needsAction",
"position": "000000000000000000011",
},
],
}
# API responses when testing update methods
UPDATE_API_RESPONSES = [
@ -793,6 +816,64 @@ async def test_parent_child_ordering(
assert items == snapshot
@pytest.mark.parametrize(
"api_responses",
[
[
LIST_TASK_LIST_RESPONSE,
LIST_TASKS_RESPONSE_MULTIPLE,
EMPTY_RESPONSE, # move
LIST_TASKS_RESPONSE_REORDER, # refresh after move
]
],
)
async def test_move_todo_item(
hass: HomeAssistant,
setup_credentials: None,
integration_setup: Callable[[], Awaitable[bool]],
ws_get_items: Callable[[], Awaitable[dict[str, str]]],
hass_ws_client: WebSocketGenerator,
mock_http_response: Any,
snapshot: SnapshotAssertion,
) -> None:
"""Test for re-ordering a To-do Item."""
assert await integration_setup()
state = hass.states.get(ENTITY_ID)
assert state
assert state.state == "3"
items = await ws_get_items()
assert items == snapshot
# Move to second in the list
client = await hass_ws_client()
data = {
"id": id,
"type": "todo/item/move",
"entity_id": ENTITY_ID,
"uid": "some-task-id-3",
"previous_uid": "some-task-id-1",
}
await client.send_json_auto_id(data)
resp = await client.receive_json()
assert resp.get("success")
assert len(mock_http_response.call_args_list) == 4
call = mock_http_response.call_args_list[2]
assert call
assert call.args == snapshot
assert call.kwargs.get("body") == snapshot
state = hass.states.get(ENTITY_ID)
assert state
assert state.state == "3"
items = await ws_get_items()
assert items == snapshot
@pytest.mark.parametrize(
"api_responses",
[