Start writing tab tests, and figure out how to test the modal dialogs

This commit is contained in:
Micah Lee 2019-11-07 13:25:47 +08:00
parent 1787adabc7
commit 6d75468aaa
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 27 additions and 27 deletions

View File

@ -142,6 +142,19 @@ class Tab(QtWidgets.QWidget):
) )
self.persistent_image_label.setFixedSize(20, 20) self.persistent_image_label.setFixedSize(20, 20)
# Create the close warning dialog -- the dialog widget needs to be in the constructor
# in order to test it
self.close_dialog = QtWidgets.QMessageBox()
self.close_dialog.setWindowTitle(strings._("gui_close_tab_warning_title"))
self.close_dialog.setIcon(QtWidgets.QMessageBox.Critical)
self.close_dialog.accept_button = self.close_dialog.addButton(
strings._("gui_close_tab_warning_close"), QtWidgets.QMessageBox.AcceptRole
)
self.close_dialog.reject_button = self.close_dialog.addButton(
strings._("gui_close_tab_warning_cancel"), QtWidgets.QMessageBox.RejectRole
)
self.close_dialog.setDefaultButton(self.close_dialog.reject_button)
def init(self, mode_settings=None): def init(self, mode_settings=None):
if mode_settings: if mode_settings:
# Load this tab # Load this tab
@ -538,21 +551,11 @@ class Tab(QtWidgets.QWidget):
# Open the warning dialog # Open the warning dialog
self.common.log("Tab", "close_tab, opening warning dialog") self.common.log("Tab", "close_tab, opening warning dialog")
dialog = QtWidgets.QMessageBox() self.close_dialog.setText(dialog_text)
dialog.setWindowTitle(strings._("gui_close_tab_warning_title")) self.close_dialog.exec_()
dialog.setText(dialog_text)
dialog.setIcon(QtWidgets.QMessageBox.Critical)
dialog.addButton(
strings._("gui_close_tab_warning_close"), QtWidgets.QMessageBox.YesRole
)
cancel_button = dialog.addButton(
strings._("gui_close_tab_warning_cancel"), QtWidgets.QMessageBox.NoRole
)
dialog.setDefaultButton(cancel_button)
reply = dialog.exec_()
# Close # Close
if reply == 0: if self.close_dialog.clickedButton() == self.close_dialog.accept_button:
self.common.log("Tab", "close_tab", "close, closing tab") self.common.log("Tab", "close_tab", "close, closing tab")
self.get_mode().stop_server() self.get_mode().stop_server()
self.app.cleanup() self.app.cleanup()

View File

@ -166,8 +166,6 @@ class TestTabs(unittest.TestCase):
@pytest.mark.gui @pytest.mark.gui
def test_010_close_share_tab_while_server_started_should_warn(self): def test_010_close_share_tab_while_server_started_should_warn(self):
"""Closing a share mode tab when the server is running should throw a warning""" """Closing a share mode tab when the server is running should throw a warning"""
pass
"""
tab = self.gui.tabs.widget(0) tab = self.gui.tabs.widget(0)
# Share files # Share files
@ -197,34 +195,33 @@ class TestTabs(unittest.TestCase):
tab.share_mode.server_status.STATUS_STARTED, tab.share_mode.server_status.STATUS_STARTED,
) )
# Prepare to reject the dialog
QtCore.QTimer.singleShot(1000, tab.close_dialog.reject_button.click)
# Close tab # Close tab
QtTest.QTest.mouseClick( QtTest.QTest.mouseClick(
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide), self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide),
QtCore.Qt.LeftButton, QtCore.Qt.LeftButton,
) )
QtTest.QTest.qWait(1000)
# The active window should now be a dialog # The tab should still be open
dialog = self.gui.qtapp.activeWindow()
self.assertEqual(type(dialog), QtWidgets.QMessageBox)
# Reject it -- the share mode tab should still be open
dialog.reject()
self.assertFalse(tab.new_tab.isVisible()) self.assertFalse(tab.new_tab.isVisible())
self.assertTrue(tab.share_mode.isVisible()) self.assertTrue(tab.share_mode.isVisible())
# Prepare to accept the dialog
QtCore.QTimer.singleShot(1000, tab.close_dialog.accept_button.click)
# Close tab # Close tab
QtTest.QTest.mouseClick( QtTest.QTest.mouseClick(
self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide), self.gui.tabs.tabBar().tabButton(0, QtWidgets.QTabBar.RightSide),
QtCore.Qt.LeftButton, QtCore.Qt.LeftButton,
) )
QtTest.QTest.qWait(1000)
# This time accept it -- the share mode tab should be closed # The tab should be closed
dialog = self.gui.qtapp.activeWindow() # QtTest.QTest.qWait(5000)
self.assertEqual(type(dialog), QtWidgets.QMessageBox)
dialog.accept()
self.assertTrue(self.gui.tabs.widget(0).new_tab.isVisible()) self.assertTrue(self.gui.tabs.widget(0).new_tab.isVisible())
"""
if __name__ == "__main__": if __name__ == "__main__":