1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-03 04:25:24 +02:00

feat: more shopping list enhancements (#2587)

* fix new position calculataion

* ensure consistent list item ordering

* fix recipe ref overflow on small screens

* added recipe ref elevation

* tweaked line height (for long notes)

* removed unused user dependency

* remove old shopping list items when there's >100

* 🤷

* cleaned up function generator

* fixed test

* fix potential type error

* made max position calc more efficient
This commit is contained in:
Michael Genson 2023-10-07 16:06:00 -05:00 committed by GitHub
parent f35bc77a7d
commit b153ddf858
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 189 additions and 8 deletions

View file

@ -0,0 +1,90 @@
from datetime import datetime
from mealie.repos.repository_factory import AllRepositories
from mealie.schema.group.group_shopping_list import ShoppingListItemCreate, ShoppingListItemOut, ShoppingListSave
from mealie.services.scheduler.tasks.delete_old_checked_shopping_list_items import (
MAX_CHECKED_ITEMS,
delete_old_checked_list_items,
)
from tests.utils.factories import random_int, random_string
from tests.utils.fixture_schemas import TestUser
def test_cleanup(database: AllRepositories, unique_user: TestUser):
list_repo = database.group_shopping_lists.by_group(unique_user.group_id)
list_item_repo = database.group_shopping_list_item
shopping_list = list_repo.create(ShoppingListSave(name=random_string(), group_id=unique_user.group_id))
unchecked_items = list_item_repo.create_many(
[
ShoppingListItemCreate(note=random_string(), shopping_list_id=shopping_list.id)
for _ in range(random_int(MAX_CHECKED_ITEMS + 10, MAX_CHECKED_ITEMS + 20))
]
)
# create them one at a time so the update timestamps are different
checked_items: list[ShoppingListItemOut] = []
for _ in range(random_int(MAX_CHECKED_ITEMS + 10, MAX_CHECKED_ITEMS + 20)):
new_item = list_item_repo.create(
ShoppingListItemCreate(note=random_string(), shopping_list_id=shopping_list.id)
)
new_item.checked = True
checked_items.append(list_item_repo.update(new_item.id, new_item))
# make sure we see all items
shopping_list = list_repo.get_one(shopping_list.id) # type: ignore
assert shopping_list
assert len(shopping_list.list_items) == len(unchecked_items) + len(checked_items)
for item in unchecked_items + checked_items:
assert item in shopping_list.list_items
checked_items.sort(key=lambda x: x.update_at or datetime.now(), reverse=True)
expected_kept_items = unchecked_items + checked_items[:MAX_CHECKED_ITEMS]
expected_deleted_items = checked_items[MAX_CHECKED_ITEMS:]
# make sure we only see the expected items
delete_old_checked_list_items()
shopping_list = list_repo.get_one(shopping_list.id) # type: ignore
assert shopping_list
assert len(shopping_list.list_items) == len(expected_kept_items)
for item in expected_kept_items:
assert item in shopping_list.list_items
for item in expected_deleted_items:
assert item not in shopping_list.list_items
def test_no_cleanup(database: AllRepositories, unique_user: TestUser):
list_repo = database.group_shopping_lists.by_group(unique_user.group_id)
list_item_repo = database.group_shopping_list_item
shopping_list = list_repo.create(ShoppingListSave(name=random_string(), group_id=unique_user.group_id))
unchecked_items = list_item_repo.create_many(
[
ShoppingListItemCreate(note=random_string(), shopping_list_id=shopping_list.id)
for _ in range(MAX_CHECKED_ITEMS)
]
)
# create them one at a time so the update timestamps are different
checked_items: list[ShoppingListItemOut] = []
for _ in range(MAX_CHECKED_ITEMS):
new_item = list_item_repo.create(
ShoppingListItemCreate(note=random_string(), shopping_list_id=shopping_list.id)
)
new_item.checked = True
checked_items.append(list_item_repo.update(new_item.id, new_item))
# make sure we see all items
shopping_list = list_repo.get_one(shopping_list.id) # type: ignore
assert shopping_list
assert len(shopping_list.list_items) == len(unchecked_items) + len(checked_items)
for item in unchecked_items + checked_items:
assert item in shopping_list.list_items
# make sure we still see all items
delete_old_checked_list_items()
shopping_list = list_repo.get_one(shopping_list.id) # type: ignore
assert shopping_list
assert len(shopping_list.list_items) == len(unchecked_items) + len(checked_items)
for item in unchecked_items + checked_items:
assert item in shopping_list.list_items