mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-18 21:15:16 +02:00
test format_title helper
This commit is contained in:
parent
6d1879ffcb
commit
e195fb77c5
1 changed files with 20 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
|
||||
import pytest
|
||||
|
||||
from app.notifications.service.messages.text import truncate
|
||||
from app.notifications.service.messages.text import format_title, truncate
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
|
|
@ -22,3 +22,22 @@ def test_truncate_keeps_text_at_exact_limit():
|
|||
def test_truncate_appends_ellipsis_when_over_limit():
|
||||
"""Text past the limit is cut to the limit and gains an ellipsis."""
|
||||
assert truncate("a" * 41, 40) == "a" * 40 + "..."
|
||||
|
||||
|
||||
def test_format_title_keeps_short_name():
|
||||
"""Short names are joined to the prefix without truncation."""
|
||||
assert format_title("Ready: ", "report.pdf") == "Ready: report.pdf"
|
||||
|
||||
|
||||
def test_format_title_truncates_long_name():
|
||||
"""Long names are truncated so the full title fits the DB limit."""
|
||||
long_name = "a" * 250
|
||||
title = format_title("Processing: ", long_name)
|
||||
assert len(title) == 200
|
||||
assert title.startswith("Processing: ")
|
||||
assert title.endswith("...")
|
||||
|
||||
|
||||
def test_format_title_respects_custom_max_length():
|
||||
"""A custom max length caps the title."""
|
||||
assert len(format_title("Go: ", "hello world", max_length=10)) == 10
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue