From 8859fc7b6b73a305e8489b8df71f14d8db923455 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 3 Mar 2024 16:31:02 +0100 Subject: [PATCH] Improve test coverage --- tests/test_core/test_core_tree.py | 3 +++ tests/test_gui/test_gui_doceditor.py | 35 ++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index 8cd9ad95..9e6e146e 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -421,6 +421,9 @@ def testCoreTree_Methods(monkeypatch, mockGUI, mockItems): assert tree.getItemPath("c000000000001") == [ "c000000000001", "b000000000001", "a000000000001" ] + assert tree.getItemPath("c000000000001", asName=True) == [ + "Chapter One", "Act One", "Novel" + ] # Cause recursion error with monkeypatch.context() as mp: diff --git a/tests/test_gui/test_gui_doceditor.py b/tests/test_gui/test_gui_doceditor.py index 1cffea70..e5a79d21 100644 --- a/tests/test_gui/test_gui_doceditor.py +++ b/tests/test_gui/test_gui_doceditor.py @@ -55,6 +55,9 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd): assert nwGUI.docEditor.verticalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert nwGUI.docEditor.horizontalScrollBarPolicy() == Qt.ScrollBarAsNeeded assert nwGUI.docEditor._typPadChar == nwUnicode.U_NBSP + assert nwGUI.docEditor.docHeader.itemTitle.text() == ( + "Novel \u203a New Chapter \u203a New Scene" + ) # Check that editor handles settings CONFIG.textFont = "" @@ -64,6 +67,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd): CONFIG.hideVScroll = True CONFIG.hideHScroll = True CONFIG.fmtPadThin = True + CONFIG.showFullPath = False nwGUI.docEditor.initEditor() @@ -75,6 +79,29 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd): assert nwGUI.docEditor.verticalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert nwGUI.docEditor.horizontalScrollBarPolicy() == Qt.ScrollBarAlwaysOff assert nwGUI.docEditor._typPadChar == nwUnicode.U_THNBSP + assert nwGUI.docEditor.docHeader.itemTitle.text() == "New Scene" + + # Header + # ====== + + # Select item from header + with qtbot.waitSignal(nwGUI.docEditor.requestProjectItemSelected, timeout=1000) as signal: + qtbot.mouseClick(nwGUI.docEditor.docHeader, Qt.MouseButton.LeftButton) + assert signal.args == [nwGUI.docEditor.docHeader._docHandle, True] + + # Close from header + with qtbot.waitSignal(nwGUI.docEditor.docHeader.closeDocumentRequest, timeout=1000): + nwGUI.docEditor.docHeader.closeButton.click() + + assert nwGUI.docEditor.docHeader.tbButton.isVisible() is False + assert nwGUI.docEditor.docHeader.searchButton.isVisible() is False + assert nwGUI.docEditor.docHeader.closeButton.isVisible() is False + assert nwGUI.docEditor.docHeader.minmaxButton.isVisible() is False + + # Select item from header + with qtbot.waitSignal(nwGUI.docEditor.requestProjectItemSelected, timeout=1000) as signal: + qtbot.mouseClick(nwGUI.docEditor.docHeader, Qt.MouseButton.LeftButton) + assert signal.args == ["", True] # qtbot.stop() @@ -82,7 +109,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd): @pytest.mark.gui -def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumText, mockRnd): +def testGuiEditor_LoadText(qtbot, nwGUI, projPath, ipsumText, mockRnd): """Test loading text into the editor.""" buildTestProject(nwGUI, projPath) assert nwGUI.openDocument(C.hSceneDoc) is True @@ -92,9 +119,6 @@ def testGuiEditor_LoadText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumTex assert nwGUI.saveDocument() is True assert nwGUI.closeDocument() is True - # Load Text - # ========= - # Invalid handle assert nwGUI.docEditor.loadText("abcdefghijklm") is False @@ -123,9 +147,6 @@ def testGuiEditor_SaveText(qtbot, monkeypatch, caplog, nwGUI, projPath, ipsumTex buildTestProject(nwGUI, projPath) assert nwGUI.openDocument(C.hSceneDoc) is True - # Save Text - # ========= - longText = "### Lorem Ipsum\n\n%s" % "\n\n".join(ipsumText) nwGUI.docEditor.replaceText(longText)