Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbreu committed Nov 28, 2023
1 parent 3f50c56 commit e5b9658
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion beeref/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ def exit_edit_mode(self, commit=True):
# reset selection:
self.setTextCursor(QtGui.QTextCursor(self.document()))
self.setTextInteractionFlags(Qt.TextInteractionFlag.NoTextInteraction)
self.scene().edit_item = None
if commit:
self.scene().undo_stack.push(
commands.ChangeText(self, self.toPlainText(), self.old_text))
self.scene().edit_item = None
if not self.toPlainText().strip():
logger.debug('Removing empty text item')
self.scene().undo_stack.push(
Expand Down
4 changes: 3 additions & 1 deletion tests/items/test_textitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def test_exit_edit_mode_when_text_empty(view):
assert view.scene.edit_item is None


@patch('PyQt6.QtGui.QTextCursor')
@patch('beeref.items.BeeTextItem.setTextCursor')
def test_exit_edit_mode_when_commit_false(setcursor_mock, cursor_mock, view):
item = BeeTextItem('foo bar')
item.edit_mode = True
Expand All @@ -258,7 +260,7 @@ def test_exit_edit_mode_when_commit_false(setcursor_mock, cursor_mock, view):
cursor_mock.assert_called_once_with(item.document())
setcursor_mock.assert_called_once_with(cursor_mock.return_value)
assert view.scene.edit_item is None
assert item.toPlaintText() == 'old'
assert item.toPlainText() == 'old'


@patch('PyQt6.QtWidgets.QGraphicsTextItem.keyPressEvent')
Expand Down

0 comments on commit e5b9658

Please sign in to comment.