Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
watkins-matt committed Apr 24, 2024
1 parent 6459dfd commit e958f66
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import gkeepapi
import pytest

from custom_components.google_keep_sync.api import GoogleKeepAPI
from custom_components.google_keep_sync.api import GoogleKeepAPI, ListCase

# Constants for testing
TEST_USERNAME = "[email protected]"
Expand Down Expand Up @@ -428,3 +428,54 @@ async def async_dump_state():
mock_store.async_save.assert_called_once_with(
{"token": TEST_TOKEN, "state": TEST_STATE, "username": TEST_USERNAME}
)


async def test_change_list_case(google_keep_api, mock_hass):
"""Test changing the case of list items."""
# Create a list with items
mock_list = MagicMock(spec=gkeepapi.node.List)
mock_list.id = "todo_list_id"
mock_list.title = "Todo List"
mock_item1 = MagicMock(id="milk_item_id", text="Milk", checked=False)
mock_item2 = MagicMock(id="apple_item_id", text="apple", checked=False)
mock_list.items = [mock_item1, mock_item2]

# Check upper case
google_keep_api.change_list_case(mock_list.items, ListCase.UPPER)
assert mock_item1.text == "MILK"
assert mock_item2.text == "APPLE"

# Check lower case
google_keep_api.change_list_case(mock_list.items, ListCase.LOWER)
assert mock_item1.text == "milk"
assert mock_item2.text == "apple"

# Check no change
google_keep_api.change_list_case(mock_list.items, ListCase.NO_CHANGE)
assert mock_item1.text == "milk"
assert mock_item2.text == "apple"

# Check title case
google_keep_api.change_list_case(mock_list.items, ListCase.TITLE)
assert mock_item1.text == "Milk"
assert mock_item2.text == "Apple"

# Check sentence case
google_keep_api.change_list_case(mock_list.items, ListCase.SENTENCE)
assert mock_item1.text == "Milk"
assert mock_item2.text == "Apple"


async def test_change_case(google_keep_api, mock_hass):
"""Test changing the case of individual strings."""
assert google_keep_api.change_case("milk", ListCase.UPPER) == "MILK"
assert google_keep_api.change_case("milk", ListCase.LOWER) == "milk"
assert google_keep_api.change_case("milk", ListCase.NO_CHANGE) == "milk"
assert (
google_keep_api.change_case("chocolate milk", ListCase.TITLE)
== "Chocolate Milk"
)
assert (
google_keep_api.change_case("chocolate milk", ListCase.SENTENCE)
== "Chocolate milk"
)

0 comments on commit e958f66

Please sign in to comment.