Improve test coverage

This commit is contained in:
Veronica Berglyd Olsen
2022-06-15 20:37:19 +02:00
parent 8c4ecaeee2
commit 0d01e108f1
+36 -4
View File
@@ -24,8 +24,9 @@ import pytest
from tools import buildTestProject, writeFile from tools import buildTestProject, writeFile
from PyQt5.QtCore import Qt from PyQt5.QtGui import QFocusEvent
from PyQt5.QtWidgets import QMessageBox from PyQt5.QtCore import Qt, QEvent
from PyQt5.QtWidgets import QMessageBox, QToolTip
from novelwriter.enum import nwWidget, nwItemType from novelwriter.enum import nwWidget, nwItemType
from novelwriter.dialogs import GuiEditLabel from novelwriter.dialogs import GuiEditLabel
@@ -53,8 +54,12 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
"# Jane Doe\n\n@tag: Jane\n\n" "# Jane Doe\n\n@tag: Jane\n\n"
) )
writeFile( writeFile(
os.path.join(nwGUI.theProject.projContent, "000000000000f.nwd"), os.path.join(nwGUI.theProject.projContent, "000000000000f.nwd"), (
"### Scene One\n\n@pov: Jane\n@focus: Jane\n\n" "### Scene One\n\n"
"@pov: Jane\n"
"@focus: Jane\n\n"
"% Synopsis: This is a scene."
)
) )
novelView = nwGUI.novelView novelView = nwGUI.novelView
@@ -165,6 +170,33 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
novelTree._lastCol = None novelTree._lastCol = None
assert novelTree._getLastColumnText("0000000000000", "T000000") == ("", "") assert novelTree._getLastColumnText("0000000000000", "T000000") == ("", "")
# Item Meta
# =========
ttText = ""
def showText(pos, text):
nonlocal ttText
ttText = text
mIndex = novelTree.model().index(2, novelTree.C_MORE)
with monkeypatch.context() as mp:
mp.setattr(QToolTip, "showText", showText)
novelTree._treeItemClicked(mIndex)
assert ttText == (
"<p><b>Point of View</b>: Jane<br><b>Focus</b>: Jane</p>"
"<p><b>Synopsis</b>: This is a scene.</p>"
)
# Other Checks
# ============
scItem = novelTree.topLevelItem(2)
scItem.setSelected(True)
assert scItem.isSelected()
novelTree.focusOutEvent(QFocusEvent(QEvent.None_, Qt.MouseFocusReason))
assert not scItem.isSelected()
# Close # Close
# ===== # =====