mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Fix off by one bug when sorting tasks in Habitica integration (#138993)
* Fix off-by-one bug when sorting dailies and to-dos in Habitica * Add test
This commit is contained in:
parent
0f7cb6b757
commit
059a6dddbe
@ -119,12 +119,13 @@ class BaseHabiticaListEntity(HabiticaBase, TodoListEntity):
|
|||||||
assert self.todo_items
|
assert self.todo_items
|
||||||
|
|
||||||
if previous_uid:
|
if previous_uid:
|
||||||
pos = (
|
pos = self.todo_items.index(
|
||||||
self.todo_items.index(
|
next(item for item in self.todo_items if item.uid == previous_uid)
|
||||||
next(item for item in self.todo_items if item.uid == previous_uid)
|
|
||||||
)
|
|
||||||
+ 1
|
|
||||||
)
|
)
|
||||||
|
if pos < self.todo_items.index(
|
||||||
|
next(item for item in self.todo_items if item.uid == uid)
|
||||||
|
):
|
||||||
|
pos += 1
|
||||||
else:
|
else:
|
||||||
pos = 0
|
pos = 0
|
||||||
|
|
||||||
|
@ -601,17 +601,19 @@ async def test_delete_completed_todo_items_exception(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("entity_id", "uid", "previous_uid"),
|
("entity_id", "uid", "second_pos", "third_pos"),
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
"todo.test_user_to_do_s",
|
"todo.test_user_to_do_s",
|
||||||
"1aa3137e-ef72-4d1f-91ee-41933602f438",
|
"1aa3137e-ef72-4d1f-91ee-41933602f438",
|
||||||
"88de7cd9-af2b-49ce-9afd-bf941d87336b",
|
"88de7cd9-af2b-49ce-9afd-bf941d87336b",
|
||||||
|
"2f6fcabc-f670-4ec3-ba65-817e8deea490",
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"todo.test_user_dailies",
|
"todo.test_user_dailies",
|
||||||
"2c6d136c-a1c3-4bef-b7c4-fa980784b1e1",
|
"2c6d136c-a1c3-4bef-b7c4-fa980784b1e1",
|
||||||
"564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
|
"564b9ac9-c53d-4638-9e7f-1cd96fe19baa",
|
||||||
|
"f2c85972-1a19-4426-bc6d-ce3337b9d99f",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
ids=["todo", "daily"],
|
ids=["todo", "daily"],
|
||||||
@ -623,7 +625,8 @@ async def test_move_todo_item(
|
|||||||
hass_ws_client: WebSocketGenerator,
|
hass_ws_client: WebSocketGenerator,
|
||||||
entity_id: str,
|
entity_id: str,
|
||||||
uid: str,
|
uid: str,
|
||||||
previous_uid: str,
|
second_pos: str,
|
||||||
|
third_pos: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test move todo items."""
|
"""Test move todo items."""
|
||||||
|
|
||||||
@ -634,13 +637,13 @@ async def test_move_todo_item(
|
|||||||
assert config_entry.state is ConfigEntryState.LOADED
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
client = await hass_ws_client()
|
client = await hass_ws_client()
|
||||||
# move to second position
|
# move up to second position
|
||||||
data = {
|
data = {
|
||||||
"id": id,
|
"id": id,
|
||||||
"type": "todo/item/move",
|
"type": "todo/item/move",
|
||||||
"entity_id": entity_id,
|
"entity_id": entity_id,
|
||||||
"uid": uid,
|
"uid": uid,
|
||||||
"previous_uid": previous_uid,
|
"previous_uid": second_pos,
|
||||||
}
|
}
|
||||||
await client.send_json_auto_id(data)
|
await client.send_json_auto_id(data)
|
||||||
resp = await client.receive_json()
|
resp = await client.receive_json()
|
||||||
@ -649,6 +652,21 @@ async def test_move_todo_item(
|
|||||||
habitica.reorder_task.assert_awaited_once_with(UUID(uid), 1)
|
habitica.reorder_task.assert_awaited_once_with(UUID(uid), 1)
|
||||||
habitica.reorder_task.reset_mock()
|
habitica.reorder_task.reset_mock()
|
||||||
|
|
||||||
|
# move down to third position
|
||||||
|
data = {
|
||||||
|
"id": id,
|
||||||
|
"type": "todo/item/move",
|
||||||
|
"entity_id": entity_id,
|
||||||
|
"uid": uid,
|
||||||
|
"previous_uid": third_pos,
|
||||||
|
}
|
||||||
|
await client.send_json_auto_id(data)
|
||||||
|
resp = await client.receive_json()
|
||||||
|
assert resp.get("success")
|
||||||
|
|
||||||
|
habitica.reorder_task.assert_awaited_once_with(UUID(uid), 2)
|
||||||
|
habitica.reorder_task.reset_mock()
|
||||||
|
|
||||||
# move to top position
|
# move to top position
|
||||||
data = {
|
data = {
|
||||||
"id": id,
|
"id": id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user