Skip to content

Commit

Permalink
go back to old replybox
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Apr 10, 2019
1 parent 3f60f19 commit 7e5e2fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
27 changes: 11 additions & 16 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def __init__(self, parent):
self.view_layout = QVBoxLayout()
self.view_layout.setContentsMargins(0, 0, 0, 0)
self.view_holder = QWidget()
self.view_holder.setStyleSheet('background: #efeef7;')
self.view_holder.setStyleSheet('background: #fff;')
self.view_holder.setLayout(self.view_layout)

self.layout.addWidget(self.view_holder, 6)
Expand Down Expand Up @@ -1279,10 +1279,17 @@ def send_reply(self, message: str) -> None:
self.controller.send_reply(self.source.uuid, msg_uuid, message)

def _show_or_hide_replybox(self, show: bool) -> None:
if not show:
self.reply_box.disable()
if show:
new_widget = ReplyBoxWidget(self)
else:
self.reply_box.enable()
new_widget = QLabel(_('You need to log in to send replies.'))

old_widget = self.layout.takeAt(2)
if old_widget is not None:
old_widget.widget().deleteLater()

self.reply_box = new_widget
self.layout.addWidget(new_widget, 3)


class ReplyBoxWidget(QWidget):
Expand All @@ -1292,9 +1299,6 @@ class ReplyBoxWidget(QWidget):

def __init__(self, conversation: SourceConversationWrapper) -> None:
super().__init__()

self.setStyleSheet('background: #fff;')

self.conversation = conversation

self.text_edit = QTextEdit()
Expand Down Expand Up @@ -1322,15 +1326,6 @@ def send_reply(self) -> None:
self.conversation.send_reply(msg)
self.text_edit.clear()

def enable(self):
self.text_edit.setEnabled(True)
self.send_button.show()

def disable(self):
self.text_edit.setText(_('You need to log in to send replies.'))
self.text_edit.setEnabled(False)
self.send_button.hide()


class DeleteSourceAction(QAction):
"""Use this action to delete the source record."""
Expand Down
49 changes: 17 additions & 32 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,32 +1513,6 @@ def test_ReplyWidget_success_failure_slots(mocker):
assert mock_logger.debug.called


def test_ReplyBoxWidget_enable(mocker):
mock_conversation = mocker.Mock()
rw = ReplyBoxWidget(mock_conversation)
rw.text_edit = QTextEdit()
rw.send_button = mocker.MagicMock()

rw.enable()

assert rw.text_edit.isEnabled()
assert rw.text_edit.toPlainText() == ''
rw.send_button.show.assert_called_once_with()


def test_ReplyBoxWidget_disable(mocker):
mock_conversation = mocker.Mock()
rw = ReplyBoxWidget(mock_conversation)
rw.text_edit = QTextEdit()
rw.send_button = mocker.MagicMock()

rw.disable()

assert not rw.text_edit.isEnabled()
assert rw.text_edit.toPlainText() == 'You need to log in to send replies.'
rw.send_button.hide.assert_called_once_with()


def test_update_conversation_maintains_old_items(mocker, homedir, session):
"""
Calling update_conversation deletes and adds old items back to layout
Expand Down Expand Up @@ -1632,11 +1606,22 @@ def test_SourceConversationWrapper_set_widgets_via_auth_value(mocker, homedir):
"""
When the client is authenticated, we should create a ReplyBoxWidget otherwise a warning.
"""
source = mocker.MagicMock()
controller = mocker.MagicMock()
scw = SourceConversationWrapper(source, 'mock home', controller, True)
scw.reply_box = mocker.MagicMock()
mock_source = mocker.Mock(collection=[])
mock_controller = mocker.MagicMock()

mocker.patch('securedrop_client.gui.widgets.LastUpdatedLabel', return_value=QLabel('now'))
cw = SourceConversationWrapper(mock_source, 'mock home', mock_controller, True)
mocker.patch.object(cw, 'layout')
mock_reply_box = mocker.patch('securedrop_client.gui.widgets.ReplyBoxWidget',
return_value=QWidget())
mock_label = mocker.patch('securedrop_client.gui.widgets.QLabel', return_value=QWidget())

cw._show_or_hide_replybox(True)
mock_reply_box.assert_called_once_with(cw)
assert not mock_label.called

scw._show_or_hide_replybox(False)
mock_reply_box.reset_mock()

scw.reply_box.disable.assert_called_once_with()
cw._show_or_hide_replybox(False)
assert not mock_reply_box.called
assert mock_label.called

0 comments on commit 7e5e2fd

Please sign in to comment.