From b27ac3525169528a7f36dca396a100b9a6689305 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Fri, 17 May 2019 20:11:47 +0200 Subject: [PATCH 1/3] Fixed coverage for wordcounter.run() --- tests/test_gui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_gui.py b/tests/test_gui.py index 842158cc..6710003a 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -94,8 +94,8 @@ def testMainWindows(qtbot, tmpdir): qtbot.keyClick(nwGUI.docEditor, Qt.Key_Return, delay=keyDelay) qtbot.wait(stepDelay) - nwGUI.docEditor._runCounter() - qtbot.wait(1000) + nwGUI.docEditor.wCounter.run() + qtbot.wait(stepDelay) # Save the document assert nwGUI.docEditor.docChanged From 9631d63690d8a4effefbd49f932475673f4bb9bf Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Fri, 17 May 2019 20:52:23 +0200 Subject: [PATCH 2/3] Added test for project editor dialog --- tests/reference/projedit_nwProject.nwx | 60 ++++++++++++++++++++++++++ tests/test_gui.py | 51 ++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/reference/projedit_nwProject.nwx diff --git a/tests/reference/projedit_nwProject.nwx b/tests/reference/projedit_nwProject.nwx new file mode 100644 index 00000000..2cd49256 --- /dev/null +++ b/tests/reference/projedit_nwProject.nwx @@ -0,0 +1,60 @@ + + + + Project Name + Project Title + Jane Doe + John Doh + + + False + + + + Novel + ROOT + NOVEL + 0 + False + + + New Chapter + FOLDER + NOVEL + 0 + False + + + New Scene + FILE + NOVEL + 0 + False + SCENE + 0 + 0 + 0 + + + Characters + ROOT + CHARACTER + 0 + False + + + Plot + ROOT + PLOT + 0 + False + + + World + ROOT + WORLD + 0 + False + + + diff --git a/tests/test_gui.py b/tests/test_gui.py index 6710003a..2bae4d09 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -6,6 +6,7 @@ import nw, pytest from nwtools import * from os import path, unlink from PyQt5.QtCore import Qt +from nw.gui.projecteditor import GuiProjectEditor keyDelay = 10 stepDelay = 50 @@ -109,3 +110,53 @@ def testMainWindows(qtbot, tmpdir): assert cmpFiles(sceneFile, path.join(testRef,"gui_1489056e0916_main.nwd")) # qtbot.stopForInteraction() + +@pytest.mark.gui +def testProjectEditor(qtbot, tmpdir): + confDir = str(tmpdir.mkdir("conf")) + projDir = str(tmpdir.mkdir("project")) + nwGUI = nw.main(["--testmode","--config=%s" % confDir]) + qtbot.addWidget(nwGUI) + nwGUI.show() + qtbot.waitForWindowShown(nwGUI) + qtbot.wait(stepDelay) + + # Create new, save, open project + nwGUI.theProject.handleSeed = 42 + assert nwGUI.theProject.setProjectPath(projDir) + assert nwGUI.newProject() + assert nwGUI.theProject.setProjectPath(projDir) + + projEdit = GuiProjectEditor(nwGUI, nwGUI.theProject) + qtbot.addWidget(projEdit) + + for c in "Project Name": + qtbot.keyClick(projEdit.editName, c, delay=keyDelay) + for c in "Project Title": + qtbot.keyClick(projEdit.editTitle, c, delay=keyDelay) + for c in "Jane Doe": + qtbot.keyClick(projEdit.editAuthors, c, delay=keyDelay) + qtbot.keyClick(projEdit.editAuthors, Qt.Key_Return, delay=keyDelay) + for c in "John Doh": + qtbot.keyClick(projEdit.editAuthors, c, delay=keyDelay) + + qtbot.mouseClick(projEdit.saveButton, Qt.LeftButton) + + projEdit = GuiProjectEditor(nwGUI, nwGUI.theProject) + qtbot.addWidget(projEdit) + assert projEdit.editName.text() == "Project Name" + assert projEdit.editTitle.text() == "Project Title" + theAuth = projEdit.editAuthors.toPlainText().strip().splitlines() + assert len(theAuth) == 2 + assert theAuth[0] == "Jane Doe" + assert theAuth[1] == "John Doh" + + qtbot.mouseClick(projEdit.closeButton, Qt.LeftButton) + + qtbot.wait(stepDelay) + assert nwGUI.saveProject() + qtbot.wait(stepDelay) + + # Check the files + projFile = path.join(projDir,"nwProject.nwx") + assert cmpFiles(projFile, path.join(testRef,"projedit_nwProject.nwx"), [2]) From bdb315a71199a425798106af47ce7b66bebdf837 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Fri, 17 May 2019 21:09:41 +0200 Subject: [PATCH 3/3] Added test for item editor dialog --- tests/reference/itemedit_nwProject.nwx | 58 ++++++++++++++++++++++++++ tests/test_gui.py | 55 ++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tests/reference/itemedit_nwProject.nwx diff --git a/tests/reference/itemedit_nwProject.nwx b/tests/reference/itemedit_nwProject.nwx new file mode 100644 index 00000000..b55ba18e --- /dev/null +++ b/tests/reference/itemedit_nwProject.nwx @@ -0,0 +1,58 @@ + + + + + + + + False + + + + Novel + ROOT + NOVEL + 0 + False + + + New Chapter + FOLDER + NOVEL + 0 + False + + + Just a Page + FILE + NOVEL + 1 + False + PAGE + 0 + 0 + 0 + + + Characters + ROOT + CHARACTER + 0 + False + + + Plot + ROOT + PLOT + 0 + False + + + World + ROOT + WORLD + 0 + False + + + diff --git a/tests/test_gui.py b/tests/test_gui.py index 2bae4d09..c5584edf 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -4,9 +4,13 @@ import nw, pytest from nwtools import * + from os import path, unlink from PyQt5.QtCore import Qt + from nw.gui.projecteditor import GuiProjectEditor +from nw.gui.itemeditor import GuiItemEditor +from nw.enum import * keyDelay = 10 stepDelay = 50 @@ -160,3 +164,54 @@ def testProjectEditor(qtbot, tmpdir): # Check the files projFile = path.join(projDir,"nwProject.nwx") assert cmpFiles(projFile, path.join(testRef,"projedit_nwProject.nwx"), [2]) + + # qtbot.stopForInteraction() + +@pytest.mark.gui +def testItemEditor(qtbot, tmpdir): + confDir = str(tmpdir.mkdir("conf")) + projDir = str(tmpdir.mkdir("project")) + nwGUI = nw.main(["--testmode","--config=%s" % confDir]) + qtbot.addWidget(nwGUI) + nwGUI.show() + qtbot.waitForWindowShown(nwGUI) + qtbot.wait(stepDelay) + + # Create new, save, open project + nwGUI.theProject.handleSeed = 42 + assert nwGUI.theProject.setProjectPath(projDir) + assert nwGUI.newProject() + assert nwGUI.theProject.setProjectPath(projDir) + + itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "31489056e0916") + qtbot.addWidget(itemEdit) + + assert itemEdit.editName.text() == "New Scene" + assert itemEdit.editStatus.currentData() == 0 + assert itemEdit.editLayout.currentData() == nwItemLayout.SCENE + + for c in "Just a Page": + qtbot.keyClick(itemEdit.editName, c, delay=keyDelay) + itemEdit.editStatus.setCurrentIndex(1) + layoutIdx = itemEdit.editLayout.findData(nwItemLayout.PAGE) + itemEdit.editLayout.setCurrentIndex(layoutIdx) + + qtbot.mouseClick(itemEdit.saveButton, Qt.LeftButton) + + itemEdit = GuiItemEditor(nwGUI, nwGUI.theProject, "31489056e0916") + qtbot.addWidget(itemEdit) + assert itemEdit.editName.text() == "Just a Page" + assert itemEdit.editStatus.currentData() == 1 + assert itemEdit.editLayout.currentData() == nwItemLayout.PAGE + + qtbot.mouseClick(itemEdit.closeButton, Qt.LeftButton) + + qtbot.wait(stepDelay) + assert nwGUI.saveProject() + qtbot.wait(stepDelay) + + # Check the files + projFile = path.join(projDir,"nwProject.nwx") + assert cmpFiles(projFile, path.join(testRef,"itemedit_nwProject.nwx"), [2]) + + # qtbot.stopForInteraction()