Fix tests and a few other bits
This commit is contained in:
@@ -511,11 +511,13 @@ class GuiDocEditor(QTextEdit):
|
||||
self.theProject.index.scanText(tHandle, docText)
|
||||
newHeader = self.theProject.index.getHandleHeaderLevel(tHandle)
|
||||
|
||||
# ToDo: This should be a signal
|
||||
if self._updateHeaders(checkLevel=True):
|
||||
self.mainGui.requestNovelTreeRefresh()
|
||||
else:
|
||||
self.mainGui.novelView.updateWordCounts(tHandle)
|
||||
|
||||
# ToDo: This should be a signal
|
||||
if oldHeader != newHeader:
|
||||
self.mainGui.projView.setTreeItemValues(tHandle)
|
||||
self.mainGui.itemDetails.updateViewBox(tHandle)
|
||||
|
||||
@@ -254,7 +254,6 @@ class GuiNovelToolBar(QWidget):
|
||||
"""Build the novel root menu.
|
||||
"""
|
||||
self.mRoot.clear()
|
||||
|
||||
agRoot = QActionGroup(self.mRoot)
|
||||
for n, (tHandle, nwItem) in enumerate(self.theProject.tree.iterRoots(nwItemClass.NOVEL)):
|
||||
aRoot = self.mRoot.addAction(nwItem.itemName)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%~name: Chapter One
|
||||
%%~path: e5e47ebf63b1c/a520879ca0b45
|
||||
%%~kind: NOVEL/DOCUMENT
|
||||
### Chapter One
|
||||
## Chapter One
|
||||
|
||||
@pov: Jane
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
%%~kind: NOVEL/DOCUMENT
|
||||
# Part One
|
||||
|
||||
>> In the beginning … <<
|
||||
>> In the beginning … <<
|
||||
|
||||
@@ -470,7 +470,7 @@ def testCoreProject_Open(monkeypatch, nwMinimal, mockGUI):
|
||||
writeFile(os.path.join(nwMinimal, "data_0", "123456789abc_main.bak"), "stuff")
|
||||
mockGUI.clear()
|
||||
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()
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QInputDialog
|
||||
|
||||
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.gui.projtree import GuiProjectTree
|
||||
from novelwriter.dialogs import GuiEditLabel
|
||||
@@ -120,6 +120,7 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
assert nwGUI.openSelectedItem() is False
|
||||
|
||||
# Project Tree has focus
|
||||
nwGUI._changeView(nwView.PROJECT)
|
||||
nwGUI.switchFocus(nwWidget.TREE)
|
||||
nwGUI.projStack.setCurrentIndex(0)
|
||||
with monkeypatch.context() as mp:
|
||||
@@ -131,20 +132,19 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
assert nwGUI.closeDocument() is True
|
||||
|
||||
# Novel Tree has focus
|
||||
nwGUI.projStack.setCurrentIndex(1)
|
||||
nwGUI._changeView(nwView.NOVEL)
|
||||
nwGUI.novelView.refreshTree(rootHandle=None, overRide=True)
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(GuiNovelView, "treeFocus", lambda *a: True)
|
||||
assert nwGUI.docEditor.docHandle() is None
|
||||
actItem = nwGUI.novelView.novelTree.topLevelItem(0)
|
||||
chpItem = actItem.child(0)
|
||||
selItem = chpItem.child(0)
|
||||
selItem = nwGUI.novelView.novelTree.topLevelItem(2)
|
||||
nwGUI.novelView.novelTree.setCurrentItem(selItem)
|
||||
nwGUI._keyPressReturn()
|
||||
assert nwGUI.docEditor.docHandle() == sHandle
|
||||
assert nwGUI.closeDocument() is True
|
||||
|
||||
# Project Outline has focus
|
||||
nwGUI._changeView(nwView.OUTLINE)
|
||||
nwGUI.switchFocus(nwWidget.OUTLINE)
|
||||
with monkeypatch.context() as mp:
|
||||
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.closeDocument() is True
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
# qtbot.stop()
|
||||
|
||||
# END Test testGuiMain_ProjectTreeItems
|
||||
|
||||
|
||||
@@ -20,9 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from tools import writeFile
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
@@ -40,9 +37,8 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
novelView = nwGUI.novelView
|
||||
novelTree = novelView.novelTree
|
||||
|
||||
##
|
||||
# Show/Hide Scrollbars
|
||||
##
|
||||
# Show/Hide Scrollbars
|
||||
# ====================
|
||||
|
||||
nwGUI.mainConf.hideVScroll = True
|
||||
nwGUI.mainConf.hideHScroll = True
|
||||
@@ -56,14 +52,13 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
assert novelTree.verticalScrollBar().isEnabled()
|
||||
assert novelTree.horizontalScrollBar().isEnabled()
|
||||
|
||||
##
|
||||
# Populate Tree
|
||||
##
|
||||
# Populate Tree
|
||||
# =============
|
||||
|
||||
nwGUI.projStack.setCurrentIndex(nwGUI.idxNovelView)
|
||||
nwGUI.rebuildIndex()
|
||||
novelTree._populateTree(rootHandle=None)
|
||||
assert novelTree.topLevelItemCount() == 1
|
||||
assert novelTree.topLevelItemCount() == 3
|
||||
|
||||
# Rebuild should preserve selection
|
||||
topItem = novelTree.topLevelItem(0)
|
||||
@@ -75,13 +70,12 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
novelView.refreshTree()
|
||||
assert novelTree.topLevelItem(0).isSelected()
|
||||
|
||||
##
|
||||
# Open Items
|
||||
##
|
||||
# Open Items
|
||||
# ==========
|
||||
|
||||
# Clear selection
|
||||
novelTree.clearSelection()
|
||||
scItem = novelTree.topLevelItem(0).child(0).child(0)
|
||||
scItem = novelTree.topLevelItem(2)
|
||||
scItem.setSelected(True)
|
||||
assert scItem.isSelected()
|
||||
|
||||
@@ -114,48 +108,10 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
qtbot.mouseClick(vPort, Qt.MiddleButton, pos=scRect.center(), delay=10)
|
||||
assert nwGUI.docViewer.docHandle() == "8c659a11cd429"
|
||||
|
||||
##
|
||||
# Populate Tree
|
||||
##
|
||||
# Close
|
||||
# =====
|
||||
|
||||
# Add weird titles to first file to check hnadling of non-standard
|
||||
# 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()
|
||||
# qtbot.stop()
|
||||
nwGUI.closeProject()
|
||||
|
||||
# END Test testGuiNovelTree_TreeItems
|
||||
|
||||
Reference in New Issue
Block a user