Fix tests and add missing methods

This commit is contained in:
Veronica Berglyd Olsen
2022-05-15 17:56:36 +02:00
parent ca48e37163
commit a5b2a06f84
4 changed files with 50 additions and 38 deletions
+9
View File
@@ -73,6 +73,9 @@ class GuiOutline(QWidget):
self.setLayout(self.outerBox) self.setLayout(self.outerBox)
# Function Mappings
self.getSelectedHandle = self.outlineView.getSelectedHandle
return return
## ##
@@ -99,6 +102,12 @@ class GuiOutline(QWidget):
self.outlineView.refreshTree(overRide=overRide, novelChanged=novelChanged) self.outlineView.refreshTree(overRide=overRide, novelChanged=novelChanged)
return return
def treeFocus(self):
return self.outlineView.hasFocus()
def setTreeFocus(self):
return self.outlineView.setFocus()
# END Class GuiOutline # END Class GuiOutline
+2 -2
View File
@@ -780,7 +780,7 @@ class GuiMain(QMainWindow):
tHandle = self.treeView.getSelectedHandle() tHandle = self.treeView.getSelectedHandle()
elif self.novelView.hasFocus(): elif self.novelView.hasFocus():
tHandle, tLine = self.novelView.getSelectedHandle() tHandle, tLine = self.novelView.getSelectedHandle()
elif self.projView.hasFocus(): elif self.projView.treeFocus():
tHandle, tLine = self.projView.getSelectedHandle() tHandle, tLine = self.projView.getSelectedHandle()
else: else:
logger.warning("No item selected") logger.warning("No item selected")
@@ -1221,7 +1221,7 @@ class GuiMain(QMainWindow):
self.docViewer.setFocus() self.docViewer.setFocus()
elif paneNo == nwWidget.OUTLINE: elif paneNo == nwWidget.OUTLINE:
self._changeView(nwView.OUTLINE) self._changeView(nwView.OUTLINE)
self.projView.setFocus() self.projView.setTreeFocus()
return return
def closeDocEditor(self): def closeDocEditor(self):
+3 -3
View File
@@ -111,12 +111,12 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
# Project Outline has focus # Project Outline has focus
nwGUI.switchFocus(nwWidget.OUTLINE) nwGUI.switchFocus(nwWidget.OUTLINE)
with monkeypatch.context() as mp: with monkeypatch.context() as mp:
mp.setattr(GuiOutline, "hasFocus", lambda *a: True) mp.setattr(GuiOutline, "treeFocus", lambda *a: True)
assert nwGUI.docEditor.docHandle() is None assert nwGUI.docEditor.docHandle() is None
actItem = nwGUI.projView.topLevelItem(0) actItem = nwGUI.projView.outlineView.topLevelItem(0)
chpItem = actItem.child(0) chpItem = actItem.child(0)
selItem = chpItem.child(0) selItem = chpItem.child(0)
nwGUI.projView.setCurrentItem(selItem) nwGUI.projView.outlineView.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
+36 -33
View File
@@ -45,69 +45,72 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
nwGUI.rebuildIndex() nwGUI.rebuildIndex()
nwGUI.mainStack.setCurrentIndex(nwGUI.idxOutlineView) nwGUI.mainStack.setCurrentIndex(nwGUI.idxOutlineView)
assert nwGUI.projView.topLevelItemCount() > 0 outlineView = nwGUI.projView.outlineView
outlineData = nwGUI.projView.outlineData
assert outlineView.topLevelItemCount() > 0
# Context Menu # Context Menu
nwGUI.projView._headerRightClick(QPoint(1, 1)) outlineView._headerRightClick(QPoint(1, 1))
nwGUI.projView.headerMenu.actionMap[nwOutline.CCOUNT].activate(QAction.Trigger) outlineView.headerMenu.actionMap[nwOutline.CCOUNT].activate(QAction.Trigger)
nwGUI.projView.headerMenu.close() outlineView.headerMenu.close()
qtbot.mouseClick(nwGUI.projView, Qt.LeftButton) qtbot.mouseClick(outlineView, Qt.LeftButton)
nwGUI.projView._loadHeaderState() outlineView._loadHeaderState()
assert not nwGUI.projView._colHidden[nwOutline.CCOUNT] assert not outlineView._colHidden[nwOutline.CCOUNT]
# First Item # First Item
nwGUI.rebuildOutline() nwGUI.rebuildOutline()
selItem = nwGUI.projView.topLevelItem(0) selItem = outlineView.topLevelItem(0)
assert isinstance(selItem, QTreeWidgetItem) assert isinstance(selItem, QTreeWidgetItem)
nwGUI.projView.setCurrentItem(selItem) outlineView.setCurrentItem(selItem)
assert nwGUI.projMeta.titleLabel.text() == "<b>Title</b>" assert outlineData.titleLabel.text() == "<b>Title</b>"
assert nwGUI.projMeta.titleValue.text() == "Lorem Ipsum" assert outlineData.titleValue.text() == "Lorem Ipsum"
assert nwGUI.projMeta.fileValue.text() == "Lorem Ipsum" assert outlineData.fileValue.text() == "Lorem Ipsum"
assert nwGUI.projMeta.itemValue.text() == "Finished" assert outlineData.itemValue.text() == "Finished"
assert nwGUI.projMeta.cCValue.text() == "230" assert outlineData.cCValue.text() == "230"
assert nwGUI.projMeta.wCValue.text() == "40" assert outlineData.wCValue.text() == "40"
assert nwGUI.projMeta.pCValue.text() == "3" assert outlineData.pCValue.text() == "3"
# Scene One # Scene One
actItem = nwGUI.projView.topLevelItem(1) actItem = outlineView.topLevelItem(1)
chpItem = actItem.child(0) chpItem = actItem.child(0)
selItem = chpItem.child(0) selItem = chpItem.child(0)
nwGUI.projView.setCurrentItem(selItem) outlineView.setCurrentItem(selItem)
tHandle, tLine = nwGUI.projView.getSelectedHandle() tHandle, tLine = outlineView.getSelectedHandle()
assert tHandle == "88243afbe5ed8" assert tHandle == "88243afbe5ed8"
assert tLine == 0 assert tLine == 0
assert nwGUI.projMeta.titleLabel.text() == "<b>Scene</b>" assert outlineData.titleLabel.text() == "<b>Scene</b>"
assert nwGUI.projMeta.titleValue.text() == "Scene One" assert outlineData.titleValue.text() == "Scene One"
assert nwGUI.projMeta.fileValue.text() == "Scene One" assert outlineData.fileValue.text() == "Scene One"
assert nwGUI.projMeta.itemValue.text() == "Finished" assert outlineData.itemValue.text() == "Finished"
# Click POV Link # Click POV Link
assert nwGUI.projMeta.povKeyValue.text() == "<a href='#pov=Bod'>Bod</a>" assert outlineData.povKeyValue.text() == "<a href='#pov=Bod'>Bod</a>"
nwGUI.projMeta._tagClicked("#pov=Bod") outlineData._tagClicked("#pov=Bod")
assert nwGUI.docViewer.docHandle() == "4c4f28287af27" assert nwGUI.docViewer.docHandle() == "4c4f28287af27"
# Scene One, Section Two # Scene One, Section Two
actItem = nwGUI.projView.topLevelItem(1) actItem = outlineView.topLevelItem(1)
chpItem = actItem.child(0) chpItem = actItem.child(0)
scnItem = chpItem.child(0) scnItem = chpItem.child(0)
selItem = scnItem.child(0) selItem = scnItem.child(0)
nwGUI.projView.setCurrentItem(selItem) outlineView.setCurrentItem(selItem)
tHandle, tLine = nwGUI.projView.getSelectedHandle() tHandle, tLine = outlineView.getSelectedHandle()
assert tHandle == "88243afbe5ed8" assert tHandle == "88243afbe5ed8"
assert tLine == 12 assert tLine == 12
assert nwGUI.projMeta.titleLabel.text() == "<b>Section</b>" assert outlineData.titleLabel.text() == "<b>Section</b>"
assert nwGUI.projMeta.titleValue.text() == "Scene One, Section Two" assert outlineData.titleValue.text() == "Scene One, Section Two"
assert nwGUI.projMeta.fileValue.text() == "Scene One" assert outlineData.fileValue.text() == "Scene One"
assert nwGUI.projMeta.itemValue.text() == "Finished" assert outlineData.itemValue.text() == "Finished"
nwGUI.projView._treeDoubleClick(selItem, 0) outlineView._treeDoubleClick(selItem, 0)
assert nwGUI.docEditor.docHandle() == "88243afbe5ed8" assert nwGUI.docEditor.docHandle() == "88243afbe5ed8"
# qtbot.stopForInteraction() # qtbot.stopForInteraction()