Update tests other than tree-related
This commit is contained in:
@@ -29,7 +29,7 @@ from PyQt5.QtGui import QDesktopServices, QMouseEvent, QTextCursor
|
||||
from PyQt5.QtWidgets import QAction, QApplication, QMenu
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.enum import nwDocAction
|
||||
from novelwriter.enum import nwChange, nwDocAction
|
||||
from novelwriter.formats.toqdoc import ToQTextDocument
|
||||
from novelwriter.types import QtModNone, QtMouseLeft
|
||||
|
||||
@@ -206,12 +206,12 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
nwItem = SHARED.project.tree["4c4f28287af27"]
|
||||
nwItem.setName("Test Title") # type: ignore
|
||||
assert nwItem.itemName == "Test Title" # type: ignore
|
||||
docViewer.updateDocInfo("4c4f28287af27")
|
||||
docViewer.onProjectItemChanged("4c4f28287af27", nwChange.UPDATE)
|
||||
assert docViewer.docHeader.itemTitle.text() == "Characters \u203a Test Title"
|
||||
|
||||
# Title without full path
|
||||
CONFIG.showFullPath = False
|
||||
docViewer.updateDocInfo("4c4f28287af27")
|
||||
docViewer.onProjectItemChanged("4c4f28287af27", nwChange.UPDATE)
|
||||
assert docViewer.docHeader.itemTitle.text() == "Test Title"
|
||||
CONFIG.showFullPath = True
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ def testGuiViewerPanel_BackRefs(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
buildTestProject(nwGUI, projPath)
|
||||
projTree = nwGUI.projView.projTree
|
||||
projTree.expandAll()
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
viewPanel = nwGUI.docViewerPanel
|
||||
tabBackRefs = viewPanel.tabBackRefs
|
||||
|
||||
@@ -81,7 +80,7 @@ def testGuiViewerPanel_BackRefs(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Update Label
|
||||
SHARED.project.tree[C.hSceneDoc].setName("First Scene") # type: ignore
|
||||
projTree.renameTreeItem(C.hSceneDoc)
|
||||
nwGUI.projView.renameTreeItem(C.hSceneDoc)
|
||||
item = tabBackRefs.topLevelItem(0)
|
||||
assert item.text(tabBackRefs.C_DOC) == "First Scene"
|
||||
assert item.text(tabBackRefs.C_TITLE) == "Scene One"
|
||||
@@ -127,8 +126,7 @@ def testGuiViewerPanel_Tags(qtbot, monkeypatch, caplog, nwGUI, projPath, mockRnd
|
||||
monkeypatch.setattr(GuiEditLabel, "getLabel", lambda *a, text: (text, True))
|
||||
|
||||
buildTestProject(nwGUI, projPath)
|
||||
projTree = nwGUI.projView.projTree
|
||||
projTree.expandAll()
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
viewPanel = nwGUI.docViewerPanel
|
||||
|
||||
nwGUI.openDocument(C.hSceneDoc)
|
||||
@@ -175,7 +173,7 @@ def testGuiViewerPanel_Tags(qtbot, monkeypatch, caplog, nwGUI, projPath, mockRnd
|
||||
nwGUI.docEditor.setPlainText("# Jane Smith\n\n@tag: Janey\n\n")
|
||||
nwGUI.saveDocument()
|
||||
SHARED.project.tree[hJane].setName("Awesome Jane") # type: ignore
|
||||
projTree.renameTreeItem(hJane)
|
||||
nwGUI.projView.renameTreeItem(hJane)
|
||||
item = charTab.topLevelItem(0)
|
||||
assert item.text(charTab.C_NAME) == "Janey"
|
||||
assert item.text(charTab.C_DOC) == "Awesome Jane"
|
||||
@@ -221,8 +219,7 @@ def testGuiViewerPanel_Tags(qtbot, monkeypatch, caplog, nwGUI, projPath, mockRnd
|
||||
nwJohn = SHARED.project.tree[hJohn]
|
||||
assert isinstance(nwJohn, NWItem)
|
||||
nwJohn.setActive(False)
|
||||
projTree.setTreeItemValues(nwJohn)
|
||||
projTree._alertTreeChange(hJohn, flush=False)
|
||||
nwJohn.notifyToRefresh()
|
||||
assert charTab.topLevelItemCount() == 1
|
||||
|
||||
# Update Labels
|
||||
|
||||
@@ -210,9 +210,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
assert nwGUI.closeProject()
|
||||
|
||||
assert len(SHARED.project.tree) == 0
|
||||
assert len(SHARED.project.tree._order) == 0
|
||||
assert len(SHARED.project.tree._roots) == 0
|
||||
assert SHARED.project.tree.trashRoot is None
|
||||
assert len(SHARED.project.tree._items) == 0
|
||||
assert len(SHARED.project.tree._nodes) == 0
|
||||
assert SHARED.project.data.name == ""
|
||||
assert SHARED.project.data.author == ""
|
||||
assert SHARED.project.data.spellCheck is False
|
||||
@@ -228,23 +227,22 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
assert nwGUI.openProject(projPath)
|
||||
|
||||
# Check that we loaded the data
|
||||
assert len(SHARED.project.tree) == 8
|
||||
assert len(SHARED.project.tree._order) == 8
|
||||
assert len(SHARED.project.tree._roots) == 4
|
||||
assert SHARED.project.tree.trashRoot is None
|
||||
assert len(SHARED.project.tree) == 9
|
||||
assert SHARED.project.tree.model.root.childCount() == 5
|
||||
assert SHARED.project.tree.trash is not None # Created automatically
|
||||
assert SHARED.project.data.name == "New Project"
|
||||
assert SHARED.project.data.author == "Jane Doe"
|
||||
assert SHARED.project.data.spellCheck is False
|
||||
|
||||
# Check that tree items have been created
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hNovelRoot) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hPlotRoot) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hCharRoot) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hWorldRoot) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hTitlePage) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hChapterDir) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hChapterDoc) is not None
|
||||
assert nwGUI.projView.projTree._getTreeItem(C.hSceneDoc) is not None
|
||||
assert SHARED.project.tree[C.hNovelRoot] is not None
|
||||
assert SHARED.project.tree[C.hPlotRoot] is not None
|
||||
assert SHARED.project.tree[C.hCharRoot] is not None
|
||||
assert SHARED.project.tree[C.hWorldRoot] is not None
|
||||
assert SHARED.project.tree[C.hTitlePage] is not None
|
||||
assert SHARED.project.tree[C.hChapterDir] is not None
|
||||
assert SHARED.project.tree[C.hChapterDoc] is not None
|
||||
assert SHARED.project.tree[C.hSceneDoc] is not None
|
||||
|
||||
nwGUI.mainMenu.aSpellCheck.setChecked(True)
|
||||
nwGUI.mainMenu._toggleSpellCheck()
|
||||
@@ -256,10 +254,12 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
CONFIG.autoScroll = True
|
||||
|
||||
# Add a Character File
|
||||
nwGUI._switchFocus(nwFocus.TREE)
|
||||
nwGUI._changeView(nwView.PROJECT)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.projView.projTree.clearSelection()
|
||||
nwGUI.projView.projTree._getTreeItem(C.hCharRoot).setSelected(True)
|
||||
nwGUI.projView.projTree.setSelectedHandle(C.hCharRoot)
|
||||
nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.openSelectedItem()
|
||||
|
||||
# Text Editor
|
||||
@@ -290,10 +290,11 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
|
||||
|
||||
# Add a Plot File
|
||||
nwGUI._switchFocus(nwFocus.TREE)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.projView.projTree.clearSelection()
|
||||
nwGUI.projView.projTree._getTreeItem(C.hPlotRoot).setSelected(True)
|
||||
nwGUI.projView.projTree.setSelectedHandle(C.hPlotRoot)
|
||||
nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.openSelectedItem()
|
||||
|
||||
# Type something into the document
|
||||
@@ -312,10 +313,11 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
|
||||
|
||||
# Add a World File
|
||||
nwGUI._switchFocus(nwFocus.TREE)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.projView.projTree.clearSelection()
|
||||
nwGUI.projView.projTree._getTreeItem(C.hWorldRoot).setSelected(True)
|
||||
nwGUI.projView.projTree.setSelectedHandle(C.hWorldRoot)
|
||||
nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.openSelectedItem()
|
||||
|
||||
# Add Some Text
|
||||
@@ -343,11 +345,9 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
nwGUI._autoSaveProject()
|
||||
|
||||
# Select the 'New Scene' file
|
||||
nwGUI._switchFocus(nwFocus.TREE)
|
||||
nwGUI.projView.projTree.expandAll()
|
||||
nwGUI.projView.projTree.clearSelection()
|
||||
nwGUI.projView.projTree._getTreeItem(C.hNovelRoot).setExpanded(True)
|
||||
nwGUI.projView.projTree._getTreeItem(C.hChapterDir).setExpanded(True)
|
||||
nwGUI.projView.projTree._getTreeItem(C.hSceneDoc).setSelected(True)
|
||||
nwGUI.projView.projTree.setSelectedHandle(C.hSceneDoc)
|
||||
nwGUI.openSelectedItem()
|
||||
|
||||
# Type something into the document
|
||||
@@ -533,6 +533,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
# Indent and Align
|
||||
# ================
|
||||
|
||||
nwGUI._switchFocus(nwView.EDITOR)
|
||||
for c in "\t\"Tab-indented text\"":
|
||||
qtbot.keyClick(docEditor, c, delay=KEY_DELAY)
|
||||
qtbot.keyClick(docEditor, Qt.Key.Key_Return, delay=KEY_DELAY)
|
||||
@@ -622,12 +623,6 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE)
|
||||
|
||||
projFile = projPath / "content" / "0000000000010.nwd"
|
||||
testFile = tstPaths.outDir / "guiEditor_Main_Final_0000000000010.nwd"
|
||||
compFile = tstPaths.refDir / "guiEditor_Main_Final_0000000000010.nwd"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE)
|
||||
|
||||
projFile = projPath / "content" / "0000000000011.nwd"
|
||||
testFile = tstPaths.outDir / "guiEditor_Main_Final_0000000000011.nwd"
|
||||
compFile = tstPaths.refDir / "guiEditor_Main_Final_0000000000011.nwd"
|
||||
@@ -640,6 +635,12 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE)
|
||||
|
||||
projFile = projPath / "content" / "0000000000013.nwd"
|
||||
testFile = tstPaths.outDir / "guiEditor_Main_Final_0000000000013.nwd"
|
||||
compFile = tstPaths.refDir / "guiEditor_Main_Final_0000000000013.nwd"
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=NWD_IGNORE)
|
||||
|
||||
# qtbot.stop()
|
||||
|
||||
|
||||
|
||||
@@ -197,7 +197,8 @@ def testGuiOutline_Content(qtbot, monkeypatch, nwGUI, prjLipsum, fncPath, tstPat
|
||||
assert outlineBar.novelValue.itemData(2) == "" # All novels
|
||||
|
||||
# Add a second novel folder
|
||||
newHandle = SHARED.project.newRoot(nwItemClass.NOVEL)
|
||||
with qtbot.waitSignal(SHARED.rootFolderChanged):
|
||||
newHandle = SHARED.project.newRoot(nwItemClass.NOVEL)
|
||||
|
||||
# Check new values in dropdown list
|
||||
assert outlineBar.novelValue.itemData(0) == lipHandle
|
||||
@@ -277,7 +278,7 @@ def testGuiOutline_Content(qtbot, monkeypatch, nwGUI, prjLipsum, fncPath, tstPat
|
||||
assert outlineData.fileValue.text() == "Scene One"
|
||||
assert outlineData.itemValue.text() == "Finished"
|
||||
|
||||
outlineTree._treeDoubleClick(selItem, 0)
|
||||
outlineTree._onItemDoubleClicked(selItem, 0)
|
||||
assert nwGUI.docEditor.docHandle == "88243afbe5ed8"
|
||||
|
||||
# Dump to CSV
|
||||
|
||||
@@ -86,9 +86,11 @@ def testGuiStatusBar_Main(qtbot, nwGUI, projPath, mockRnd):
|
||||
|
||||
# Project Stats
|
||||
CONFIG.incNotesWCount = False
|
||||
nwGUI._lastTotalCount = 0
|
||||
nwGUI._updateStatusWordCount()
|
||||
assert nwGUI.mainStatus.statsText.text() == "Words: 9 (+9)"
|
||||
CONFIG.incNotesWCount = True
|
||||
nwGUI._lastTotalCount = 0
|
||||
nwGUI._updateStatusWordCount()
|
||||
assert nwGUI.mainStatus.statsText.text() == "Words: 11 (+11)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user