Fix tests and a few other bits

This commit is contained in:
Veronica Berglyd Olsen
2022-06-14 19:33:12 +02:00
parent ea61db9591
commit 538b722bdf
7 changed files with 22 additions and 65 deletions
+2
View File
@@ -511,11 +511,13 @@ class GuiDocEditor(QTextEdit):
self.theProject.index.scanText(tHandle, docText) self.theProject.index.scanText(tHandle, docText)
newHeader = self.theProject.index.getHandleHeaderLevel(tHandle) newHeader = self.theProject.index.getHandleHeaderLevel(tHandle)
# ToDo: This should be a signal
if self._updateHeaders(checkLevel=True): if self._updateHeaders(checkLevel=True):
self.mainGui.requestNovelTreeRefresh() self.mainGui.requestNovelTreeRefresh()
else: else:
self.mainGui.novelView.updateWordCounts(tHandle) self.mainGui.novelView.updateWordCounts(tHandle)
# ToDo: This should be a signal
if oldHeader != newHeader: if oldHeader != newHeader:
self.mainGui.projView.setTreeItemValues(tHandle) self.mainGui.projView.setTreeItemValues(tHandle)
self.mainGui.itemDetails.updateViewBox(tHandle) self.mainGui.itemDetails.updateViewBox(tHandle)
-1
View File
@@ -254,7 +254,6 @@ class GuiNovelToolBar(QWidget):
"""Build the novel root menu. """Build the novel root menu.
""" """
self.mRoot.clear() self.mRoot.clear()
agRoot = QActionGroup(self.mRoot) agRoot = QActionGroup(self.mRoot)
for n, (tHandle, nwItem) in enumerate(self.theProject.tree.iterRoots(nwItemClass.NOVEL)): for n, (tHandle, nwItem) in enumerate(self.theProject.tree.iterRoots(nwItemClass.NOVEL)):
aRoot = self.mRoot.addAction(nwItem.itemName) aRoot = self.mRoot.addAction(nwItem.itemName)
+1 -1
View File
@@ -1,7 +1,7 @@
%%~name: Chapter One %%~name: Chapter One
%%~path: e5e47ebf63b1c/a520879ca0b45 %%~path: e5e47ebf63b1c/a520879ca0b45
%%~kind: NOVEL/DOCUMENT %%~kind: NOVEL/DOCUMENT
### Chapter One ## Chapter One
@pov: Jane @pov: Jane
+1 -1
View File
@@ -3,4 +3,4 @@
%%~kind: NOVEL/DOCUMENT %%~kind: NOVEL/DOCUMENT
# Part One # Part One
>> In the beginning … << >> In the beginning … <<
+1 -1
View File
@@ -470,7 +470,7 @@ def testCoreProject_Open(monkeypatch, nwMinimal, mockGUI):
writeFile(os.path.join(nwMinimal, "data_0", "123456789abc_main.bak"), "stuff") writeFile(os.path.join(nwMinimal, "data_0", "123456789abc_main.bak"), "stuff")
mockGUI.clear() mockGUI.clear()
assert theProject.openProject(nwMinimal) is True assert theProject.openProject(nwMinimal) is True
assert "version 1.0" in mockGUI.lastAlert assert "There was an error updating the project." in mockGUI.lastAlert
assert theProject.closeProject() assert theProject.closeProject()
+6 -6
View File
@@ -29,7 +29,7 @@ from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMessageBox, QInputDialog from PyQt5.QtWidgets import QMessageBox, QInputDialog
from novelwriter.gui import GuiDocEditor, GuiNovelView, GuiOutlineView from novelwriter.gui import GuiDocEditor, GuiNovelView, GuiOutlineView
from novelwriter.enum import nwItemType, nwWidget from novelwriter.enum import nwItemType, nwView, nwWidget
from novelwriter.tools import GuiProjectWizard from novelwriter.tools import GuiProjectWizard
from novelwriter.gui.projtree import GuiProjectTree from novelwriter.gui.projtree import GuiProjectTree
from novelwriter.dialogs import GuiEditLabel from novelwriter.dialogs import GuiEditLabel
@@ -120,6 +120,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
assert nwGUI.openSelectedItem() is False assert nwGUI.openSelectedItem() is False
# Project Tree has focus # Project Tree has focus
nwGUI._changeView(nwView.PROJECT)
nwGUI.switchFocus(nwWidget.TREE) nwGUI.switchFocus(nwWidget.TREE)
nwGUI.projStack.setCurrentIndex(0) nwGUI.projStack.setCurrentIndex(0)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
@@ -131,20 +132,19 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
assert nwGUI.closeDocument() is True assert nwGUI.closeDocument() is True
# Novel Tree has focus # Novel Tree has focus
nwGUI.projStack.setCurrentIndex(1) nwGUI._changeView(nwView.NOVEL)
nwGUI.novelView.refreshTree(rootHandle=None, overRide=True) nwGUI.novelView.refreshTree(rootHandle=None, overRide=True)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiNovelView, "treeFocus", lambda *a: True) mp.setattr(GuiNovelView, "treeFocus", lambda *a: True)
assert nwGUI.docEditor.docHandle() is None assert nwGUI.docEditor.docHandle() is None
actItem = nwGUI.novelView.novelTree.topLevelItem(0) selItem = nwGUI.novelView.novelTree.topLevelItem(2)
chpItem = actItem.child(0)
selItem = chpItem.child(0)
nwGUI.novelView.novelTree.setCurrentItem(selItem) nwGUI.novelView.novelTree.setCurrentItem(selItem)
nwGUI._keyPressReturn() nwGUI._keyPressReturn()
assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.docEditor.docHandle() == sHandle
assert nwGUI.closeDocument() is True assert nwGUI.closeDocument() is True
# Project Outline has focus # Project Outline has focus
nwGUI._changeView(nwView.OUTLINE)
nwGUI.switchFocus(nwWidget.OUTLINE) nwGUI.switchFocus(nwWidget.OUTLINE)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiOutlineView, "treeFocus", lambda *a: True) mp.setattr(GuiOutlineView, "treeFocus", lambda *a: True)
@@ -157,7 +157,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
assert nwGUI.docEditor.docHandle() == sHandle assert nwGUI.docEditor.docHandle() == sHandle
assert nwGUI.closeDocument() is True assert nwGUI.closeDocument() is True
# qtbot.stopForInteraction() # qtbot.stop()
# END Test testGuiMain_ProjectTreeItems # END Test testGuiMain_ProjectTreeItems
+11 -55
View File
@@ -20,9 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
import pytest import pytest
import os
from tools import writeFile
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QMessageBox
@@ -40,9 +37,8 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
novelView = nwGUI.novelView novelView = nwGUI.novelView
novelTree = novelView.novelTree novelTree = novelView.novelTree
## # Show/Hide Scrollbars
# Show/Hide Scrollbars # ====================
##
nwGUI.mainConf.hideVScroll = True nwGUI.mainConf.hideVScroll = True
nwGUI.mainConf.hideHScroll = True nwGUI.mainConf.hideHScroll = True
@@ -56,14 +52,13 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
assert novelTree.verticalScrollBar().isEnabled() assert novelTree.verticalScrollBar().isEnabled()
assert novelTree.horizontalScrollBar().isEnabled() assert novelTree.horizontalScrollBar().isEnabled()
## # Populate Tree
# Populate Tree # =============
##
nwGUI.projStack.setCurrentIndex(nwGUI.idxNovelView) nwGUI.projStack.setCurrentIndex(nwGUI.idxNovelView)
nwGUI.rebuildIndex() nwGUI.rebuildIndex()
novelTree._populateTree(rootHandle=None) novelTree._populateTree(rootHandle=None)
assert novelTree.topLevelItemCount() == 1 assert novelTree.topLevelItemCount() == 3
# Rebuild should preserve selection # Rebuild should preserve selection
topItem = novelTree.topLevelItem(0) topItem = novelTree.topLevelItem(0)
@@ -75,13 +70,12 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
novelView.refreshTree() novelView.refreshTree()
assert novelTree.topLevelItem(0).isSelected() assert novelTree.topLevelItem(0).isSelected()
## # Open Items
# Open Items # ==========
##
# Clear selection # Clear selection
novelTree.clearSelection() novelTree.clearSelection()
scItem = novelTree.topLevelItem(0).child(0).child(0) scItem = novelTree.topLevelItem(2)
scItem.setSelected(True) scItem.setSelected(True)
assert scItem.isSelected() assert scItem.isSelected()
@@ -114,48 +108,10 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10) qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10)
assert nwGUI.docViewer.docHandle() == "8c659a11cd429" assert nwGUI.docViewer.docHandle() == "8c659a11cd429"
## # Close
# Populate Tree # =====
##
# Add weird titles to first file to check hnadling of non-standard # qtbot.stop()
# order of title levels.
writeFile(os.path.join(nwMinimal, "content", "a35baf2e93843.nwd"), (
"#### Section wo/Scene\n\n"
"### Scene wo/Chapter\n\n"
"## Chapter wo/Title\n\n"
"# Title\n\n"
"#### Section w/Title, wo/Scene\n\n"
"### Scene w/Title, wo/Chapter\n\n"
"## Chapter\n\n"
"#### Section w/Chapter, wo/Scene\n\n"
"### Scene\n\n"
"#### Section\n\n"
))
nwGUI.rebuildIndex()
novelTree._populateTree(None)
assert novelTree.topLevelItem(0).text(novelTree.C_TITLE) == "Section wo/Scene"
assert novelTree.topLevelItem(1).text(novelTree.C_TITLE) == "Scene wo/Chapter"
assert novelTree.topLevelItem(2).text(novelTree.C_TITLE) == "Chapter wo/Title"
assert novelTree.topLevelItem(3).text(novelTree.C_TITLE) == "Title"
tTitle = novelTree.topLevelItem(3)
assert tTitle.child(0).text(novelTree.C_TITLE) == "Section w/Title, wo/Scene"
assert tTitle.child(1).text(novelTree.C_TITLE) == "Scene w/Title, wo/Chapter"
assert tTitle.child(2).text(novelTree.C_TITLE) == "Chapter"
tChap = tTitle.child(2)
assert tChap.child(0).text(novelTree.C_TITLE) == "Section w/Chapter, wo/Scene"
assert tChap.child(1).text(novelTree.C_TITLE) == "Scene"
tScene = tChap.child(1)
assert tScene.child(0).text(novelTree.C_TITLE) == "Section"
##
# Close
##
# qtbot.stopForInteraction()
nwGUI.closeProject() nwGUI.closeProject()
# END Test testGuiNovelTree_TreeItems # END Test testGuiNovelTree_TreeItems