Merge branch 'main' into outline_view
This commit is contained in:
@@ -23,7 +23,7 @@ import os
|
||||
import pytest
|
||||
|
||||
from shutil import copyfile
|
||||
from tools import cmpFiles
|
||||
from tools import cmpFiles, buildTestProject, XML_IGNORE, writeFile
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QDialog
|
||||
@@ -32,6 +32,7 @@ from novelwriter.gui import (
|
||||
GuiDocEditor, GuiProjectTree, GuiNovelTree, GuiOutline
|
||||
)
|
||||
from novelwriter.enum import nwItemType, nwWidget
|
||||
from novelwriter.tools import GuiProjectWizard
|
||||
from novelwriter.dialogs.itemeditor import GuiItemEditor
|
||||
|
||||
keyDelay = 2
|
||||
@@ -70,15 +71,52 @@ def testGuiMain_ProjectBlocker(monkeypatch, nwGUI):
|
||||
# END Test testGuiMain_NoProject
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_NewProject(monkeypatch, nwGUI, fncProj):
|
||||
"""Test creating a new project.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
|
||||
# No data
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(GuiProjectWizard, "exec_", lambda *a: None)
|
||||
assert nwGUI.newProject(projData=None) is False
|
||||
|
||||
# Close project
|
||||
with monkeypatch.context() as mp:
|
||||
nwGUI.hasProject = True
|
||||
mp.setattr(QMessageBox, "question", lambda *a: QMessageBox.No)
|
||||
assert nwGUI.newProject(projData={"projPath": fncProj}) is False
|
||||
|
||||
# No project path
|
||||
assert nwGUI.newProject(projData={}) is False
|
||||
|
||||
# Project file already exists
|
||||
projFile = os.path.join(fncProj, nwGUI.theProject.projFile)
|
||||
writeFile(projFile, "Stuff")
|
||||
assert nwGUI.newProject(projData={"projPath": fncProj}) is False
|
||||
os.unlink(projFile)
|
||||
|
||||
# An unreachable path should also fail
|
||||
projPath = os.path.join(fncProj, "stuff", "stuff", "stuff")
|
||||
assert nwGUI.newProject(projData={"projPath": projPath}) is False
|
||||
|
||||
# This one should work just fine
|
||||
assert nwGUI.newProject(projData={"projPath": fncProj}) is True
|
||||
assert os.path.isfile(os.path.join(fncProj, nwGUI.theProject.projFile))
|
||||
assert os.path.isdir(os.path.join(fncProj, "content"))
|
||||
|
||||
# END Test testGuiMain_NewProject
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
"""Test handling of project tree items based on GUI focus states.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
assert nwGUI.newProject({"projPath": fncProj}) is True
|
||||
assert nwGUI.saveProject() is True
|
||||
# assert False
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
|
||||
sHandle = "000000000000f"
|
||||
assert nwGUI.openSelectedItem() is False
|
||||
@@ -139,7 +177,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True)
|
||||
|
||||
# Create new, save, close project
|
||||
assert nwGUI.newProject({"projPath": fncProj})
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
assert nwGUI.saveProject()
|
||||
assert nwGUI.closeProject()
|
||||
|
||||
@@ -160,7 +198,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
testFile = os.path.join(outDir, "guiEditor_Main_Initial_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "guiEditor_Main_Initial_nwProject.nwx")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [2, 6, 7, 8])
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE)
|
||||
qtbot.wait(stepDelay)
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
@@ -178,9 +216,9 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
assert nwGUI.theProject.projMeta == os.path.join(fncProj, "meta")
|
||||
assert nwGUI.theProject.projFile == "nwProject.nwx"
|
||||
assert nwGUI.theProject.projName == "New Project"
|
||||
assert nwGUI.theProject.bookTitle == ""
|
||||
assert len(nwGUI.theProject.bookAuthors) == 0
|
||||
assert not nwGUI.theProject.spellCheck
|
||||
assert nwGUI.theProject.bookTitle == "New Novel"
|
||||
assert len(nwGUI.theProject.bookAuthors) == 1
|
||||
assert nwGUI.theProject.spellCheck is False
|
||||
|
||||
# Check that tree items have been created
|
||||
assert nwGUI.treeView._getTreeItem("0000000000008") is not None
|
||||
@@ -438,7 +476,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
testFile = os.path.join(outDir, "guiEditor_Main_Final_nwProject.nwx")
|
||||
compFile = os.path.join(refDir, "guiEditor_Main_Final_nwProject.nwx")
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, [2, 6, 7, 8])
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE)
|
||||
|
||||
projFile = os.path.join(fncProj, "content", "000000000000f.nwd")
|
||||
testFile = os.path.join(outDir, "guiEditor_Main_Final_000000000000f.nwd")
|
||||
@@ -467,3 +505,52 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiMain_Editing
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_FocusFullMode(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
"""Test toggling focus mode in main window.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
assert nwGUI.isFocusMode is False
|
||||
|
||||
# Focus Mode
|
||||
# ==========
|
||||
|
||||
# No document open, so not allowing focus mode
|
||||
assert nwGUI.toggleFocusMode() is False
|
||||
|
||||
# Open a file in editor and viewer
|
||||
assert nwGUI.openDocument("000000000000f")
|
||||
assert nwGUI.viewDocument("000000000000f")
|
||||
|
||||
# Enable focus mode
|
||||
assert nwGUI.toggleFocusMode() is True
|
||||
assert nwGUI.treePane.isVisible() is False
|
||||
assert nwGUI.statusBar.isVisible() is False
|
||||
assert nwGUI.mainMenu.isVisible() is False
|
||||
assert nwGUI.viewsBar.isVisible() is False
|
||||
assert nwGUI.splitView.isVisible() is False
|
||||
|
||||
# Disable focus mode
|
||||
assert nwGUI.toggleFocusMode() is True
|
||||
assert nwGUI.treePane.isVisible() is True
|
||||
assert nwGUI.statusBar.isVisible() is True
|
||||
assert nwGUI.mainMenu.isVisible() is True
|
||||
assert nwGUI.viewsBar.isVisible() is True
|
||||
assert nwGUI.splitView.isVisible() is True
|
||||
|
||||
# Full Screen Mode
|
||||
# ================
|
||||
|
||||
assert nwGUI.mainConf.isFullScreen is False
|
||||
nwGUI.toggleFullScreenMode()
|
||||
assert nwGUI.mainConf.isFullScreen is True
|
||||
nwGUI.toggleFullScreenMode()
|
||||
assert nwGUI.mainConf.isFullScreen is False
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiMain_FocusFullMode
|
||||
|
||||
@@ -26,7 +26,7 @@ from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QTextCursor, QTextBlock
|
||||
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
|
||||
|
||||
from tools import writeFile
|
||||
from tools import writeFile, buildTestProject
|
||||
|
||||
from novelwriter.gui.doceditor import GuiDocEditor
|
||||
from novelwriter.enum import nwDocAction, nwDocInsert
|
||||
@@ -465,7 +465,7 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj, mockRnd):
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
|
||||
assert nwGUI.newProject({"projPath": fncProj})
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
|
||||
assert nwGUI.treeView._getTreeItem("000000000000f") is not None
|
||||
assert nwGUI.openDocument("000000000000f") is True
|
||||
|
||||
@@ -22,6 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from tools import buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||
|
||||
from novelwriter.guimain import GuiMain
|
||||
@@ -47,7 +49,7 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd)
|
||||
|
||||
# Create a project
|
||||
prjDir = os.path.join(fncDir, "project")
|
||||
assert nwGUI.newProject({"projPath": prjDir}) is True
|
||||
buildTestProject(nwGUI, prjDir)
|
||||
|
||||
# No itemType set
|
||||
nwTree.clearSelection()
|
||||
@@ -155,7 +157,7 @@ def testGuiProjTree_MoveItems(qtbot, monkeypatch, nwGUI, fncDir, mockRnd):
|
||||
|
||||
# Create a project
|
||||
prjDir = os.path.join(fncDir, "project")
|
||||
assert nwGUI.newProject({"projPath": prjDir}) is True
|
||||
buildTestProject(nwGUI, prjDir)
|
||||
|
||||
# Move Documents
|
||||
# ==============
|
||||
@@ -283,7 +285,7 @@ def testGuiProjTree_DeleteItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR
|
||||
|
||||
# Create a project
|
||||
prjDir = os.path.join(fncDir, "project")
|
||||
assert nwGUI.newProject({"projPath": prjDir}) is True
|
||||
buildTestProject(nwGUI, prjDir)
|
||||
|
||||
# Try emptying the trash already now, when there is no trash folder
|
||||
assert nwTree.emptyTrash() is False
|
||||
|
||||
@@ -22,6 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import time
|
||||
import pytest
|
||||
|
||||
from tools import buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
from novelwriter.core import NWDoc
|
||||
@@ -34,7 +36,7 @@ def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
assert nwGUI.newProject({"projPath": fncProj}) is True
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
cHandle = nwGUI.theProject.newFile("A Note", "000000000000a")
|
||||
newDoc = NWDoc(nwGUI.theProject, cHandle)
|
||||
newDoc.writeDocument("# A Note\n\n")
|
||||
@@ -89,10 +91,10 @@ def testGuiStatusBar_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
# Project Stats
|
||||
nwGUI.statusBar.mainConf.incNotesWCount = False
|
||||
nwGUI._updateStatusWordCount()
|
||||
assert nwGUI.statusBar.statsText.text() == "Words: 6 (+6)"
|
||||
assert nwGUI.statusBar.statsText.text() == "Words: 9 (+9)"
|
||||
nwGUI.statusBar.mainConf.incNotesWCount = True
|
||||
nwGUI._updateStatusWordCount()
|
||||
assert nwGUI.statusBar.statsText.text() == "Words: 8 (+8)"
|
||||
assert nwGUI.statusBar.statsText.text() == "Words: 11 (+11)"
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user