Skip to content

Commit

Permalink
make reply message italic when error
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier authored and sssoleileraaa committed Sep 30, 2020
1 parent 02918ec commit 7318a35
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 95 deletions.
29 changes: 13 additions & 16 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ def __init__(
self.message.setContextMenuPolicy(Qt.NoContextMenu)

if error:
self.set_error_styles()
self.set_failed_to_decrypt_styles()

self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

Expand All @@ -1733,7 +1733,7 @@ def set_error(self, source_uuid: str, uuid: str, text: str):
"""
if uuid == self.uuid:
self.message.setText(text)
self.set_error_styles()
self.set_failed_to_decrypt_styles()

def set_normal_styles(self):
self.message.setStyleSheet("")
Expand All @@ -1743,7 +1743,7 @@ def set_normal_styles(self):
self.color_bar.setObjectName("SpeechBubble_status_bar")
self.color_bar.setStyleSheet(self.STATUS_BAR_CSS)

def set_error_styles(self):
def set_failed_to_decrypt_styles(self):
self.message.setStyleSheet("")
self.message.setObjectName("SpeechBubble_message_decryption_error")
self.message.setStyleSheet(self.MESSAGE_CSS)
Expand Down Expand Up @@ -1774,8 +1774,8 @@ class ReplyWidget(SpeechBubble):
Represents a reply to a source.
"""

MESSAGE_CSS = load_css("reply_message.css")
STATUS_BAR_CSS = load_css("reply_status_bar.css")
MESSAGE_CSS = load_css("speech_bubble_message.css")
STATUS_BAR_CSS = load_css("speech_bubble_status_bar.css")

def __init__(
self,
Expand Down Expand Up @@ -1810,18 +1810,13 @@ def __init__(
message_succeeded_signal.connect(self._on_reply_success)
message_failed_signal.connect(self._on_reply_failure)

self._set_reply_state(reply_status)

def _set_reply_state(self, status: str) -> None:
logger.debug(f"Setting ReplyWidget state: {status}")

if status == "SUCCEEDED":
if reply_status == "SUCCEEDED":
self.set_normal_styles()
self.error.hide()
elif status == "FAILED":
elif reply_status == "FAILED":
self.set_failed_styles()
self.error.show()
elif status == "PENDING":
elif reply_status == "PENDING":
self.set_pending_styles()

@pyqtSlot(str, str, str)
Expand All @@ -1831,7 +1826,8 @@ def _on_reply_success(self, source_id: str, message_uuid: str, content: str) ->
signal matches the uuid of this widget.
"""
if message_uuid == self.uuid:
self._set_reply_state("SUCCEEDED")
self.set_normal_styles()
self.error.hide()

@pyqtSlot(str)
def _on_reply_failure(self, message_uuid: str) -> None:
Expand All @@ -1840,11 +1836,12 @@ def _on_reply_failure(self, message_uuid: str) -> None:
signal matches the uuid of this widget.
"""
if message_uuid == self.uuid:
self._set_reply_state("FAILED")
self.set_failed_styles()
self.error.show()

def set_normal_styles(self):
self.message.setStyleSheet("")
self.message.setObjectName("ReplyWidget_message")
self.message.setObjectName("SpeechBubble_message")
self.message.setStyleSheet(self.MESSAGE_CSS)
self.color_bar.setStyleSheet("")
self.color_bar.setObjectName("ReplyWidget_status_bar")
Expand Down
26 changes: 0 additions & 26 deletions securedrop_client/resources/css/reply_message.css

This file was deleted.

20 changes: 0 additions & 20 deletions securedrop_client/resources/css/reply_status_bar.css

This file was deleted.

28 changes: 28 additions & 0 deletions securedrop_client/resources/css/speech_bubble_message.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@
padding: 16px;
}

#ReplyWidget_message_pending {
font-family: 'Source Sans Pro';
font-weight: 400;
font-size: 15px;
color: #a9aaad;
background-color: #f7f8fc;
padding: 16px;
}

#ReplyWidget_message_failed {
font-family: 'Source Sans Pro';
font-weight: 400;
font-size: 15px;
background-color: #fff;
color: #3b3b3b;
padding: 16px;
}

#ReplyWidget_message_decryption_error {
font-family: 'Source Sans Pro';
font-weight: 400;
font-size: 15px;
font-style: italic;
background-color: rgba(255, 255, 255, 0.6);
color: #3b3b3b;
padding: 16px;
}

#SpeechBubble_message_decryption_error {
font-family: 'Source Sans Pro';
font-weight: 400;
Expand Down
21 changes: 21 additions & 0 deletions securedrop_client/resources/css/speech_bubble_status_bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@
max-height: 5px;
background-color: #bcbfcd;
border: 0px;
}

#ReplyWidget_status_bar {
min-height: 5px;
max-height: 5px;
background-color: #0065db;
border: 0px;
}

#ReplyWidget_status_bar_pending {
min-height: 5px;
max-height: 5px;
background-color: #0065db;
border: 0px;
}

#ReplyWidget_status_bar_failed {
min-height: 5px;
max-height: 5px;
background-color: #ff3366;
border: 0px;
}
78 changes: 76 additions & 2 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,23 @@ def test_MessageWidget_init(mocker):
assert mock_connected.called


def test_MessageWidget_set_failed_to_decrypt_styles(mocker):
"""
Check the CSS is set as expected when error=True.
"""
message_widget = MessageWidget("mock", "mock", mocker.MagicMock(), mocker.MagicMock(), 0, True)

message_widget.message = mocker.patch.object(message_widget, "message")
message_widget.color_bar = mocker.patch.object(message_widget, "color_bar")

message_widget.set_failed_to_decrypt_styles()

message_widget.message.setObjectName.assert_called_with("SpeechBubble_message_decryption_error")
message_widget.color_bar.setObjectName.assert_called_with(
"SpeechBubble_status_bar_decryption_error"
)


def test_ReplyWidget_init(mocker):
"""
Check the CSS is set as expected.
Expand Down Expand Up @@ -2198,7 +2215,7 @@ def test_ReplyWidget_init(mocker):
assert mock_failure_connected.called


def test_ReplyWidget_init_with_error(mocker):
def test_ReplyWidget_init_with_failed_to_send_error(mocker):
"""
Check the CSS is set as expected when error=True.
"""
Expand Down Expand Up @@ -2227,14 +2244,71 @@ def test_ReplyWidget_init_with_error(mocker):
mock_success_signal,
mock_failure_signal,
0,
error=True,
error=False,
)

assert mock_update_connected.called
assert mock_success_connected.called
assert mock_failure_connected.called


def test_ReplyWidget_init_with_failed_to_decrypt_error(mocker):
"""
Check the CSS is set as expected when error=True.
"""
mock_download_failure_signal = mocker.MagicMock()
mock_download_failure_connected = mocker.Mock()
mock_download_failure_signal.connect = mock_download_failure_connected

set_failed_to_decrypt_styles = mocker.patch(
"securedrop_client.gui.widgets.SpeechBubble.set_failed_to_decrypt_styles"
)

ReplyWidget(
"mock id",
"hello",
"dummy",
mocker.MagicMock(),
mock_download_failure_signal,
mocker.MagicMock(),
mocker.MagicMock(),
0,
error=True,
)

set_failed_to_decrypt_styles.assert_called_once_with()


def test_ReplyWidget_set_failed_to_decrypt_styles(mocker):
"""
Check the CSS is set as expected when error=True.
"""
mock_download_failure_signal = mocker.MagicMock()
mock_download_failure_connected = mocker.Mock()
mock_download_failure_signal.connect = mock_download_failure_connected
reply_widget = ReplyWidget(
"mock id",
"hello",
"dummy",
mocker.MagicMock(),
mock_download_failure_signal,
mocker.MagicMock(),
mocker.MagicMock(),
0,
error=True,
)

reply_widget.message = mocker.patch.object(reply_widget, "message")
reply_widget.color_bar = mocker.patch.object(reply_widget, "color_bar")

reply_widget.set_failed_to_decrypt_styles()

reply_widget.message.setObjectName.assert_called_with("SpeechBubble_message_decryption_error")
reply_widget.color_bar.setObjectName.assert_called_with(
"SpeechBubble_status_bar_decryption_error"
)


def test_FileWidget_init_file_not_downloaded(mocker, source, session):
"""
Check the FileWidget is configured correctly when the file is not downloaded.
Expand Down
29 changes: 0 additions & 29 deletions tests/integration/test_styles_reply_message.py

This file was deleted.

11 changes: 9 additions & 2 deletions tests/integration/test_styles_reply_status_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ def test_styles(mocker, main_window):
assert "#0065db" == reply_widget.color_bar.palette().color(QPalette.Background).name()
# assert border: 0px;

reply_widget._set_reply_state("PENDING")
reply_widget.set_pending_styles()

assert 5 == reply_widget.color_bar.minimumSize().height()
assert 5 == reply_widget.color_bar.maximumSize().height()
assert "#0065db" == reply_widget.color_bar.palette().color(QPalette.Background).name()
# assert border: 0px;

reply_widget._set_reply_state("FAILED")
reply_widget.set_failed_styles()

assert 5 == reply_widget.color_bar.minimumSize().height()
assert 5 == reply_widget.color_bar.maximumSize().height()
assert "#ff3366" == reply_widget.color_bar.palette().color(QPalette.Background).name()
# assert border: 0px;

reply_widget.set_error("123", reply_widget.uuid, reply_widget.message.text())

assert 5 == reply_widget.color_bar.minimumSize().height()
assert 5 == reply_widget.color_bar.maximumSize().height()
assert "#bcbfcd" == reply_widget.color_bar.palette().color(QPalette.Background).name()
# assert border: 0px;

0 comments on commit 7318a35

Please sign in to comment.