From bd33b28d2df757bf02b0101c718a07ee6d8e5e06 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 6 Oct 2020 20:34:12 +0200 Subject: [PATCH] Fix dialog test method and make appropriate changes to the project load tool --- nw/gui/projload.py | 24 ++++++++++++++++++------ tests/test_dialogs.py | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/nw/gui/projload.py b/nw/gui/projload.py index 38356093..8f18f7bb 100644 --- a/nw/gui/projload.py +++ b/nw/gui/projload.py @@ -125,7 +125,7 @@ class GuiProjectLoad(QDialog): self.buttonBox = QDialogButtonBox(QDialogButtonBox.Open | QDialogButtonBox.Cancel) self.buttonBox.accepted.connect(self._doOpenRecent) - self.buttonBox.rejected.connect(self._doClose) + self.buttonBox.rejected.connect(self._doCancel) self.newButton = self.buttonBox.addButton("New", QDialogButtonBox.ActionRole) self.newButton.clicked.connect(self._doNewProject) @@ -153,7 +153,7 @@ class GuiProjectLoad(QDialog): """Close the dialog window with a recent project selected. """ logger.verbose("GuiProjectLoad open button clicked") - self._saveDialogState() + self._saveSettings() selItems = self.listBox.selectedItems() if selItems: @@ -194,11 +194,12 @@ class GuiProjectLoad(QDialog): return - def _doClose(self): + def _doCancel(self): """Close the dialog window without doing anything. """ logger.verbose("GuiProjectLoad close button clicked") - self._saveDialogState() + self.openPath = None + self.openState = self.NONE_STATE self.close() return @@ -206,7 +207,7 @@ class GuiProjectLoad(QDialog): """Create a new project. """ logger.verbose("GuiProjectLoad new project button clicked") - self._saveDialogState() + self._saveSettings() self.openPath = None self.openState = self.NEW_STATE self.accept() @@ -230,11 +231,22 @@ class GuiProjectLoad(QDialog): return + ## + # Events + ## + + def closeEvent(self, theEvent): + """Capture the user closing the dialog so we can save settings. + """ + self._saveSettings() + theEvent.accept() + return + ## # Internal Functions ## - def _saveDialogState(self): + def _saveSettings(self): """Save the changes made to the dialog. """ colWidths = [0, 0, 0] diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py index 93a5f43f..6fe0f2e4 100644 --- a/tests/test_dialogs.py +++ b/tests/test_dialogs.py @@ -114,7 +114,12 @@ def testProjectSettings(qtbot, monkeypatch, yesToAll, nwFuncTemp, nwTempGUI, nwR projEdit._doSave() # Open again, and check project settings - projEdit = GuiProjectSettings(nwGUI, nwGUI.theProject) + nwGUI.mainMenu.aProjectSettings.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiProjectSettings") is not None, timeout=1000) + + projEdit = getGuiItem("GuiProjectSettings") + assert isinstance(projEdit, GuiProjectSettings) + qtbot.addWidget(projEdit) assert projEdit.tabMain.editName.text() == "Project Name" assert projEdit.tabMain.editTitle.text() == "Project Title" @@ -582,8 +587,13 @@ def testBuildTool(qtbot, yesToAll, nwTempBuild, nwLipsum, nwRef, nwTemp): nwBuild._doClose() # Re-open build dialog from cahce - nwBuild = GuiBuildNovel(nwGUI, nwGUI.theProject) + nwGUI.mainMenu.aBuildProject.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiBuildNovel") is not None, timeout=1000) + nwBuild = getGuiItem("GuiBuildNovel") + assert isinstance(nwBuild, GuiBuildNovel) + + assert nwBuild.viewCachedDoc() assert nwBuild.htmlText == htmlText assert nwBuild.htmlStyle == htmlStyle assert nwBuild.nwdText == nwdText @@ -659,7 +669,11 @@ def testMergeSplitTools(qtbot, monkeypatch, yesToAll, nwTempGUI, nwLipsum, nwRef # Split By Scene assert nwGUI.treeView.setSelectedHandle("73475cb40a568") qtbot.wait(stepDelay) - nwSplit = GuiDocSplit(nwGUI, nwGUI.theProject) + nwGUI.mainMenu.aSplitDoc.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiDocSplit") is not None, timeout=1000) + + nwSplit = getGuiItem("GuiDocSplit") + assert isinstance(nwSplit, GuiDocSplit) qtbot.wait(stepDelay) nwSplit.splitLevel.setCurrentIndex(2) qtbot.wait(stepDelay) @@ -691,7 +705,11 @@ def testMergeSplitTools(qtbot, monkeypatch, yesToAll, nwTempGUI, nwLipsum, nwRef # Split By Section assert nwGUI.treeView.setSelectedHandle("73475cb40a568") qtbot.wait(stepDelay) - nwSplit = GuiDocSplit(nwGUI, nwGUI.theProject) + nwGUI.mainMenu.aSplitDoc.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiDocSplit") is not None, timeout=1000) + + nwSplit = getGuiItem("GuiDocSplit") + assert isinstance(nwSplit, GuiDocSplit) qtbot.wait(stepDelay) nwSplit.splitLevel.setCurrentIndex(3) qtbot.wait(stepDelay) @@ -945,6 +963,7 @@ def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): assert nwGUI.openProject(nwMinimal) assert nwGUI.closeProject() + qtbot.wait(stepDelay) monkeypatch.setattr(GuiProjectLoad, "exec_", lambda *args: None) monkeypatch.setattr(GuiProjectLoad, "result", lambda *args: QDialog.Accepted) nwGUI.mainMenu.aOpenProject.activate(QAction.Trigger) @@ -954,36 +973,50 @@ def testLoadProject(qtbot, monkeypatch, yesToAll, nwMinimal, nwTemp): assert isinstance(nwLoad, GuiProjectLoad) nwLoad.show() + qtbot.wait(stepDelay) recentCount = nwLoad.listBox.topLevelItemCount() assert recentCount > 0 + qtbot.wait(stepDelay) selItem = nwLoad.listBox.topLevelItem(0) selPath = selItem.data(nwLoad.C_NAME, Qt.UserRole) assert isinstance(selItem, QTreeWidgetItem) + qtbot.wait(stepDelay) nwLoad.selPath.setText("") nwLoad.listBox.setCurrentItem(selItem) nwLoad._doSelectRecent() assert nwLoad.selPath.text() == selPath + qtbot.wait(stepDelay) qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Open), Qt.LeftButton) assert nwLoad.openPath == selPath assert nwLoad.openState == nwLoad.OPEN_STATE # Just create a new project load from scratch for the rest of the test del nwLoad - nwLoad = GuiProjectLoad(nwGUI) + + qtbot.wait(stepDelay) + nwGUI.mainMenu.aOpenProject.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiProjectLoad") is not None, timeout=1000) + + qtbot.wait(stepDelay) + nwLoad = getGuiItem("GuiProjectLoad") + assert isinstance(nwLoad, GuiProjectLoad) nwLoad.show() + qtbot.wait(stepDelay) qtbot.mouseClick(nwLoad.buttonBox.button(QDialogButtonBox.Cancel), Qt.LeftButton) assert nwLoad.openPath is None assert nwLoad.openState == nwLoad.NONE_STATE + qtbot.wait(stepDelay) nwLoad.show() qtbot.mouseClick(nwLoad.newButton, Qt.LeftButton) assert nwLoad.openPath is None assert nwLoad.openState == nwLoad.NEW_STATE + qtbot.wait(stepDelay) nwLoad.show() nwLoad._keyPressDelete() assert nwLoad.listBox.topLevelItemCount() == recentCount - 1