Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check for empty excerpts in popups #1086

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions GTG/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# REGEXES
# ------------------------------------------------------------------------------

TAG_REGEX = re.compile(r'^\B\@\w+(\-\w+)*\,*')
TAG_LINE_REGEX = re.compile(r'^\B\@\w+(\-\w+)*\,*.*')
SUB_REGEX = re.compile(r'\{\!.+\!\}')


Expand Down Expand Up @@ -307,16 +307,19 @@ def title(self, value) -> None:

@GObject.Property(type=str)
def excerpt(self) -> str:
if not self.content:
return ''

# Strip tags
txt = TAG_REGEX.sub('', self.content)
txt = TAG_LINE_REGEX.sub('', self.content)

# Strip subtasks
txt = SUB_REGEX.sub('', txt)

return f'{txt.strip()[:80]}…'
# Strip whitespace
txt = txt.strip()

if not txt:
return ''

return f'{txt[:80]}…'


def add_tag(self, tag: Tag) -> None:
Expand Down
34 changes: 33 additions & 1 deletion tests/core/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_title(self):
self.assertEqual(task.title, 'My Title')


def test_excerpt(self):
def test_excerpt_normal(self):
task = Task(id=uuid4(), title='A Task')

self.assertEqual(task.excerpt, '')
Expand All @@ -51,6 +51,38 @@ def test_excerpt(self):
self.assertEqual(task.excerpt, expected)


def test_excerpt_empty_task(self):
task = Task(id=uuid4(), title='A Task')

self.assertEqual(task.excerpt, '')

task.content = ''

self.assertEqual(task.excerpt, '')


def test_excerpt_only_tags(self):
task = Task(id=uuid4(), title='A Task')

self.assertEqual(task.excerpt, '')

task.content = '@sometag, @someother'

self.assertEqual(task.excerpt, '')


def test_excerpt_only_whitespace(self):
task = Task(id=uuid4(), title='A Task')

self.assertEqual(task.excerpt, '')

task.content = (' '
''
' ')

self.assertEqual(task.excerpt, '')


def test_toggle_active_single(self):
task = Task(id=uuid4(), title='A Task')

Expand Down