|
7 | 7 | from zulipterminal.config.keys import keys_for_command |
8 | 8 | from zulipterminal.ui_tools.buttons import ( |
9 | 9 | MessageLinkButton, |
| 10 | + SpoilerButton, |
10 | 11 | StarredButton, |
11 | 12 | StreamButton, |
12 | 13 | TopButton, |
@@ -414,6 +415,66 @@ def test_keypress_EXIT_TOGGLE_TOPIC(self, mocker, topic_button, key, widget_size |
414 | 415 | topic_button.view.left_panel.show_stream_view.assert_called_once_with() |
415 | 416 |
|
416 | 417 |
|
| 418 | +class TestSpoilerButton: |
| 419 | + @pytest.fixture(autouse=True) |
| 420 | + def mock_external_classes(self, mocker): |
| 421 | + self.controller = mocker.Mock() |
| 422 | + self.super_init = mocker.patch(BUTTONS + ".urwid.Button.__init__") |
| 423 | + self.connect_signal = mocker.patch(BUTTONS + ".urwid.connect_signal") |
| 424 | + |
| 425 | + def spoiler_button( |
| 426 | + self, header_len=0, header=[""], content=[""], display_attr=None |
| 427 | + ): |
| 428 | + self.content = content |
| 429 | + self.header_len = header_len |
| 430 | + self.header = header |
| 431 | + self.display_attr = display_attr |
| 432 | + return SpoilerButton(self.controller, header_len, header, content, display_attr) |
| 433 | + |
| 434 | + def test_init(self, mocker): |
| 435 | + self.update_widget = mocker.patch(BUTTONS + ".SpoilerButton.update_widget") |
| 436 | + |
| 437 | + mocked_button = self.spoiler_button() |
| 438 | + |
| 439 | + assert mocked_button.controller == self.controller |
| 440 | + assert mocked_button.content == self.content |
| 441 | + self.super_init.assert_called_once_with("") |
| 442 | + self.update_widget.assert_called_once_with( |
| 443 | + self.header_len, self.header, self.display_attr |
| 444 | + ) |
| 445 | + assert self.connect_signal.called |
| 446 | + |
| 447 | + @pytest.mark.parametrize( |
| 448 | + "header, header_len, expected_cursor_position", |
| 449 | + [ |
| 450 | + (["Test"], 4, 5), |
| 451 | + (["Check"], 5, 6), |
| 452 | + ], |
| 453 | + ) |
| 454 | + def test_update_widget( |
| 455 | + self, mocker, header, header_len, expected_cursor_position, display_attr=None |
| 456 | + ): |
| 457 | + self.selectable_icon = mocker.patch(BUTTONS + ".urwid.SelectableIcon") |
| 458 | + |
| 459 | + # The method update_widget() is called in SpoilerButton's init. |
| 460 | + mocked_button = self.spoiler_button( |
| 461 | + header=header, header_len=header_len, display_attr=display_attr |
| 462 | + ) |
| 463 | + self.selectable_icon.assert_called_once_with( |
| 464 | + header, cursor_position=expected_cursor_position |
| 465 | + ) |
| 466 | + assert isinstance(mocked_button._w, AttrMap) |
| 467 | + |
| 468 | + def test_show_spoiler(self, mocker): |
| 469 | + mocked_button = self.spoiler_button() |
| 470 | + |
| 471 | + mocked_button.show_spoiler() |
| 472 | + |
| 473 | + mocked_button.controller.show_spoiler.assert_called_once_with( |
| 474 | + mocked_button.content |
| 475 | + ) |
| 476 | + |
| 477 | + |
417 | 478 | class TestMessageLinkButton: |
418 | 479 | @pytest.fixture(autouse=True) |
419 | 480 | def mock_external_classes(self, mocker): |
|
0 commit comments