Added project wizard gui test
This commit is contained in:
@@ -56,7 +56,7 @@ class GuiProjectWizard(QWizard):
|
|||||||
QWizard.__init__(self, theParent)
|
QWizard.__init__(self, theParent)
|
||||||
|
|
||||||
logger.debug("Initialising GuiProjectWizard ...")
|
logger.debug("Initialising GuiProjectWizard ...")
|
||||||
|
self.setObjectName("GuiProjectWizard")
|
||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theTheme = theParent.theTheme
|
self.theTheme = theParent.theTheme
|
||||||
|
|||||||
+41
-35
@@ -780,42 +780,10 @@ class GuiMain(QMainWindow):
|
|||||||
newProj = GuiProjectWizard(self)
|
newProj = GuiProjectWizard(self)
|
||||||
newProj.exec_()
|
newProj.exec_()
|
||||||
|
|
||||||
if newProj.result() == QDialog.Rejected:
|
if newProj.result() == QDialog.Accepted:
|
||||||
return None
|
return self._assembleProjectWizardData(newProj)
|
||||||
|
|
||||||
projData = {
|
return None
|
||||||
"projName": newProj.field("projName"),
|
|
||||||
"projTitle": newProj.field("projTitle"),
|
|
||||||
"projAuthors": newProj.field("projAuthors"),
|
|
||||||
"projPath": newProj.field("projPath"),
|
|
||||||
"popSample": newProj.field("popSample"),
|
|
||||||
"popMinimal": newProj.field("popMinimal"),
|
|
||||||
"popCustom": newProj.field("popCustom"),
|
|
||||||
"addRoots": [],
|
|
||||||
"numChapters": 0,
|
|
||||||
"numScenes": 0,
|
|
||||||
"chFolders": False,
|
|
||||||
}
|
|
||||||
if newProj.field("popCustom"):
|
|
||||||
addRoots = []
|
|
||||||
if newProj.field("addPlot"):
|
|
||||||
addRoots.append(nwItemClass.PLOT)
|
|
||||||
if newProj.field("addChar"):
|
|
||||||
addRoots.append(nwItemClass.CHARACTER)
|
|
||||||
if newProj.field("addWorld"):
|
|
||||||
addRoots.append(nwItemClass.WORLD)
|
|
||||||
if newProj.field("addTime"):
|
|
||||||
addRoots.append(nwItemClass.TIMELINE)
|
|
||||||
if newProj.field("addObject"):
|
|
||||||
addRoots.append(nwItemClass.OBJECT)
|
|
||||||
if newProj.field("addEntity"):
|
|
||||||
addRoots.append(nwItemClass.ENTITY)
|
|
||||||
projData["addRoots"] = addRoots
|
|
||||||
projData["numChapters"] = newProj.field("numChapters")
|
|
||||||
projData["numScenes"] = newProj.field("numScenes")
|
|
||||||
projData["chFolders"] = newProj.field("chFolders")
|
|
||||||
|
|
||||||
return projData
|
|
||||||
|
|
||||||
def editConfigDialog(self):
|
def editConfigDialog(self):
|
||||||
"""Open the preferences dialog.
|
"""Open the preferences dialog.
|
||||||
@@ -1156,6 +1124,44 @@ class GuiMain(QMainWindow):
|
|||||||
self.importIcons[sLabel] = QIcon(theIcon)
|
self.importIcons[sLabel] = QIcon(theIcon)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _assembleProjectWizardData(self, newProj):
|
||||||
|
"""Extract the user choices from the New Project Wizard and
|
||||||
|
store them in a dictionary.
|
||||||
|
"""
|
||||||
|
projData = {
|
||||||
|
"projName": newProj.field("projName"),
|
||||||
|
"projTitle": newProj.field("projTitle"),
|
||||||
|
"projAuthors": newProj.field("projAuthors"),
|
||||||
|
"projPath": newProj.field("projPath"),
|
||||||
|
"popSample": newProj.field("popSample"),
|
||||||
|
"popMinimal": newProj.field("popMinimal"),
|
||||||
|
"popCustom": newProj.field("popCustom"),
|
||||||
|
"addRoots": [],
|
||||||
|
"numChapters": 0,
|
||||||
|
"numScenes": 0,
|
||||||
|
"chFolders": False,
|
||||||
|
}
|
||||||
|
if newProj.field("popCustom"):
|
||||||
|
addRoots = []
|
||||||
|
if newProj.field("addPlot"):
|
||||||
|
addRoots.append(nwItemClass.PLOT)
|
||||||
|
if newProj.field("addChar"):
|
||||||
|
addRoots.append(nwItemClass.CHARACTER)
|
||||||
|
if newProj.field("addWorld"):
|
||||||
|
addRoots.append(nwItemClass.WORLD)
|
||||||
|
if newProj.field("addTime"):
|
||||||
|
addRoots.append(nwItemClass.TIMELINE)
|
||||||
|
if newProj.field("addObject"):
|
||||||
|
addRoots.append(nwItemClass.OBJECT)
|
||||||
|
if newProj.field("addEntity"):
|
||||||
|
addRoots.append(nwItemClass.ENTITY)
|
||||||
|
projData["addRoots"] = addRoots
|
||||||
|
projData["numChapters"] = newProj.field("numChapters")
|
||||||
|
projData["numScenes"] = newProj.field("numScenes")
|
||||||
|
projData["chFolders"] = newProj.field("chFolders")
|
||||||
|
|
||||||
|
return projData
|
||||||
|
|
||||||
##
|
##
|
||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
from os import path, mkdir
|
from os import path, mkdir
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import qApp
|
||||||
|
|
||||||
def ensureDir(theDir):
|
def ensureDir(theDir):
|
||||||
if not path.isdir(theDir):
|
if not path.isdir(theDir):
|
||||||
mkdir(theDir)
|
mkdir(theDir)
|
||||||
@@ -60,3 +62,8 @@ def cmpList(listOne, listTwo):
|
|||||||
if flatOne[i] != flatTwo[i]:
|
if flatOne[i] != flatTwo[i]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def getGuiItem(theName):
|
||||||
|
for qWidget in qApp.topLevelWidgets():
|
||||||
|
if qWidget.objectName() == theName:
|
||||||
|
return qWidget
|
||||||
|
|||||||
+131
-1
@@ -7,10 +7,11 @@ from nwtools import *
|
|||||||
|
|
||||||
from os import path, unlink
|
from os import path, unlink
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
|
# from PyQt5.QtWidgets import qApp
|
||||||
|
|
||||||
from nw.gui import (
|
from nw.gui import (
|
||||||
GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel,
|
GuiProjectSettings, GuiItemEditor, GuiAbout, GuiBuildNovel,
|
||||||
GuiDocMerge, GuiDocSplit, GuiWritingStats
|
GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard
|
||||||
)
|
)
|
||||||
from nw.constants import *
|
from nw.constants import *
|
||||||
|
|
||||||
@@ -740,6 +741,135 @@ def testSplitTool(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
|||||||
# qtbot.stopForInteraction()
|
# qtbot.stopForInteraction()
|
||||||
nwGUI.closeMain()
|
nwGUI.closeMain()
|
||||||
|
|
||||||
|
@pytest.mark.gui
|
||||||
|
def testNewProjectWizard(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QWizard
|
||||||
|
from nw.gui.projwizard import (
|
||||||
|
ProjWizardIntroPage, ProjWizardFolderPage, ProjWizardPopulatePage,
|
||||||
|
ProjWizardCustomPage, ProjWizardFinalPage
|
||||||
|
)
|
||||||
|
|
||||||
|
nwGUI = nw.main(["--testmode","--config=%s" % nwTempGUI, "--data=%s" % nwTemp])
|
||||||
|
qtbot.addWidget(nwGUI)
|
||||||
|
nwGUI.show()
|
||||||
|
qtbot.waitForWindowShown(nwGUI)
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
|
||||||
|
for wStep in range(3):
|
||||||
|
|
||||||
|
# The Wizard
|
||||||
|
nwWiz = GuiProjectWizard(nwGUI)
|
||||||
|
nwWiz.show()
|
||||||
|
qtbot.waitForWindowShown(nwWiz)
|
||||||
|
|
||||||
|
# Intro Page
|
||||||
|
introPage = nwWiz.currentPage()
|
||||||
|
assert isinstance(introPage, ProjWizardIntroPage)
|
||||||
|
assert not nwWiz.button(QWizard.NextButton).isEnabled()
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
for c in "Test Minimal":
|
||||||
|
qtbot.keyClick(introPage.projName, c, delay=keyDelay)
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
for c in "Minimal Novel":
|
||||||
|
qtbot.keyClick(introPage.projTitle, c, delay=keyDelay)
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
for c in "Jane Doe":
|
||||||
|
qtbot.keyClick(introPage.projAuthors, c, delay=keyDelay)
|
||||||
|
|
||||||
|
# Setting projName should activate the button
|
||||||
|
assert nwWiz.button(QWizard.NextButton).isEnabled()
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
|
||||||
|
|
||||||
|
# Folder Page
|
||||||
|
storagePage = nwWiz.currentPage()
|
||||||
|
assert isinstance(storagePage, ProjWizardFolderPage)
|
||||||
|
assert not nwWiz.button(QWizard.NextButton).isEnabled()
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
projPath = path.join(nwTemp, "dummy")
|
||||||
|
for c in projPath:
|
||||||
|
qtbot.keyClick(storagePage.projPath, c, delay=keyDelay)
|
||||||
|
|
||||||
|
# Setting projPath should activate the button
|
||||||
|
assert nwWiz.button(QWizard.NextButton).isEnabled()
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
|
||||||
|
|
||||||
|
# Populate Page
|
||||||
|
popPage = nwWiz.currentPage()
|
||||||
|
assert isinstance(popPage, ProjWizardPopulatePage)
|
||||||
|
assert nwWiz.button(QWizard.NextButton).isEnabled()
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
if wStep == 0:
|
||||||
|
popPage.popMinimal.setChecked(True)
|
||||||
|
elif wStep == 1:
|
||||||
|
popPage.popCustom.setChecked(True)
|
||||||
|
elif wStep == 2:
|
||||||
|
popPage.popSample.setChecked(True)
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
|
||||||
|
|
||||||
|
# Custom Page
|
||||||
|
if wStep == 1:
|
||||||
|
customPage = nwWiz.currentPage()
|
||||||
|
assert isinstance(customPage, ProjWizardCustomPage)
|
||||||
|
assert nwWiz.button(QWizard.NextButton).isEnabled()
|
||||||
|
|
||||||
|
customPage.addPlot.setChecked(True)
|
||||||
|
customPage.addChar.setChecked(True)
|
||||||
|
customPage.addWorld.setChecked(True)
|
||||||
|
customPage.addTime.setChecked(True)
|
||||||
|
customPage.addObject.setChecked(True)
|
||||||
|
customPage.addEntity.setChecked(True)
|
||||||
|
|
||||||
|
qtbot.wait(stepDelay)
|
||||||
|
qtbot.mouseClick(nwWiz.button(QWizard.NextButton), Qt.LeftButton)
|
||||||
|
|
||||||
|
# Final Page
|
||||||
|
finalPage = nwWiz.currentPage()
|
||||||
|
assert isinstance(finalPage, ProjWizardFinalPage)
|
||||||
|
assert nwWiz.button(QWizard.FinishButton).isEnabled()
|
||||||
|
qtbot.mouseClick(nwWiz.button(QWizard.FinishButton), Qt.LeftButton)
|
||||||
|
|
||||||
|
# Check Data
|
||||||
|
projData = nwGUI._assembleProjectWizardData(nwWiz)
|
||||||
|
assert projData["projName"] == "Test Minimal"
|
||||||
|
assert projData["projTitle"] == "Minimal Novel"
|
||||||
|
assert projData["projAuthors"] == "Jane Doe"
|
||||||
|
assert projData["projPath"] == projPath
|
||||||
|
assert projData["popMinimal"] == (wStep == 0)
|
||||||
|
assert projData["popCustom"] == (wStep == 1)
|
||||||
|
assert projData["popSample"] == (wStep == 2)
|
||||||
|
if wStep == 1:
|
||||||
|
assert projData["addRoots"] == [
|
||||||
|
nwItemClass.PLOT,
|
||||||
|
nwItemClass.CHARACTER,
|
||||||
|
nwItemClass.WORLD,
|
||||||
|
nwItemClass.TIMELINE,
|
||||||
|
nwItemClass.OBJECT,
|
||||||
|
nwItemClass.ENTITY,
|
||||||
|
]
|
||||||
|
assert projData["numChapters"] == 5
|
||||||
|
assert projData["numScenes"] == 5
|
||||||
|
assert projData["chFolders"] == True
|
||||||
|
else:
|
||||||
|
assert projData["addRoots"] == []
|
||||||
|
assert projData["numChapters"] == 0
|
||||||
|
assert projData["numScenes"] == 0
|
||||||
|
assert projData["chFolders"] == False
|
||||||
|
|
||||||
|
# qtbot.stopForInteraction()
|
||||||
|
nwGUI.closeMain()
|
||||||
|
|
||||||
@pytest.mark.gui
|
@pytest.mark.gui
|
||||||
def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
def testDocAction(qtbot, nwTempGUI, nwLipsum, nwRef, nwTemp):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user