Added test for main preferences and improved the Preferences dialog a bit

This commit is contained in:
Veronica K. B. Olsen
2020-09-19 20:30:04 +02:00
parent 4338580d2c
commit 5810ba68b5
5 changed files with 274 additions and 86 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ def nwConf(nwRef, nwTemp):
return theConf
@pytest.fixture(scope="session")
def tmpConf(nwRef, nwTemp):
def tmpConf(nwTemp):
theConf = Config()
theConf.initConfig(nwTemp, nwTemp)
theConf.setLastPath("")
+69
View File
@@ -0,0 +1,69 @@
[Main]
timestamp = 2020-06-29 17:34:15
theme = default
syntax = default_light
icons = typicons_colour_light
guidark = True
guifont = Cantarell
guifontsize = 12
[Sizes]
geometry = 1100, 650
treecols = 120, 30, 50
projcols = 140, 55, 140
mainpane = 300, 800
docpane = 400, 400
viewpane = 500, 150
outlinepane = 500, 150
fullscreen = False
[Project]
autosaveproject = 40
autosavedoc = 20
[Editor]
textfont = Cantarell
textsize = 13
fixedwidth = False
width = 700
margin = 45
tabwidth = 45
focuswidth = 900
hidefocusfooter = True
justify = False
autoselect = False
autoreplace = False
repsquotes = True
repdquotes = True
repdash = True
repdots = True
fmtsinglequote = ,
fmtdoublequote = “, ”
spelltool = internal
spellcheck = en
showtabsnspaces = True
showlineendings = True
bigdoclimit = 500
showfullpath = False
highlightquotes = False
highlightemph = False
[Backup]
backuppath =
backuponclose = True
askbeforebackup = True
[State]
showrefpanel = False
viewcomments = True
viewsynopsis = True
searchcase = False
searchword = False
searchregex = False
searchloop = False
searchnextfile = False
searchmatchcap = False
[Path]
lastpath =
+149 -1
View File
@@ -15,7 +15,7 @@ from PyQt5.QtWidgets import QDialogButtonBox, QTreeWidgetItem
from nw.gui import (
GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel,
GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard,
GuiProjectLoad
GuiProjectLoad, GuiPreferences
)
from nw.constants import nwItemType, nwItemLayout, nwItemClass
@@ -765,3 +765,151 @@ def testLoadProject(qtbot, nwMinimal, nwTemp):
nwLoad.close()
# qtbot.stopForInteraction()
nwGUI.closeMain()
@pytest.mark.gui
def testPreferences(qtbot, nwMinimal, nwTemp, nwRef, tmpConf):
nwGUI = nw.main(["--testmode", "--config=%s" % nwMinimal, "--data=%s" % nwTemp])
qtbot.addWidget(nwGUI)
nwGUI.show()
qtbot.waitForWindowShown(nwGUI)
qtbot.wait(stepDelay)
assert nwGUI.openProject(nwMinimal)
nwPrefs = GuiPreferences(nwGUI, nwGUI.theProject)
nwPrefs.show()
# Override Config
tmpConf.showGUI = False
tmpConf.confPath = nwMinimal
nwGUI.mainConf = tmpConf
nwPrefs.mainConf = tmpConf
nwPrefs.tabGeneral.mainConf = tmpConf
nwPrefs.tabLayout.mainConf = tmpConf
nwPrefs.tabEditing.mainConf = tmpConf
nwPrefs.tabAutoRep.mainConf = tmpConf
# General Settings
qtbot.wait(keyDelay)
tabGeneral = nwPrefs.tabGeneral
nwPrefs._tabBox.setCurrentWidget(tabGeneral)
tabGeneral.backupPath = nwTemp
qtbot.wait(keyDelay)
assert not tabGeneral.preferDarkIcons.isChecked()
qtbot.mouseClick(tabGeneral.preferDarkIcons, Qt.LeftButton)
assert tabGeneral.preferDarkIcons.isChecked()
qtbot.wait(keyDelay)
assert tabGeneral.showFullPath.isChecked()
qtbot.mouseClick(tabGeneral.showFullPath, Qt.LeftButton)
assert not tabGeneral.showFullPath.isChecked()
qtbot.wait(keyDelay)
assert not tabGeneral.backupOnClose.isChecked()
qtbot.mouseClick(tabGeneral.backupOnClose, Qt.LeftButton)
assert tabGeneral.backupOnClose.isChecked()
qtbot.wait(keyDelay)
tabGeneral.guiFontSize.setValue(12)
tabGeneral.autoSaveDoc.setValue(20)
tabGeneral.autoSaveProj.setValue(40)
# Text Layour Settings
qtbot.wait(keyDelay)
tabLayout = nwPrefs.tabLayout
nwPrefs._tabBox.setCurrentWidget(tabLayout)
qtbot.wait(keyDelay)
tabLayout.textStyleSize.setValue(13)
tabLayout.textFlowMax.setValue(700)
tabLayout.focusDocWidth.setValue(900)
tabLayout.textMargin.setValue(45)
tabLayout.tabWidth.setValue(45)
qtbot.wait(keyDelay)
assert not tabLayout.textFlowFixed.isChecked()
qtbot.mouseClick(tabLayout.textFlowFixed, Qt.LeftButton)
assert tabLayout.textFlowFixed.isChecked()
qtbot.wait(keyDelay)
assert not tabLayout.hideFocusFooter.isChecked()
qtbot.mouseClick(tabLayout.hideFocusFooter, Qt.LeftButton)
assert tabLayout.hideFocusFooter.isChecked()
qtbot.wait(keyDelay)
assert tabLayout.textJustify.isChecked()
qtbot.mouseClick(tabLayout.textJustify, Qt.LeftButton)
assert not tabLayout.textJustify.isChecked()
# Editor Settings
qtbot.wait(keyDelay)
tabEditing = nwPrefs.tabEditing
nwPrefs._tabBox.setCurrentWidget(tabEditing)
qtbot.wait(keyDelay)
assert tabEditing.highlightQuotes.isChecked()
qtbot.mouseClick(tabEditing.highlightQuotes, Qt.LeftButton)
assert not tabEditing.highlightQuotes.isChecked()
qtbot.wait(keyDelay)
assert tabEditing.highlightEmph.isChecked()
qtbot.mouseClick(tabEditing.highlightEmph, Qt.LeftButton)
assert not tabEditing.highlightEmph.isChecked()
qtbot.wait(keyDelay)
assert not tabEditing.showTabsNSpaces.isChecked()
qtbot.mouseClick(tabEditing.showTabsNSpaces, Qt.LeftButton)
assert tabEditing.showTabsNSpaces.isChecked()
qtbot.wait(keyDelay)
assert not tabEditing.showLineEndings.isChecked()
qtbot.mouseClick(tabEditing.showLineEndings, Qt.LeftButton)
assert tabEditing.showLineEndings.isChecked()
qtbot.wait(keyDelay)
tabEditing.bigDocLimit.setValue(500)
# Auto-Replace Settings
qtbot.wait(keyDelay)
tabAutoRep = nwPrefs.tabAutoRep
nwPrefs._tabBox.setCurrentWidget(tabAutoRep)
qtbot.wait(keyDelay)
assert tabAutoRep.autoSelect.isChecked()
qtbot.mouseClick(tabAutoRep.autoSelect, Qt.LeftButton)
assert not tabAutoRep.autoSelect.isChecked()
qtbot.wait(keyDelay)
assert tabAutoRep.autoReplaceMain.isChecked()
qtbot.mouseClick(tabAutoRep.autoReplaceMain, Qt.LeftButton)
assert not tabAutoRep.autoReplaceMain.isChecked()
qtbot.wait(keyDelay)
assert not tabAutoRep.autoReplaceSQ.isEnabled()
assert not tabAutoRep.autoReplaceDQ.isEnabled()
assert not tabAutoRep.autoReplaceDash.isEnabled()
assert not tabAutoRep.autoReplaceDots.isEnabled()
# Save and Check Config
# qtbot.stopForInteraction()
qtbot.mouseClick(nwPrefs.buttonBox.button(QDialogButtonBox.Ok), Qt.LeftButton)
assert tmpConf.confChanged
assert tmpConf.backupPath == nwTemp
tmpConf.backupPath = ""
tmpConf.lastPath = ""
assert nwGUI.mainConf.saveConfig()
nwGUI.closeMain()
refConf = path.join(nwRef, "prefs_novelwriter.conf")
projConf = path.join(nwGUI.mainConf.confPath, "novelwriter.conf")
testConf = path.join(nwTemp, "prefs_novelwriter.conf")
copyfile(projConf, testConf)
ignoreLines = [
2, # Timestamp
11, 12, 13, 14, 15, 16, 17, # Window sizes
7, 25, # Fonts (depends in system default)
]
assert cmpFiles(testConf, refConf, ignoreLines)