When dismissing a message, it should be removed from the list and the tree view.

This commit is contained in:
2026-04-06 23:53:46 -04:00
parent 667c0babcb
commit e72cc79c6a
2 changed files with 195 additions and 0 deletions
@@ -81,6 +81,41 @@ class _FakeLabel:
self.visible = value
class _FakeListStore:
def __init__(self, rows=None):
self.rows = list(rows or [])
def iter_n_children(self, _parent):
return len(self.rows)
def get_iter(self, path):
index = path if isinstance(path, int) else path[0]
if 0 <= index < len(self.rows):
return index
return None
def get_value(self, row_iter, column):
return self.rows[row_iter][column]
def remove(self, row_iter):
del self.rows[row_iter]
return row_iter < len(self.rows)
class _FakeSelection:
def __init__(self, model=None, selected_path=0):
self.model = model
self.selected_path = selected_path
def get_selected_rows(self):
if self.selected_path is None:
return self.model, []
return self.model, [self.selected_path]
def select_path(self, path):
self.selected_path = path
class NotificationPresenterMakoTests(unittest.TestCase):
def setUp(self):
self.presenter = NotificationPresenter()
@@ -163,13 +198,104 @@ class NotificationPresenterMakoTests(unittest.TestCase):
self.assertTrue(self.presenter.dismiss_entry(script, entry))
self.assertEqual(self.monitor.dismissed, [6])
self.assertEqual(self.presenter._notifications, [])
script.presentMessage.assert_called_with(messages.NOTIFICATION_DISMISSED)
script.reset_mock()
entry = self.presenter.save_notification(
"Notification current",
source="mako",
source_generation=2,
notification_id=6,
live=True,
actions={"default": "View"},
)
self.assertTrue(self.presenter.invoke_action_for_entry(script, entry, "default"))
self.assertEqual(self.monitor.invoked, [(6, "default")])
script.presentMessage.assert_called_with(messages.NOTIFICATION_ACTION_INVOKED)
def test_notification_list_dismiss_removes_selected_entry_from_history_and_model(self):
entry = self.presenter.save_notification(
"Notification current",
source="mako",
source_generation=2,
notification_id=6,
live=True,
actions={"default": "View"},
)
remaining = self.presenter.save_notification(
"Notification stale",
source="mako",
source_generation=1,
notification_id=7,
live=False,
actions={},
)
gui = notification_presenter.NotificationListGUI.__new__(
notification_presenter.NotificationListGUI
)
gui._script = mock.Mock()
gui._presenter = self.presenter
gui._dismiss_button = _FakeButton()
gui._actions_box = _FakeBox()
gui._actions_status_label = _FakeLabel()
gui._model = _FakeListStore(
[
[entry.message, "now", entry],
[remaining.message, "later", remaining],
]
)
gui._selection = _FakeSelection(model=gui._model, selected_path=0)
gui._update_action_buttons = mock.Mock()
gui._dismiss_selected_notification()
self.assertEqual(self.monitor.dismissed, [6])
self.assertEqual(self.presenter._notifications, [remaining])
self.assertEqual(gui._model.rows, [[remaining.message, "later", remaining]])
gui._script.presentMessage.assert_called_with(messages.NOTIFICATION_DISMISSED)
def test_notification_list_dismiss_reselects_remaining_row_after_removing_last_selection(self):
remaining = self.presenter.save_notification(
"Notification stale",
source="mako",
source_generation=1,
notification_id=7,
live=False,
actions={},
)
entry = self.presenter.save_notification(
"Notification current",
source="mako",
source_generation=2,
notification_id=6,
live=True,
actions={"default": "View"},
)
gui = notification_presenter.NotificationListGUI.__new__(
notification_presenter.NotificationListGUI
)
gui._script = mock.Mock()
gui._presenter = self.presenter
gui._dismiss_button = _FakeButton()
gui._actions_box = _FakeBox()
gui._actions_status_label = _FakeLabel()
gui._model = _FakeListStore(
[
[remaining.message, "later", remaining],
[entry.message, "now", entry],
]
)
gui._selection = _FakeSelection(model=gui._model, selected_path=1)
gui._update_action_buttons = mock.Mock()
gui._dismiss_selected_notification()
self.assertEqual(gui._model.rows, [[remaining.message, "later", remaining]])
self.assertEqual(gui._selection.selected_path, 0)
def test_notification_list_builds_inline_action_buttons_in_reported_order(self):
entry = self.presenter.save_notification(
"Notification current",