Skip to content

Commit

Permalink
fix: Set viewed status of first page in Book when Book is set
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler committed Oct 21, 2024
1 parent 9a2baa6 commit 209a61f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 46 deletions.
18 changes: 12 additions & 6 deletions encyclopaedia/actions_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ def set_entry(self) -> None:
# The active entry is set to whichever list position was found.
self.enc.active = self.entry

if self.enc.active.locked is False and not isinstance(self.entry, Book):
if self.entry.viewed is False:
# Run the callback, if provided.
self.entry.emit("viewed")
# Mark the entry as viewed.
self.enc.active.viewed = True
if self.enc.active.locked is False:
if not isinstance(self.entry, Book):
if self.entry.viewed is False:
# Run the callback, if provided.
self.entry.emit("viewed")
# Mark the entry as viewed.
self.enc.active.viewed = True

# When setting a Book, set the first page to viewed, not the Book.
elif isinstance(self.entry, Book):
self.entry.active.viewed = True
self.entry.active.emit("viewed")

# When sorting by Unread, setting an entry marks is as read.
# Thus we have to resort the entries to ensure they appear in the
Expand Down
40 changes: 0 additions & 40 deletions tests/actions/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,46 +132,6 @@ def test_reset_sub_page():
assert e.current_page == e


def test_set_entry(add_dummy_entries):
"""Test Actions through their implementation in Encyclopaedia."""

enc = Encyclopaedia()

entries = add_dummy_entries(enc, 5)

add_dummy_entries(enc, 5, locked=True)

e = entries[-1]

# Use the last unlocked Entry created for the test.
enc.SetEntry(e)()

assert e == enc.active
assert 4 == enc.current_position


def test_set_entry_sorting_mode_unread(add_dummy_entries):
"""
When the sorting mode is by unread entries,
Then the Encyclopaedia should resort when an entry is set
And the newly read entry is in the correct position
"""

enc = Encyclopaedia(sorting_mode=4)

entries = add_dummy_entries(enc, 5)

e = entries[1]

assert e == enc.current_entries[1]

enc.SetEntry(e)()

assert e == enc.active

# entry should be moved from 2nd position to the last
assert e == enc.current_entries[-1]

def test_filter_by_subject():
"""Test Actions through their implementation in Encyclopaedia."""

Expand Down
57 changes: 57 additions & 0 deletions tests/actions/test_set_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from encyclopaedia import Encyclopaedia
from encyclopaedia import EncEntry
from encyclopaedia.book import Book


def test_set_entry(add_dummy_entries):
"""Test Actions through their implementation in Encyclopaedia."""

enc = Encyclopaedia()

entries = add_dummy_entries(enc, 5)

add_dummy_entries(enc, 5, locked=True)

e = entries[-1]

# Use the last unlocked Entry created for the test.
enc.SetEntry(e)()

assert e == enc.active
assert 4 == enc.current_position


def test_set_entry_sorting_mode_unread(add_dummy_entries):
"""
When the sorting mode is by unread entries,
Then the Encyclopaedia should resort when an entry is set
And the newly read entry is in the correct position
"""

enc = Encyclopaedia(sorting_mode=4)

entries = add_dummy_entries(enc, 5)

e = entries[1]

assert e == enc.current_entries[1]

enc.SetEntry(e)()

assert e == enc.active

# entry should be moved from 2nd position to the last
assert e == enc.current_entries[-1]


def test_set_entry_book_viewed():
enc = Encyclopaedia()

book = Book(parent=enc, title="Greek Gods", subject="Mythology")
EncEntry(parent=book, number=0, name="Zeus")
EncEntry(parent=book, number=1, name="Hades")

enc.SetEntry(book)()

assert book.viewed is False
assert book.active.viewed is True

0 comments on commit 209a61f

Please sign in to comment.